Ian,
Here is a first go at a patch to allow SQLObject to build classes from
SQLite databases. It uses a the same code as MySQLConnection with some
very small changes, this means that to have this work the columns in
SQLite tables have to have types set and use the type names that MySQL
uses.
Where in the tests should I add a test for this?
Index: SQLObject/DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.54
diff -r1.54 DBConnection.py
747a748,781
> def columnsFromSchema(self, tableName, soClass):
> """
> Look at the given table and create Col instances (or
> subclasses of Col) for the fields it finds in that table.
> """
>
> fieldqry = "PRAGMA table_info(%s)"
>
> colData = self.queryAll(fieldqry % tableName.upper())
> results = []
> for pos, field, t, nullAllowed, thedefault in colData:
> if field == 'id':
> continue
> colClass, kw = self.guessClass(t)
> kw['name'] = soClass._style.dbColumnToPythonAttr(field)
> kw['notNone'] = not nullAllowed
> kw['default'] = thedefault
> results.append(colClass(**kw))
> return results
>
> def guessClass(self, t):
> if t.startswith('int'):
> return Col.IntCol, {}
> elif t.startswith('varchar'):
> return Col.StringCol, {}
> elif t.startswith('char'):
> return Col.StringCol, {}
> elif t.startswith('datetime'):
> return Col.DateTimeCol, {}
> elif t.startswith('bool'):
> return Col.BoolCol, {}
> else:
> return Col.Col, {}
>
--
Regards,
Peter Wilkinson.
|