1 from __future__
import print_function
2 from __future__
import absolute_import
4 from .
import nameDealer
6 """Manages the autoincremental ID values.\n 7 Input: coral.schema object 19 get the new id value to use for the given table 23 query = self.__schema.tableHandle(idtableName).newQuery()
26 cursor = query.execute()
28 while (
next(cursor) ):
32 except Exception
as e:
37 Set the nextID in the IDTableName to current id value + 1 .\n 42 tableHandle = self.__schema.tableHandle(idtableName)
43 query = tableHandle.newQuery()
46 cursor = query.execute()
48 while (
next(cursor) ):
49 result = cursor.currentRow()[0].
data()
50 dataEditor = tableHandle.dataEditor()
51 inputData = coral.AttributeList()
52 dataEditor.updateRows(
'NEXTID = NEXTID+1',
'',inputData)
55 except Exception
as e:
58 if __name__ ==
"__main__":
59 fakeIDtableName=
'Fake_ID' 60 svc=coral.ConnectionService()
61 session=svc.connect(
'sqlite_file:fake.db')
62 transaction=session.transaction()
64 transaction.start(
False)
65 schema=session.nominalSchema()
67 if schema.existsTable(fakeIDtableName)
is False:
68 description=coral.TableDescription()
69 description.setName(fakeIDtableName)
70 description.setPrimaryKey(idor.getIDColumnDefinition()[0])
71 description.insertColumn(idor.getIDColumnDefinition()[0],idor.getIDColumnDefinition()[1])
72 idtableHandle=schema.createTable(description)
73 idtableHandle.privilegeManager().grantToPublic(coral.privilege_Select)
74 inputData=coral.AttributeList()
75 editor=idtableHandle.dataEditor()
76 editor.rowBuffer(inputData)
77 inputData[ idor.getIDColumnDefinition()[0] ].setData(0)
78 editor.insertRow(inputData)
79 idor.generateNextIDForTable(
'Fake')
80 print(idor.getIDforTable(
'Fake'))
83 except coral.Exception
as e:
84 transaction.rollback()
86 except Exception
as e:
87 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)