5 """Class wrap up all the database operations.\n
8 """Input: coral schema handle.
11 def existRow( self, tableName, condition, conditionbindDict):
12 """Return true if one row fulfills the selection criteria
15 tableHandle = self.__schema.tableHandle(tableName)
16 query = tableHandle.newQuery()
17 query.setCondition(condition,conditionbindDict)
18 cursor = query.execute()
20 while ( cursor.next() ):
26 raise Exception, str(e)
27 def insertOneRow( self, tableName, tabrowDefDict, tabrowValueDict ):
31 tableHandle = self.__schema.tableHandle(tableName)
32 editor = tableHandle.dataEditor()
33 inputData = coral.AttributeList()
34 for name,type
in tabrowDefDict.items():
36 inputData.extend( name, type )
37 inputData[name].setData(tabrowValueDict[name])
38 editor.insertRow( inputData )
40 raise Exception, str(e)
41 def bulkInsert( self, tableName, tabrowDefDict, bulkinput):
42 """Bulk insert bulkinput=[{}]
45 dataEditor=self.__schema.tableHandle(tableName).dataEditor()
46 insertdata=coral.AttributeList()
47 for (columnname,columntype)
in tabrowDefDict.items():
48 insertdata.extend(columnname,columntype)
50 bulkOperation=dataEditor.bulkInsert(insertdata,len(bulkinput))
51 for valuedict
in bulkinput:
52 for (columnname,columnvalue)
in valuedict.items():
53 insertdata[columnname].setData(columnvalue)
54 bulkOperation.processNextIteration()
58 raise Exception, str(e)
59 def deleteRows( self, tableName, condition, conditionbindDict ):
63 tableHandle = self.__schema.tableHandle(tableName)
64 editor = tableHandle.dataEditor()
65 editor.deleteRows( condition, conditionbindDict )
67 raise Exception, str(e)
70 """Drop specified table.
72 self.__schema.dropIfExistsTable( tableName )
74 """Tell whether table exists
77 self.__schema.tableHandle(tableName)
79 except coral.Exception, e:
82 if __name__ ==
"__main__":