4 """Manages the autoincremental ID values.\n
5 Input: coral.schema object
12 """Return the ID value in the specified ID table.\n
16 query = self.__schema.tableHandle(IDtableName).newQuery()
19 cursor = query.execute()
21 while ( cursor.next() ):
26 raise Exception, str(e)
28 """Set the nextID in the IDTableName to current id value + 1 .\n
32 tableHandle = self.__schema.tableHandle(IDtableName)
33 query = tableHandle.newQuery()
36 cursor = query.execute()
38 while ( cursor.next() ):
39 result = cursor.currentRow()[0].
data()
41 dataEditor = tableHandle.dataEditor()
42 inputData = coral.AttributeList()
44 inputData[
'newid'].setData(result+1)
45 dataEditor.updateRows(
'nextID = :newid',
'',inputData)
47 raise Exception, str(e)
56 """Create ID table 'tableName_ID' for the given table.\n
57 Input: name of the table which needs new associated id table
58 Output: name of the id table created
62 if dbop.tableExists(idtableName)
is True:
64 dbop.dropTable(idtableName)
67 description = coral.TableDescription();
68 description.setName(idtableName)
70 idtableHandle=self.__schema.createTable( description )
71 idtableHandle.privilegeManager().grantToPublic( coral.privilege_Select )
72 inputData = coral.AttributeList()
73 editor = idtableHandle.dataEditor()
74 editor.rowBuffer( inputData )
76 editor.insertRow( inputData )
78 raise Exception, str(e)
79 if __name__ ==
"__main__":
80 idtableName =
'TagTreeTable_IDS'
81 svc = coral.ConnectionService()
82 session = svc.connect(
'sqlite_file:data.db', accessMode = coral.access_Update )
83 transaction = session.transaction()
86 schema = session.nominalSchema()
88 generator.createIDTable( idtableName )
90 transaction.start(
True)
91 result=generator.getNewID(idtableName)
92 print 'new id ',result
94 transaction.start(
False)
95 generator.incrementNextID(idtableName)
96 print 'new id ',generator.getNewID(idtableName)
99 except coral.Exception, e:
100 transaction.rollback()
104 print "Failed in unit test"