home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_win32com_test_daodump.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  2.1 KB  |  66 lines

  1. # import dao3032
  2. # No longer imported here - callers responsibility to load
  3. import win32com.client
  4.  
  5. def DumpDB(db, bDeep = 1):
  6.     # MUST be a DB object.
  7.     DumpTables(db,bDeep)
  8.     DumpRelations(db,bDeep)
  9.     DumpAllContainers(db,bDeep)
  10.  
  11. def DumpTables(db, bDeep = 1):
  12.     for tab in db.TableDefs:
  13.         tab = db.TableDefs(tab.Name) # Redundant lookup for testing purposes.
  14.         print "Table %s - Fields: %d, Attributes:%d" % (tab.Name, len(tab.Fields), tab.Attributes)
  15.         if bDeep: DumpFields(tab.Fields)
  16.  
  17. def DumpFields(fields):
  18.     for field in fields:
  19.         print "  %s, size=%d, reqd=%d, type=%d, defVal=%s" % (field.Name, field.Size, field.Required, field.Type, str(field.DefaultValue))
  20.  
  21. def DumpRelations(db, bDeep = 1):
  22.     for relation in db.Relations:
  23.         print "Relation %s - %s->%s" % (relation.Name, relation.Table, relation.ForeignTable)
  24.  
  25. #### This dont work.  TLB says it is a Fields collection, but apparently not!
  26. ####        if bDeep: DumpFields(relation.Fields)
  27.  
  28. def DumpAllContainers(db, bDeep = 1):
  29.     for cont in db.Containers:
  30.         print "Container %s - %d documents" % (cont.Name, len(cont.Documents))
  31.         if bDeep: DumpContainerDocuments(cont)
  32.  
  33. def DumpContainerDocuments(container):
  34.     for doc in container.Documents:
  35.         import time
  36.         timeStr = time.ctime(int(doc.LastUpdated))
  37.         print "  %s - updated %s (" % (doc.Name, timeStr),
  38.         print doc.LastUpdated,")" # test the _print_ method?
  39.  
  40. def TestEngine(engine):
  41.     import sys
  42.     if len(sys.argv)>1:
  43.         dbName = sys.argv[1]
  44.     else:
  45.         dbName = "e:\\temp\\TestPython.mdb"
  46.     db = engine.OpenDatabase(dbName)
  47.     DumpDB(db)
  48.     
  49. def test():
  50.     import win32com.client.gencache
  51.     if win32com.client.gencache.GetModuleForProgID("DAO.DBEngine.35") is None:
  52.         print "DAO 3.5 does not seem to be installed or have makepy support"
  53.     else:
  54.         TestEngine(win32com.client.Dispatch("DAO.DBEngine.35"))
  55.     
  56.     if win32com.client.gencache.GetModuleForProgID("DAO.DBEngine.30") is None:
  57.         print "DAO 3.0 does not seem to be installed or have makepy support"
  58.     else:
  59.         TestEngine(win32com.client.Dispatch("DAO.DBEngine.30"))
  60.     
  61.  
  62. if __name__=='__main__':
  63.     test()
  64.  
  65.