1 from __future__
import print_function
5 """Manages the autoincremental ID values.\n 6 Input: coral.schema object 18 get the new id value to use for the given table 22 query = self.__schema.tableHandle(idtableName).newQuery()
25 cursor = query.execute()
27 while (
next(cursor) ):
31 except Exception
as e:
36 Set the nextID in the IDTableName to current id value + 1 .\n 41 tableHandle = self.__schema.tableHandle(idtableName)
42 query = tableHandle.newQuery()
45 cursor = query.execute()
47 while (
next(cursor) ):
48 result = cursor.currentRow()[0].
data()
49 dataEditor = tableHandle.dataEditor()
50 inputData = coral.AttributeList()
51 dataEditor.updateRows(
'NEXTID = NEXTID+1',
'',inputData)
54 except Exception
as e:
57 if __name__ ==
"__main__":
58 fakeIDtableName=
'Fake_ID' 59 svc=coral.ConnectionService()
60 session=svc.connect(
'sqlite_file:fake.db')
61 transaction=session.transaction()
63 transaction.start(
False)
64 schema=session.nominalSchema()
66 if schema.existsTable(fakeIDtableName)
is False:
67 description=coral.TableDescription()
68 description.setName(fakeIDtableName)
69 description.setPrimaryKey(idor.getIDColumnDefinition()[0])
70 description.insertColumn(idor.getIDColumnDefinition()[0],idor.getIDColumnDefinition()[1])
71 idtableHandle=schema.createTable(description)
72 idtableHandle.privilegeManager().grantToPublic(coral.privilege_Select)
73 inputData=coral.AttributeList()
74 editor=idtableHandle.dataEditor()
75 editor.rowBuffer(inputData)
76 inputData[ idor.getIDColumnDefinition()[0] ].setData(0)
77 editor.insertRow(inputData)
78 idor.generateNextIDForTable(
'Fake')
79 print(idor.getIDforTable(
'Fake'))
82 except coral.Exception
as e:
83 transaction.rollback()
85 except Exception
as e:
86 print(
'failed in unit test')
S & print(S &os, JobReport::InputFile const &f)
def __init__(self, schema)
def getIDforTable(self, tableName)
def idTableColumnDefinition()
char data[epos_bytes_allocation]
def getIDColumnDefinition(self)
def idTableName(dataTableName)
def generateNextIDForTable(self, tableName)