3 from multivaluedict
import mseqdict
7 Dumps the list of tables and views grouped and ordered by hierarchy, specifying the existing constraints and indexes.
8 Input parameter schema : a schema object, obtained by the sessionproxy object
16 print "--------------------------------------"
17 print "Listing Table Description "
18 print "--------------------------------------"
19 for key,value
in dTableInfo.items():
23 print "Listing View Information"
24 print "--------------------------------------"
25 for viewName
in schema.listViews():
29 raise Exception (
"Error in dumpobjectlist method: " + str(e))
36 listOfTableNames = schema.listTables()
39 dTable=mseqdict( [], {})
40 dRefTable=mseqdict( [], {})
41 dCopyTable=mseqdict( [], {})
43 for tableName
in listOfTableNames:
46 dTable.append(tableName,
'')
47 description = coral.TableDescription()
48 description.setName( tableName )
49 table = schema.tableHandle(tableName )
51 numberOfForeignKeys = table.description().numberOfForeignKeys()
52 for i
in range(0, numberOfForeignKeys):
53 foreignKey = table.description().foreignKey( i )
54 columnNames = foreignKey.columnNames()
56 dRefTable.append (tableName, foreignKey.referencedTableName())
57 columnNamesR = foreignKey.referencedColumnNames()
63 for rTable, refTable
in dRefTable.items():
64 for table
in refTable:
68 for rTable, refTable
in r1.items():
70 for rTable1, refTable1
in dRefTable.items():
72 for table
in refTable1:
76 for key,value
in r2.items():
80 for key,value
in r1.items():
83 for key,value
in dTable.items():
84 dCopyTable.append(key,
'')
86 for key,value
in r2.items():
87 dCopyTable.append(key,
'')
89 for key,value
in r1.items():
90 dCopyTable.append(key,
'')
95 raise Exception (
" " + str(e))
102 description = coral.TableDescription()
103 description.setName( tableName )
104 table = schema.tableHandle(tableName )
106 numberOfColumns = table.description().numberOfColumns()
107 print "Table " , tableName
108 print "Columns : " , numberOfColumns
109 for i
in range(0, numberOfColumns):
110 column = table.description().columnDescription( i )
111 print "" , column.name() ,
" (" , column.type() ,
")"
112 if ( column.isUnique() ):
114 if ( column.isNotNull() ):
117 if ( table.description().hasPrimaryKey() ):
118 columnNames = table.description().primaryKey().columnNames()
120 print "Primary key defined for column :"
121 for iColumn
in columnNames:
122 print " ",iColumn ,
" "
124 numberOfUniqueConstraints = table.description().numberOfUniqueConstraints()
126 print "Unique Constraints : " , numberOfUniqueConstraints
127 for i
in range( 0, numberOfUniqueConstraints ):
128 uniqueConstraint = table.description().uniqueConstraint( i )
129 print "" , uniqueConstraint.name() ,
" defined for column"
130 columnNames = uniqueConstraint.columnNames()
131 for iColumn
in columnNames:
134 numberOfIndices = table.description().numberOfIndices()
136 print "Index : " , numberOfIndices
137 for i
in range(0, numberOfIndices ):
138 index = table.description().
index( i )
139 print "" , index.name()
140 if ( index.isUnique() ):
142 print " defined for column"
143 columnNames = index.columnNames()
144 for iColumn
in columnNames:
147 numberOfForeignKeys = table.description().numberOfForeignKeys()
149 print "Foreign Keys : " , numberOfForeignKeys
150 for i
in range(0, numberOfForeignKeys):
151 foreignKey = table.description().foreignKey( i )
152 print "" , foreignKey.name() ,
" defined for column"
153 columnNames = foreignKey.columnNames()
154 for iColumn
in columnNames:
156 print " references -> " , foreignKey.referencedTableName() ,
"on Column ";
157 columnNamesR = foreignKey.referencedColumnNames()
158 for iColumn
in columnNamesR:
161 print "--------------------------------------"
164 raise Exception (
" " + str(e))
171 view = schema.viewHandle(viewName )
172 numberOfColumns = view.numberOfColumns()
173 print "View " , view.name()
174 print "has",
" ", numberOfColumns ,
" columns :"
175 for i
in range( 0,numberOfColumns ):
176 column = view.column( i )
177 print "" , column.name(),
" (", column.type() ,
")"
178 if ( column.isUnique() ):
180 if ( column.isNotNull() ):
183 print " definition string : " , view.definition()
185 print "--------------------------------------"
188 raise Exception (
" " + str(e))
194 listOfTableNames = schema.listTables()
197 dTable=mseqdict( [], {})
198 dRefTable=mseqdict( [], {})
199 dCopyTable=mseqdict( [], {})
200 dCircTable=mseqdict( [], {})
202 for tableName
in listOfTableNames:
205 dTable.append(tableName,
'')
206 description = coral.TableDescription()
207 description.setName( tableName )
208 table = schema.tableHandle(tableName )
210 numberOfForeignKeys = table.description().numberOfForeignKeys()
211 for i
in range(0, numberOfForeignKeys):
212 foreignKey = table.description().foreignKey( i )
213 columnNames = foreignKey.columnNames()
215 dRefTable.append (tableName, foreignKey.referencedTableName())
216 dCircTable.append (tableName, foreignKey.referencedTableName())
217 columnNamesR = foreignKey.referencedColumnNames()
223 for rTable, refTable
in dCircTable.items():
224 for table
in refTable:
225 d1.append(rTable,table)
228 for rTable, refTable
in dCircTable.items():
229 for table
in refTable:
230 d2.append(rTable,table)
232 for key,value
in d1.items():
235 for key,value
in d2.items():
236 if key==firsttable
and value==secondtable:
237 raise Exception (
"Circular Dependency exists between tables : "+firsttable,secondtable)
243 for rTable, refTable
in dRefTable.items():
244 for table
in refTable:
248 for rTable, refTable
in r1.items():
250 for rTable1, refTable1
in dRefTable.items():
252 for table
in refTable1:
256 for key,value
in r2.items():
258 dTable.remove(key,
'')
260 for key,value
in r1.items():
261 dTable.remove(key,
'')
263 for key,value
in dTable.items():
264 dCopyTable.append(key,
'')
266 for key,value
in r2.items():
267 dCopyTable.append(key,
'')
269 for key,value
in r1.items():
270 dCopyTable.append(key,
'')
275 raise Exception (
" " + str(e))
281 listOfTableNames = schema.listTables()
284 dTable=mseqdict( [], {})
285 dCopyTable=mseqdict( [], {})
287 for tableName
in listOfTableNames:
288 if tablename==tableName:
290 dTable.append(tableName,
'')
291 description = coral.TableDescription()
292 description.setName( tableName )
293 table = schema.tableHandle(tableName )
295 numberOfForeignKeys = table.description().numberOfForeignKeys()
296 for i
in range(0, numberOfForeignKeys):
297 foreignKey = table.description().foreignKey( i )
298 columnNames = foreignKey.columnNames()
299 columnNamesR = foreignKey.referencedColumnNames()
301 for key,value
in dTable.items():
302 dCopyTable.append(key,
'')
307 raise Exception (
" " + str(e))
313 listOfTableNames = schema.listTables()
316 dTable=mseqdict( [], {})
317 dCircTable=mseqdict( [], {})
318 dCopyTable=mseqdict( [], {})
319 dTempTable=mseqdict( [], {})
321 for table
in listOfTableNames:
322 for tableName
in tableset:
325 dTable.append(tableName,
'')
326 description = coral.TableDescription()
327 description.setName( tableName )
328 table = schema.tableHandle(tableName )
330 numberOfForeignKeys = table.description().numberOfForeignKeys()
331 for i
in range(0, numberOfForeignKeys):
332 foreignKey = table.description().foreignKey( i )
333 columnNames = foreignKey.columnNames()
335 dTable.append (tableName, foreignKey.referencedTableName())
336 dCircTable.append (tableName, foreignKey.referencedTableName())
337 columnNamesR = foreignKey.referencedColumnNames()
343 for rTable, refTable
in dCircTable.items():
344 for table
in refTable:
345 d1.append(rTable,table)
348 for rTable, refTable
in dCircTable.items():
349 for table
in refTable:
350 d2.append(rTable,table)
352 for key,value
in d1.items():
355 for key,value
in d2.items():
356 if key==firsttable
and value==secondtable:
357 raise Exception (
"Circular Dependency exists between tables : "+firsttable,secondtable)
363 for rTable, refTable
in dTable.items():
364 for table
in refTable:
368 for rTable, refTable
in r1.items():
370 for rTable1, refTable1
in dTable.items():
372 for table
in refTable1:
376 for key,value
in r2.items():
379 for key,value
in r2.items():
380 dTempTable.append(key,
'')
382 for key,value
in r1.items():
383 dTempTable.append(key,
'')
385 for key,value
in dTempTable.items():
387 for table
in tableset:
389 dCopyTable.append(key,
'')
394 raise Exception (
" " + str(e))
397 if __name__ ==
"__main__":
398 svc = coral.ConnectionService()
399 session = svc.connect(
'sqlite_file:source.db',
400 accessMode = coral.access_Update )
401 session.transaction().
start(
True)
402 schema=session.nominalSchema()
403 print 'TEST listobjects'
405 print 'TEST dumpobjectlist'
407 print 'TEST listtables'
410 session.transaction().commit()