CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
python.listobjects Namespace Reference

Functions

def _printTableInfo
 
def _printViewInfo
 
def dumpobjectlist
 
def listobjects
 
def listschema
 
def listtables
 
def listtableset
 

Variables

tuple schema = session.nominalSchema()
 
tuple session
 
tuple svc = coral.ConnectionService()
 

Function Documentation

def python.listobjects._printTableInfo (   schema,
  tableName 
)
private

Definition at line 99 of file listobjects.py.

References getHLTprescales.index.

Referenced by python.listobjects.dumpobjectlist().

99 
100 def _printTableInfo( schema,tableName ):
101  try:
102 
103  description = coral.TableDescription()
104  description.setName( tableName )
105  table = schema.tableHandle(tableName )
106 
107  numberOfColumns = table.description().numberOfColumns()
108  print "Table " , tableName
109  print "Columns : " , numberOfColumns
110  for i in range(0, numberOfColumns):
111  column = table.description().columnDescription( i )
112  print "" , column.name() , " (" , column.type() , ")"
113  if ( column.isUnique() ):
114  print " UNIQUE";
115  if ( column.isNotNull() ):
116  print " NOT NULL"
117 
118  if ( table.description().hasPrimaryKey() ):
119  columnNames = table.description().primaryKey().columnNames()
120  print ""
121  print "Primary key defined for column :"
122  for iColumn in columnNames:
123  print " ",iColumn , " "
124 
125  numberOfUniqueConstraints = table.description().numberOfUniqueConstraints()
126  print ""
127  print "Unique Constraints : " , numberOfUniqueConstraints
128  for i in range( 0, numberOfUniqueConstraints ):
129  uniqueConstraint = table.description().uniqueConstraint( i )
130  print "" , uniqueConstraint.name() , " defined for column"
131  columnNames = uniqueConstraint.columnNames()
132  for iColumn in columnNames:
133  print " ",iColumn
134 
135  numberOfIndices = table.description().numberOfIndices()
136  print ""
137  print "Index : " , numberOfIndices
138  for i in range(0, numberOfIndices ):
139  index = table.description().index( i )
140  print "" , index.name()
141  if ( index.isUnique() ):
142  print " (UNIQUE)"
143  print " defined for column"
144  columnNames = index.columnNames()
145  for iColumn in columnNames:
146  print " ",iColumn
147 
148  numberOfForeignKeys = table.description().numberOfForeignKeys()
149  print ""
150  print "Foreign Keys : " , numberOfForeignKeys
151  for i in range(0, numberOfForeignKeys):
152  foreignKey = table.description().foreignKey( i )
153  print "" , foreignKey.name() , " defined for column"
154  columnNames = foreignKey.columnNames()
155  for iColumn in columnNames:
156  print " ",iColumn
157  print " references -> " , foreignKey.referencedTableName() , "on Column ";
158  columnNamesR = foreignKey.referencedColumnNames()
159  for iColumn in columnNamesR:
160  print " ",iColumn
161 
162  print "--------------------------------------"
163 
164  except Exception, e:
165  raise Exception (" " + str(e))
166  return False
167 
#For printing the View Information
def python.listobjects._printViewInfo (   schema,
  viewName 
)
private

Definition at line 168 of file listobjects.py.

Referenced by python.listobjects.dumpobjectlist().

169 def _printViewInfo( schema,viewName ):
170  try:
171 
172  view = schema.viewHandle(viewName )
173  numberOfColumns = view.numberOfColumns()
174  print "View " , view.name()
175  print "has", " ", numberOfColumns , " columns :"
176  for i in range( 0,numberOfColumns ):
177  column = view.column( i )
178  print "" , column.name(), " (", column.type() , ")"
179  if ( column.isUnique() ):
180  print " UNIQUE"
181  if ( column.isNotNull() ):
182  print " NOT NULL"
183 
184  print " definition string : " , view.definition()
185 
186  print "--------------------------------------"
187 
188  except Exception, e:
189  raise Exception (" " + str(e))
190  return False
191 
#Returns the list of tables ordered by hierarchy and checks for circular dependency between tables in source schema
def python.listobjects.dumpobjectlist (   schema)

Definition at line 11 of file listobjects.py.

References python.listobjects._printTableInfo(), python.listobjects._printViewInfo(), and python.listobjects.listobjects().

11 
12 def dumpobjectlist( schema ):
13  try:
14 
15  dTableInfo=listobjects( schema )
16 
17  print "--------------------------------------"
18  print "Listing Table Description "
19  print "--------------------------------------"
20  for key,value in dTableInfo.items():
21  tableName= key
22  _printTableInfo(schema,tableName)
23 
24  print "Listing View Information"
25  print "--------------------------------------"
26  for viewName in schema.listViews():
27  _printViewInfo(schema,viewName)
28 
29  except Exception, e:
30  raise Exception ("Error in dumpobjectlist method: " + str(e))
31  return False
32 
#Returns the list of tables ordered by hierarchy
def python.listobjects.listobjects (   schema)

Definition at line 33 of file listobjects.py.

Referenced by python.exporter.exporter.copydata(), python.exporter.exporter.copyschema(), and python.listobjects.dumpobjectlist().

33 
34 def listobjects( schema ):
35  try:
36 
37  listOfTableNames = schema.listTables()
38 
39  #Dictionaries are created for resolving table dependencies
40  dTable=mseqdict( [], {})
41  dRefTable=mseqdict( [], {})
42  dCopyTable=mseqdict( [], {})
43 
44  for tableName in listOfTableNames:
45 
46  #Add tablename to dictionary
47  dTable.append(tableName,'')
48  description = coral.TableDescription()
49  description.setName( tableName )
50  table = schema.tableHandle(tableName )
51 
52  numberOfForeignKeys = table.description().numberOfForeignKeys()
53  for i in range(0, numberOfForeignKeys):
54  foreignKey = table.description().foreignKey( i )
55  columnNames = foreignKey.columnNames()
56  #Add referenced tablename to dictionary
57  dRefTable.append (tableName, foreignKey.referencedTableName())
58  columnNamesR = foreignKey.referencedColumnNames()
59 
60  #For retrieving the tables in order of dependency
61  r1=mseqdict( [], {})
62  r2=mseqdict( [], {})
63 
64  for rTable, refTable in dRefTable.items():
65  for table in refTable:
66  r1.append(table,'')
67  r1.append(rTable,'')
68 
69  for rTable, refTable in r1.items():
70  test=rTable
71  for rTable1, refTable1 in dRefTable.items():
72  if rTable1==test:
73  for table in refTable1:
74  if rTable1!=table:
75  r2.append(table,'')
76 
77  for key,value in r2.items():
78  r1.remove(key,'')
79  dTable.remove(key,'')
80 
81  for key,value in r1.items():
82  dTable.remove(key,'')
83 
84  for key,value in dTable.items():
85  dCopyTable.append(key,'')
86 
87  for key,value in r2.items():
88  dCopyTable.append(key,'')
89 
90  for key,value in r1.items():
91  dCopyTable.append(key,'')
92 
93  return dCopyTable
94 
95  except Exception, e:
96  raise Exception (" " + str(e))
97  return False
98 
#For printing the Table Information
def python.listobjects.listschema (   schema)

Definition at line 192 of file listobjects.py.

Referenced by python.exporter.exporter.copydata(), and python.exporter.exporter.copyschema().

193 def listschema( schema ):
194  try:
195  listOfTableNames = schema.listTables()
196 
197  #Dictionaries are created for resolving table dependencies
198  dTable=mseqdict( [], {})
199  dRefTable=mseqdict( [], {})
200  dCopyTable=mseqdict( [], {})
201  dCircTable=mseqdict( [], {})
202 
203  for tableName in listOfTableNames:
204 
205  #Add tablename to dictionary
206  dTable.append(tableName,'')
207  description = coral.TableDescription()
208  description.setName( tableName )
209  table = schema.tableHandle(tableName )
210 
211  numberOfForeignKeys = table.description().numberOfForeignKeys()
212  for i in range(0, numberOfForeignKeys):
213  foreignKey = table.description().foreignKey( i )
214  columnNames = foreignKey.columnNames()
215  #Add referenced tablename to dictionary
216  dRefTable.append (tableName, foreignKey.referencedTableName())
217  dCircTable.append (tableName, foreignKey.referencedTableName())
218  columnNamesR = foreignKey.referencedColumnNames()
219 
220  #For checking circular dependency between the tables
221  d1=mseqdict( [], {})
222  d2=mseqdict( [], {})
223 
224  for rTable, refTable in dCircTable.items():
225  for table in refTable:
226  d1.append(rTable,table)
227 
228  dCircTable.swap()
229  for rTable, refTable in dCircTable.items():
230  for table in refTable:
231  d2.append(rTable,table)
232 
233  for key,value in d1.items():
234  firsttable=key
235  secondtable=value
236  for key,value in d2.items():
237  if key==firsttable and value==secondtable:
238  raise Exception ("Circular Dependency exists between tables : "+firsttable,secondtable)
239 
240  #For retrieving the tables in order of dependency
241  r1=mseqdict( [], {})
242  r2=mseqdict( [], {})
243 
244  for rTable, refTable in dRefTable.items():
245  for table in refTable:
246  r1.append(table,'')
247  r1.append(rTable,'')
248 
249  for rTable, refTable in r1.items():
250  test=rTable
251  for rTable1, refTable1 in dRefTable.items():
252  if rTable1==test:
253  for table in refTable1:
254  if rTable1!=table:
255  r2.append(table,'')
256 
257  for key,value in r2.items():
258  r1.remove(key,'')
259  dTable.remove(key,'')
260 
261  for key,value in r1.items():
262  dTable.remove(key,'')
263 
264  for key,value in dTable.items():
265  dCopyTable.append(key,'')
266 
267  for key,value in r2.items():
268  dCopyTable.append(key,'')
269 
270  for key,value in r1.items():
271  dCopyTable.append(key,'')
272 
273  return dCopyTable
274 
275  except Exception, e:
276  raise Exception (" " + str(e))
277  return False
278 
#Returns the tablename for the specified table schema
def python.listobjects.listtables (   schema,
  tablename 
)

Definition at line 279 of file listobjects.py.

Referenced by python.exporter.exporter.copytabledata(), and python.exporter.exporter.copytableschema().

280 def listtables( schema,tablename ):
281  try:
282  listOfTableNames = schema.listTables()
283 
284  #Dictionaries are created for resolving table dependencies
285  dTable=mseqdict( [], {})
286  dCopyTable=mseqdict( [], {})
287 
288  for tableName in listOfTableNames:
289  if tablename==tableName:
290  #Add tablename to dictionary
291  dTable.append(tableName,'')
292  description = coral.TableDescription()
293  description.setName( tableName )
294  table = schema.tableHandle(tableName )
295 
296  numberOfForeignKeys = table.description().numberOfForeignKeys()
297  for i in range(0, numberOfForeignKeys):
298  foreignKey = table.description().foreignKey( i )
299  columnNames = foreignKey.columnNames()
300  columnNamesR = foreignKey.referencedColumnNames()
301 
302  for key,value in dTable.items():
303  dCopyTable.append(key,'')
304 
305  return dCopyTable
306 
307  except Exception, e:
308  raise Exception (" " + str(e))
309  return False
310 
#Returns the list of tables ordered by hierarchy for the specified list of tables and also checks for circular dependency between the tables
def python.listobjects.listtableset (   schema,
  tableset 
)

Definition at line 311 of file listobjects.py.

Referenced by python.exporter.exporter.copytablelistdata(), and python.exporter.exporter.copytablelistschema().

312 def listtableset( schema,tableset ):
313  try:
314  listOfTableNames = schema.listTables()
315 
316  #Dictionaries are created for resolving table dependencies
317  dTable=mseqdict( [], {})
318  dCircTable=mseqdict( [], {})
319  dCopyTable=mseqdict( [], {})
320  dTempTable=mseqdict( [], {})
321 
322  for table in listOfTableNames:
323  for tableName in tableset:
324  if tableName==table:
325  #Add tablename to dictionary
326  dTable.append(tableName,'')
327  description = coral.TableDescription()
328  description.setName( tableName )
329  table = schema.tableHandle(tableName )
330 
331  numberOfForeignKeys = table.description().numberOfForeignKeys()
332  for i in range(0, numberOfForeignKeys):
333  foreignKey = table.description().foreignKey( i )
334  columnNames = foreignKey.columnNames()
335  #Add referenced tablename to dictionary
336  dTable.append (tableName, foreignKey.referencedTableName())
337  dCircTable.append (tableName, foreignKey.referencedTableName())
338  columnNamesR = foreignKey.referencedColumnNames()
339 
340  #For checking circular dependency between the tables
341  d1=mseqdict( [], {})
342  d2=mseqdict( [], {})
343 
344  for rTable, refTable in dCircTable.items():
345  for table in refTable:
346  d1.append(rTable,table)
347 
348  dCircTable.swap()
349  for rTable, refTable in dCircTable.items():
350  for table in refTable:
351  d2.append(rTable,table)
352 
353  for key,value in d1.items():
354  firsttable=key
355  secondtable=value
356  for key,value in d2.items():
357  if key==firsttable and value==secondtable:
358  raise Exception ("Circular Dependency exists between tables : "+firsttable,secondtable)
359 
360  #For retrieving the tables in order of dependency
361  r1=mseqdict( [], {})
362  r2=mseqdict( [], {})
363 
364  for rTable, refTable in dTable.items():
365  for table in refTable:
366  r1.append(table,'')
367  r1.append(rTable,'')
368 
369  for rTable, refTable in r1.items():
370  test=rTable
371  for rTable1, refTable1 in dTable.items():
372  if rTable1==test:
373  for table in refTable1:
374  if rTable1!=table:
375  r2.append(table,'')
376 
377  for key,value in r2.items():
378  r1.remove(key,'')
379 
380  for key,value in r2.items():
381  dTempTable.append(key,'')
382 
383  for key,value in r1.items():
384  dTempTable.append(key,'')
385 
386  for key,value in dTempTable.items():
387  iTable= key
388  for table in tableset:
389  if table==iTable:
390  dCopyTable.append(key,'')
391 
392  return dCopyTable
393 
394  except Exception, e:
395  raise Exception (" " + str(e))
396  return False

Variable Documentation

tuple python.listobjects.schema = session.nominalSchema()

Definition at line 402 of file listobjects.py.

tuple python.listobjects.session
Initial value:
1 = svc.connect( 'sqlite_file:source.db',
2  accessMode = coral.access_Update )

Definition at line 399 of file listobjects.py.

tuple python.listobjects.svc = coral.ConnectionService()

Definition at line 398 of file listobjects.py.