Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv18791/SQLObject
Modified Files:
DBConnection.py
Log Message:
Firebird fixes:
* "name" is a reserved word; fixed tests.
* Limit/offset (slices)
* columnsFromSchema support
* ALTER TABLE fix
Index: DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -d -r1.51 -r1.52
*** DBConnection.py 27 Sep 2003 22:56:41 -0000 1.51
--- DBConnection.py 1 Oct 2003 01:53:48 -0000 1.52
***************
*** 182,188 ****
def countSelect(self, select):
! q = "SELECT COUNT(*) FROM %s WHERE %s" % \
! (", ".join(select.tables),
! self.whereClauseForSelect(select, limit=0, order=0))
val = int(self.queryOne(q)[0])
return val
--- 182,188 ----
def countSelect(self, select):
! q = "SELECT COUNT(*) FROM %s WHERE" % \
! ", ".join(select.tables)
! q = self._addWhereClause(select, q, limit=0, order=0)
val = int(self.queryOne(q)[0])
return val
***************
*** 202,208 ****
", ".join(select.tables))
! return q + self.whereClauseForSelect(select)
! def whereClauseForSelect(self, select, limit=1, order=1):
q = str(select.clause)
--- 202,208 ----
", ".join(select.tables))
! return self._addWhereClause(select, q)
! def _addWhereClause(self, select, startSelect, limit=1, order=1):
q = str(select.clause)
***************
*** 242,245 ****
--- 242,247 ----
end = ops.get('end', None)
+ q = startSelect + ' ' + q
+
if limit and (start or end):
# @@: Raising an error might be an annoyance, but some warning is
***************
*** 775,778 ****
--- 777,785 ----
return val
+ def _setAutoCommit(self, conn, auto):
+ # Only _runWithConnection does "autocommit", so we don't
+ # need to worry about that.
+ pass
+
def makeConnection(self):
return kinterbasdb.connect(
***************
*** 839,843 ****
def addColumn(self, tableName, column):
! self.query('ALTER TABLE %s ADD COLUMN %s' %
(tableName,
column.firebirdCreateSQL()))
--- 846,850 ----
def addColumn(self, tableName, column):
! self.query('ALTER TABLE %s ADD %s' %
(tableName,
column.firebirdCreateSQL()))
***************
*** 848,854 ****
def delColumn(self, tableName, column):
! self.query('ALTER TABLE %s DROP COLUMN %s' %
(tableName,
column.dbName))
########################################
--- 855,918 ----
def delColumn(self, tableName, column):
! self.query('ALTER TABLE %s DROP %s' %
(tableName,
column.dbName))
+
+ 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 = """\
+ SELECT RDB$RELATION_FIELDS.RDB$FIELD_NAME as field,
+ RDB$TYPES.RDB$TYPE_NAME as t,
+ RDB$FIELDS.RDB$FIELD_LENGTH as flength,
+ RDB$FIELDS.RDB$FIELD_SCALE as fscale,
+ RDB$RELATION_FIELDS.RDB$NULL_FLAG as nullAllowed,
+ RDB$RELATION_FIELDS.RDB$DEFAULT_VALUE as thedefault,
+ RDB$FIELDS.RDB$FIELD_SUB_TYPE as blobtype
+ FROM RDB$RELATION_FIELDS
+ INNER JOIN RDB$FIELDS ON
+ (RDB$RELATION_FIELDS.RDB$FIELD_SOURCE = RDB$FIELDS.RDB$FIELD_NAME)
+ INNER JOIN RDB$TYPES ON (RDB$FIELDS.RDB$FIELD_TYPE =
+ RDB$TYPES.RDB$TYPE)
+ WHERE
+ (RDB$RELATION_FIELDS.RDB$RELATION_NAME = '%s')
+ AND (RDB$TYPES.RDB$FIELD_NAME = 'RDB$FIELD_TYPE')"""
+
+ colData = self.queryAll(fieldqry % tableName.upper())
+ results = []
+ for field, t, flength, fscale, nullAllowed, thedefault, blobType in colData:
+ if field == 'id':
+ continue
+ colClass, kw = self.guessClass(t, flength, fscale)
+ kw['name'] = soClass._style.dbColumnToPythonAttr(field)
+ kw['notNone'] = not nullAllowed
+ kw['default'] = thedefault
+ results.append(colClass(**kw))
+ return results
+
+ _intTypes=['INT64', 'SHORT','LONG']
+ _dateTypes=['DATE','TIME','TIMESTAMP']
+
+ def guessClass(self, t, flength, fscale=None):
+ """
+ An internal method that tries to figure out what Col subclass
+ is appropriate given whatever introspective information is
+ available -- both very database-specific.
+ """
+
+ if t in self._intTypes:
+ return Col.IntCol, {}
+ elif t == 'VARYING':
+ return Col.StringCol, {'length': flength}
+ elif t == 'TEXT':
+ return Col.StringCol, {'length': flength,
+ 'varchar': False}
+ elif t in self._dateTypes:
+ return Col.DateTimeCol, {}
+ else:
+ return Col.Col, {}
########################################
|