Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv14660/SQLObject
Modified Files:
DBConnection.py SQLObject.py
Log Message:
Allow non-integer IDs
Index: DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** DBConnection.py 7 Sep 2003 07:25:58 -0000 1.46
--- DBConnection.py 7 Sep 2003 23:36:08 -0000 1.47
***************
*** 152,157 ****
return Transaction(self)
! def queryInsertID(self, table, idName, names, values):
! return self._runWithConnection(self._queryInsertID, table, idName, names, values)
def _iterSelect(self, conn, select, withConnection=None,
--- 152,157 ----
return Transaction(self)
! def queryInsertID(self, table, idName, id, names, values):
! return self._runWithConnection(self._queryInsertID, table, idName, id, names, values)
def _iterSelect(self, conn, select, withConnection=None,
***************
*** 373,379 ****
return self._dbConnection._queryOne(self._connection, s)
! def queryInsertID(self, table, idName, names, values):
return self._dbConnection._queryInsertID(
! self._connection, table, idName, names, values)
def iterSelect(self, select):
--- 373,379 ----
return self._dbConnection._queryOne(self._connection, s)
! def queryInsertID(self, table, idName, id, names, values):
return self._dbConnection._queryInsertID(
! self._connection, table, idName, id, names, values)
def iterSelect(self, select):
***************
*** 439,449 ****
user=self.user, passwd=self.passwd)
! def _queryInsertID(self, conn, table, idName, names, values):
c = conn.cursor()
q = self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
c.execute(q)
! id = c.insert_id()
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
--- 439,453 ----
user=self.user, passwd=self.passwd)
! def _queryInsertID(self, conn, table, idName, id, names, values):
c = conn.cursor()
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
q = self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
c.execute(q)
! if id is None:
! id = c.insert_id()
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
***************
*** 558,570 ****
return conn
! def _queryInsertID(self, conn, table, idName, names, values):
c = conn.cursor()
q = self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
c.execute(q)
! c.execute('SELECT %s FROM %s WHERE oid = %s'
! % (idName, table, c.lastoid()))
! id = c.fetchone()[0]
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
--- 562,578 ----
return conn
! def _queryInsertID(self, conn, table, idName, id, names, values):
c = conn.cursor()
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
q = self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
c.execute(q)
! if id is None:
! c.execute('SELECT %s FROM %s WHERE oid = %s'
! % (idName, table, c.lastoid()))
! id = c.fetchone()[0]
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
***************
*** 682,687 ****
return self._conn
! def _queryInsertID(self, conn, table, idName, names, values):
c = conn.cursor()
q = self._insertSQL(table, names, values)
if self.debug:
--- 690,698 ----
return self._conn
! def _queryInsertID(self, conn, table, idName, id, names, values):
c = conn.cursor()
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
q = self._insertSQL(table, names, values)
if self.debug:
***************
*** 689,693 ****
c.execute(q)
# lastrowid is a DB-API extension from "PEP 0249":
! id = int(c.lastrowid)
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
--- 700,705 ----
c.execute(q)
# lastrowid is a DB-API extension from "PEP 0249":
! if id is None:
! id = int(c.lastrowid)
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
***************
*** 748,761 ****
)
! def _queryInsertID(self, conn, table, idName, names, values):
"""Firebird uses 'generators' to create new ids for a table.
The users needs to create a generator named GEN_<tablename>
for each table this method to work."""
! row = self.queryOne('SELECT gen_id(GEN_%s,1) FROM rdb$database'
! % table)
! new_key = row[0]
! names.append('ID')
! values.append(new_key)
qry = self._insertSQL(table, names, values)
if self.debug:
--- 760,774 ----
)
! def _queryInsertID(self, conn, table, idName, id, names, values):
"""Firebird uses 'generators' to create new ids for a table.
The users needs to create a generator named GEN_<tablename>
for each table this method to work."""
! if id is None:
! row = self.queryOne('SELECT gen_id(GEN_%s,1) FROM rdb$database'
! % table)
! id = row[0]
! names = [idName] + names
! values = [id] + values
qry = self._insertSQL(table, names, values)
if self.debug:
***************
*** 763,768 ****
self.query(qry)
if self.debugOutput:
! self.printDebug(conn, new_key, 'QueryIns', 'result')
! return new_key
def _queryAddLimitOffset(self, query, start, end):
--- 776,781 ----
self.query(qry)
if self.debugOutput:
! self.printDebug(conn, id, 'QueryIns', 'result')
! return id
def _queryAddLimitOffset(self, query, start, end):
***************
*** 840,845 ****
"""
! def queryInsertID(self, table, idName, names, values):
! id = self._newID(table)
self._saveDict(table, id, dict(zip(names, values)))
return id
--- 853,859 ----
"""
! def queryInsertID(self, table, idName, id, names, values):
! if id is None:
! id = self._newID(table)
self._saveDict(table, id, dict(zip(names, values)))
return id
Index: SQLObject.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v
retrieving revision 1.56
retrieving revision 1.57
diff -C2 -d -r1.56 -r1.57
*** SQLObject.py 7 Sep 2003 22:35:09 -0000 1.56
--- SQLObject.py 7 Sep 2003 23:36:08 -0000 1.57
***************
*** 817,820 ****
--- 817,826 ----
inst = cls(CreateNewSQLObject)
+ if kw.has_key('id'):
+ id = kw['id']
+ del kw['id']
+ else:
+ id = None
+
# First we do a little fix-up on the keywords we were
# passed:
***************
*** 862,870 ****
# Then we finalize the process:
! inst._SO_finishCreate()
return inst
new = classmethod(new)
! def _SO_finishCreate(self):
# Here's where an INSERT is finalized.
# These are all the column values that were supposed
--- 868,876 ----
# Then we finalize the process:
! inst._SO_finishCreate(id)
return inst
new = classmethod(new)
! def _SO_finishCreate(self, id=None):
# Here's where an INSERT is finalized.
# These are all the column values that were supposed
***************
*** 884,888 ****
# non-standard.
id = self._connection.queryInsertID(self._table, self._idName,
! names, values)
cache = self._connection.cache
cache.created(id, self.__class__, self)
--- 890,894 ----
# non-standard.
id = self._connection.queryInsertID(self._table, self._idName,
! id, names, values)
cache = self._connection.cache
cache.created(id, self.__class__, self)
|