@@ -0,0 +1,2058 @@
+#!/usr/bin/env python%0A%0A%22%22%22%0A  dbcol.py: DBCol is a struct describing an sqlite database table column%0A%22%22%22%0A%0Afrom dbcol import *%0A%0A%0A# ----------------------------DATABASE-COLUMN-----------------------------#%0Aclass DBRow:%0A    @staticmethod%0A    def dict(columns, values):%0A        if (values is not None):%0A            if (len(columns) == len(values)):%0A                dict = %7B%7D%0A                i = 0%0A                for col in columns:%0A                    dict%5Bcol.name%5D = values%5Bi%5D%0A                    i += 1%0A                return dict%0A            else:%0A                raise ValueError('columns do not match values')%0A        else:%0A            return None%0A%0A    @staticmethod%0A    def sqlForRowInsert(table, columns, values):%0A        c = len(columns)%0A        v = len(values)%0A        sql = 'INSERT INTO %22%7B%7D%22 ('.format(table)%0A        i = 1%0A        for col in columns:%0A            sql += '%22%7B%7D%22'.format(col.name)%0A            if (i %3C c):%0A                sql += ','%0A            i += 1%0A        sql += ') VALUES ('%0A        i = 1%0A        # allow for first column autoincrement%0A        if (v == (c - 1)):%0A            sql += 'NULL,'%0A            i += 1%0A        for val in values:%0A            if (isinstance(val, int)):%0A                # don't need quotes in integer values%0A                sql += str(val)%0A            elif (val == 'NULL'):%0A                # keep quotes off of NULL%0A                sql += val%0A            else:%0A                # wrap value with quotes%0A                sql += '%22%7B%7D%22'.format(val)%0A            if (i %3C v):%0A                sql += ','%0A            i += 1%0A        sql += ');'%0A        return sql%0A%0A# ---------------------------------EXPORT---------------------------------#%0A__all__ = %5B'DBRow'%5D%0A%0A%0A# ----------------------------------MAIN----------------------------------#%0Adef main():%0A    f1 = DBCol('f1', 'INTEGER')%0A    f2 = DBCol('f2', 'TEXT')%0A    f3 = DBCol('f3', 'TEXT')%0A    cols = %5Bf1, f2, f3%5D%0A    vals = %5B1, 'Test', 'Third'%5D%0A    print DBRow.dict(cols, vals)%0A    print DBRow.sqlForRowInsert('sample', cols, vals)%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

Create database row class (DBRow)