CMS 3D CMS Logo

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.

00100                                        :
00101  try:
00102 
00103    description = coral.TableDescription()
00104    description.setName( tableName )
00105    table = schema.tableHandle(tableName )
00106 
00107    numberOfColumns = table.description().numberOfColumns()
00108    print "Table " , tableName
00109    print "Columns : " , numberOfColumns  
00110    for  i in range(0, numberOfColumns):
00111      column = table.description().columnDescription( i )
00112      print "" , column.name() , " (" , column.type() , ")"
00113      if ( column.isUnique() ): 
00114       print "      UNIQUE";
00115      if ( column.isNotNull() ):
00116       print "      NOT NULL"
00117 
00118    if ( table.description().hasPrimaryKey() ):
00119      columnNames = table.description().primaryKey().columnNames()
00120      print ""
00121      print "Primary key defined for column :"
00122      for iColumn in columnNames:
00123       print "      ",iColumn , " "
00124 
00125    numberOfUniqueConstraints = table.description().numberOfUniqueConstraints()
00126    print ""
00127    print "Unique Constraints : " , numberOfUniqueConstraints
00128    for i in range( 0, numberOfUniqueConstraints ):
00129      uniqueConstraint = table.description().uniqueConstraint( i )
00130      print "" , uniqueConstraint.name() , " defined for column"
00131      columnNames = uniqueConstraint.columnNames()
00132      for iColumn in columnNames:
00133        print "      ",iColumn
00134 
00135    numberOfIndices = table.description().numberOfIndices()
00136    print ""
00137    print "Index :  " , numberOfIndices
00138    for i in range(0, numberOfIndices ):
00139      index = table.description().index( i )
00140      print "" , index.name()
00141      if ( index.isUnique() ):
00142       print " (UNIQUE)"
00143      print " defined for column"
00144      columnNames = index.columnNames()
00145      for iColumn in columnNames:
00146        print "      ",iColumn
00147 
00148    numberOfForeignKeys = table.description().numberOfForeignKeys()
00149    print "" 
00150    print "Foreign Keys : " , numberOfForeignKeys
00151    for i in range(0, numberOfForeignKeys):
00152      foreignKey = table.description().foreignKey( i )
00153      print "" , foreignKey.name() , " defined for column"
00154      columnNames = foreignKey.columnNames()
00155      for iColumn in columnNames:
00156        print "      ",iColumn
00157      print " references -> " , foreignKey.referencedTableName() , "on Column "; 
00158      columnNamesR = foreignKey.referencedColumnNames()
00159      for iColumn in columnNamesR:
00160        print "      ",iColumn
00161 
00162    print "--------------------------------------"
00163 
00164  except Exception, e:
00165   raise Exception (" " + str(e))
00166   return False
00167 
#For printing the View Information
def python::listobjects::_printViewInfo (   schema,
  viewName 
) [private]

Definition at line 168 of file listobjects.py.

00169                                      :
00170  try:
00171 
00172    view = schema.viewHandle(viewName )
00173    numberOfColumns = view.numberOfColumns()
00174    print "View " , view.name()
00175    print "has", " ", numberOfColumns , " columns :"
00176    for i in range( 0,numberOfColumns ):
00177     column = view.column( i )
00178     print "" , column.name(), " (", column.type() , ")"
00179     if ( column.isUnique() ):
00180      print "      UNIQUE"
00181     if ( column.isNotNull() ):
00182      print "      NOT NULL"
00183 
00184    print " definition string : " , view.definition()
00185 
00186    print "--------------------------------------"
00187 
00188  except Exception, e:
00189   raise Exception (" " + str(e))
00190   return False
00191 
#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.

00012                             :
00013  try:
00014 
00015   dTableInfo=listobjects( schema )
00016 
00017   print "--------------------------------------"
00018   print "Listing Table Description "
00019   print "--------------------------------------"
00020   for key,value in dTableInfo.items():
00021     tableName= key
00022     _printTableInfo(schema,tableName)
00023 
00024   print "Listing View Information"
00025   print "--------------------------------------"
00026   for viewName in schema.listViews():
00027     _printViewInfo(schema,viewName)
00028 
00029  except Exception, e:
00030   raise Exception ("Error in dumpobjectlist method: " + str(e))
00031   return False
00032 
#Returns the list of tables ordered by hierarchy 
def python::listobjects::listobjects (   schema)

Definition at line 33 of file listobjects.py.

00034                          :
00035  try:
00036 
00037   listOfTableNames = schema.listTables()
00038 
00039   #Dictionaries are created for resolving table dependencies 
00040   dTable=mseqdict( [], {}) 
00041   dRefTable=mseqdict( [], {}) 
00042   dCopyTable=mseqdict( [], {}) 
00043 
00044   for tableName in listOfTableNames:
00045 
00046     #Add tablename to dictionary
00047     dTable.append(tableName,'')
00048     description = coral.TableDescription()
00049     description.setName( tableName )
00050     table = schema.tableHandle(tableName )
00051 
00052     numberOfForeignKeys = table.description().numberOfForeignKeys()
00053     for i in range(0, numberOfForeignKeys):
00054      foreignKey = table.description().foreignKey( i )
00055      columnNames = foreignKey.columnNames()
00056      #Add referenced tablename to dictionary
00057      dRefTable.append (tableName, foreignKey.referencedTableName()) 
00058      columnNamesR = foreignKey.referencedColumnNames()
00059 
00060   #For retrieving the tables in order of dependency 
00061   r1=mseqdict( [], {})
00062   r2=mseqdict( [], {})
00063 
00064   for rTable, refTable in dRefTable.items():
00065       for table in refTable:
00066         r1.append(table,'')
00067       r1.append(rTable,'')
00068 
00069   for rTable, refTable in r1.items():
00070     test=rTable
00071     for rTable1, refTable1 in dRefTable.items():
00072       if rTable1==test:
00073         for table in refTable1:
00074           if rTable1!=table:
00075              r2.append(table,'')
00076 
00077   for key,value in r2.items():
00078       r1.remove(key,'')
00079       dTable.remove(key,'')
00080 
00081   for key,value in r1.items():
00082       dTable.remove(key,'')
00083 
00084   for key,value in dTable.items():
00085     dCopyTable.append(key,'')
00086 
00087   for key,value in r2.items():
00088     dCopyTable.append(key,'')
00089   
00090   for key,value in r1.items():
00091     dCopyTable.append(key,'')
00092 
00093   return dCopyTable
00094 
00095  except Exception, e:
00096   raise Exception (" " + str(e))
00097   return False
00098 
#For printing the Table Information
def python::listobjects::listschema (   schema)

Definition at line 192 of file listobjects.py.

00193                         :
00194  try:
00195   listOfTableNames = schema.listTables()
00196 
00197   #Dictionaries are created for resolving table dependencies 
00198   dTable=mseqdict( [], {}) 
00199   dRefTable=mseqdict( [], {}) 
00200   dCopyTable=mseqdict( [], {}) 
00201   dCircTable=mseqdict( [], {}) 
00202 
00203   for tableName in listOfTableNames:
00204 
00205     #Add tablename to dictionary
00206     dTable.append(tableName,'')
00207     description = coral.TableDescription()
00208     description.setName( tableName )
00209     table = schema.tableHandle(tableName )
00210 
00211     numberOfForeignKeys = table.description().numberOfForeignKeys()
00212     for i in range(0, numberOfForeignKeys):
00213      foreignKey = table.description().foreignKey( i )
00214      columnNames = foreignKey.columnNames()
00215      #Add referenced tablename to dictionary
00216      dRefTable.append (tableName, foreignKey.referencedTableName()) 
00217      dCircTable.append (tableName, foreignKey.referencedTableName()) 
00218      columnNamesR = foreignKey.referencedColumnNames()
00219 
00220   #For checking circular dependency between the tables 
00221   d1=mseqdict( [], {})
00222   d2=mseqdict( [], {})
00223 
00224   for rTable, refTable in dCircTable.items():
00225     for table in refTable:
00226            d1.append(rTable,table)
00227 
00228   dCircTable.swap()
00229   for rTable, refTable in dCircTable.items():
00230     for table in refTable:
00231            d2.append(rTable,table)
00232 
00233   for key,value in d1.items():
00234      firsttable=key
00235      secondtable=value
00236      for key,value in d2.items():
00237         if key==firsttable and value==secondtable:
00238            raise Exception ("Circular Dependency exists between tables : "+firsttable,secondtable)
00239 
00240   #For retrieving the tables in order of dependency 
00241   r1=mseqdict( [], {})
00242   r2=mseqdict( [], {})
00243 
00244   for rTable, refTable in dRefTable.items():
00245       for table in refTable:
00246         r1.append(table,'')
00247       r1.append(rTable,'')
00248 
00249   for rTable, refTable in r1.items():
00250     test=rTable
00251     for rTable1, refTable1 in dRefTable.items():
00252       if rTable1==test:
00253         for table in refTable1:
00254           if rTable1!=table:
00255              r2.append(table,'')
00256 
00257   for key,value in r2.items():
00258       r1.remove(key,'')
00259       dTable.remove(key,'')
00260 
00261   for key,value in r1.items():
00262       dTable.remove(key,'')
00263 
00264   for key,value in dTable.items():
00265     dCopyTable.append(key,'')
00266 
00267   for key,value in r2.items():
00268     dCopyTable.append(key,'')
00269   
00270   for key,value in r1.items():
00271     dCopyTable.append(key,'')
00272 
00273   return dCopyTable
00274 
00275  except Exception, e:
00276   raise Exception (" " + str(e))
00277   return False
00278 
#Returns the tablename  for the specified table schema 
def python::listobjects::listtables (   schema,
  tablename 
)

Definition at line 279 of file listobjects.py.

00280                                   :
00281  try:
00282   listOfTableNames = schema.listTables()
00283 
00284   #Dictionaries are created for resolving table dependencies 
00285   dTable=mseqdict( [], {}) 
00286   dCopyTable=mseqdict( [], {}) 
00287 
00288   for tableName in listOfTableNames:
00289     if tablename==tableName: 
00290      #Add tablename to dictionary
00291      dTable.append(tableName,'')
00292      description = coral.TableDescription()
00293      description.setName( tableName )
00294      table = schema.tableHandle(tableName )
00295 
00296      numberOfForeignKeys = table.description().numberOfForeignKeys()
00297      for i in range(0, numberOfForeignKeys):
00298       foreignKey = table.description().foreignKey( i )
00299       columnNames = foreignKey.columnNames()
00300       columnNamesR = foreignKey.referencedColumnNames()
00301 
00302   for key,value in dTable.items():
00303        dCopyTable.append(key,'')
00304 
00305   return dCopyTable
00306 
00307  except Exception, e:
00308   raise Exception (" " + str(e))
00309   return False
00310 
#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.

00312                                    :
00313  try:
00314   listOfTableNames = schema.listTables()
00315 
00316   #Dictionaries are created for resolving table dependencies 
00317   dTable=mseqdict( [], {}) 
00318   dCircTable=mseqdict( [], {}) 
00319   dCopyTable=mseqdict( [], {}) 
00320   dTempTable=mseqdict( [], {}) 
00321 
00322   for table in listOfTableNames:
00323    for tableName in tableset:
00324     if tableName==table: 
00325      #Add tablename to dictionary
00326      dTable.append(tableName,'')
00327      description = coral.TableDescription()
00328      description.setName( tableName )
00329      table = schema.tableHandle(tableName )
00330 
00331      numberOfForeignKeys = table.description().numberOfForeignKeys()
00332      for i in range(0, numberOfForeignKeys):
00333       foreignKey = table.description().foreignKey( i )
00334       columnNames = foreignKey.columnNames()
00335       #Add referenced tablename to dictionary
00336       dTable.append (tableName, foreignKey.referencedTableName()) 
00337       dCircTable.append (tableName, foreignKey.referencedTableName()) 
00338       columnNamesR = foreignKey.referencedColumnNames()
00339 
00340   #For checking  circular dependency between the tables 
00341   d1=mseqdict( [], {})
00342   d2=mseqdict( [], {})
00343 
00344   for rTable, refTable in dCircTable.items():
00345     for table in refTable:
00346            d1.append(rTable,table)
00347 
00348   dCircTable.swap()
00349   for rTable, refTable in dCircTable.items():
00350     for table in refTable:
00351            d2.append(rTable,table)
00352 
00353   for key,value in d1.items():
00354      firsttable=key
00355      secondtable=value
00356      for key,value in d2.items():
00357         if key==firsttable and value==secondtable:
00358            raise Exception ("Circular Dependency exists between tables : "+firsttable,secondtable)
00359 
00360   #For retrieving the tables in order of dependency 
00361   r1=mseqdict( [], {})
00362   r2=mseqdict( [], {})
00363 
00364   for rTable, refTable in dTable.items():
00365       for table in refTable:
00366         r1.append(table,'')
00367       r1.append(rTable,'')
00368 
00369   for rTable, refTable in r1.items():
00370     test=rTable
00371     for rTable1, refTable1 in dTable.items():
00372       if rTable1==test:
00373         for table in refTable1:
00374           if rTable1!=table:
00375              r2.append(table,'')
00376 
00377   for key,value in r2.items():
00378       r1.remove(key,'')
00379 
00380   for key,value in r2.items():
00381     dTempTable.append(key,'')
00382   
00383   for key,value in r1.items():
00384     dTempTable.append(key,'')
00385 
00386   for key,value in dTempTable.items():
00387        iTable= key
00388        for table in tableset:
00389            if table==iTable:
00390               dCopyTable.append(key,'')
00391 
00392   return dCopyTable
00393 
00394  except Exception, e:
00395   raise Exception (" " + str(e))
00396   return False


Variable Documentation

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

Definition at line 402 of file listobjects.py.

Initial value:
00001 svc.connect( 'sqlite_file:source.db',
00002                            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.