4 """Manages the autoincremental ID values.\n
5 Input: coral.schema object
17 get the new id value to use for the given table
21 query = self.__schema.tableHandle(idtableName).newQuery()
24 cursor = query.execute()
26 while (
next(cursor) ):
30 except Exception
as e:
35 Set the nextID in the IDTableName to current id value + 1 .\n
40 tableHandle = self.__schema.tableHandle(idtableName)
41 query = tableHandle.newQuery()
44 cursor = query.execute()
46 while (
next(cursor) ):
47 result = cursor.currentRow()[0].
data()
48 dataEditor = tableHandle.dataEditor()
49 inputData = coral.AttributeList()
50 dataEditor.updateRows(
'NEXTID = NEXTID+1',
'',inputData)
53 except Exception
as e:
56 if __name__ ==
"__main__":
57 fakeIDtableName=
'Fake_ID'
58 svc=coral.ConnectionService()
59 session=svc.connect(
'sqlite_file:fake.db')
60 transaction=session.transaction()
62 transaction.start(
False)
63 schema=session.nominalSchema()
65 if schema.existsTable(fakeIDtableName)
is False:
66 description=coral.TableDescription()
67 description.setName(fakeIDtableName)
68 description.setPrimaryKey(idor.getIDColumnDefinition()[0])
69 description.insertColumn(idor.getIDColumnDefinition()[0],idor.getIDColumnDefinition()[1])
70 idtableHandle=schema.createTable(description)
71 idtableHandle.privilegeManager().grantToPublic(coral.privilege_Select)
72 inputData=coral.AttributeList()
73 editor=idtableHandle.dataEditor()
74 editor.rowBuffer(inputData)
75 inputData[ idor.getIDColumnDefinition()[0] ].setData(0)
76 editor.insertRow(inputData)
77 idor.generateNextIDForTable(
'Fake')
78 print idor.getIDforTable(
'Fake')
81 except coral.Exception
as e:
82 transaction.rollback()
84 except Exception
as e:
85 print 'failed in unit test'
def idTableColumnDefinition
def getIDColumnDefinition
char data[epos_bytes_allocation]
def generateNextIDForTable