daodump.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # import dao3032
  2. # No longer imported here - callers responsibility to load
  3. #
  4. import win32com.client
  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. def DumpTables(db, bDeep = 1):
  11. for tab in db.TableDefs:
  12. tab = db.TableDefs(tab.Name) # Redundant lookup for testing purposes.
  13. print("Table %s - Fields: %d, Attributes:%d" % (tab.Name, len(tab.Fields), tab.Attributes))
  14. if bDeep: DumpFields(tab.Fields)
  15. def DumpFields(fields):
  16. for field in fields:
  17. print(" %s, size=%d, reqd=%d, type=%d, defVal=%s" % (field.Name, field.Size, field.Required, field.Type, str(field.DefaultValue)))
  18. def DumpRelations(db, bDeep = 1):
  19. for relation in db.Relations:
  20. print("Relation %s - %s->%s" % (relation.Name, relation.Table, relation.ForeignTable))
  21. #### This dont work. TLB says it is a Fields collection, but apparently not!
  22. #### if bDeep: DumpFields(relation.Fields)
  23. def DumpAllContainers(db, bDeep = 1):
  24. for cont in db.Containers:
  25. print("Container %s - %d documents" % (cont.Name, len(cont.Documents)))
  26. if bDeep: DumpContainerDocuments(cont)
  27. def DumpContainerDocuments(container):
  28. for doc in container.Documents:
  29. import time
  30. timeStr = time.ctime(int(doc.LastUpdated))
  31. print(" %s - updated %s (" % (doc.Name, timeStr), end=' ')
  32. print(doc.LastUpdated,")") # test the _print_ method?
  33. def TestEngine(engine):
  34. import sys
  35. if len(sys.argv)>1:
  36. dbName = sys.argv[1]
  37. else:
  38. dbName = "e:\\temp\\TestPython.mdb"
  39. db = engine.OpenDatabase(dbName)
  40. DumpDB(db)
  41. def test():
  42. for progid in ("DAO.DBEngine.36", "DAO.DBEngine.35", "DAO.DBEngine.30"):
  43. try:
  44. ob = win32com.client.gencache.EnsureDispatch(progid)
  45. except pythoncom.com_error:
  46. print(progid, "does not seem to be installed")
  47. else:
  48. TestEngine(ob)
  49. break
  50. if __name__=='__main__':
  51. test()