Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

daodump.py 2.2KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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(
  14. "Table %s - Fields: %d, Attributes:%d"
  15. % (tab.Name, len(tab.Fields), tab.Attributes)
  16. )
  17. if bDeep:
  18. DumpFields(tab.Fields)
  19. def DumpFields(fields):
  20. for field in fields:
  21. print(
  22. " %s, size=%d, reqd=%d, type=%d, defVal=%s"
  23. % (
  24. field.Name,
  25. field.Size,
  26. field.Required,
  27. field.Type,
  28. str(field.DefaultValue),
  29. )
  30. )
  31. def DumpRelations(db, bDeep=1):
  32. for relation in db.Relations:
  33. print(
  34. "Relation %s - %s->%s"
  35. % (relation.Name, relation.Table, relation.ForeignTable)
  36. )
  37. #### This dont work. TLB says it is a Fields collection, but apparently not!
  38. #### if bDeep: DumpFields(relation.Fields)
  39. def DumpAllContainers(db, bDeep=1):
  40. for cont in db.Containers:
  41. print("Container %s - %d documents" % (cont.Name, len(cont.Documents)))
  42. if bDeep:
  43. DumpContainerDocuments(cont)
  44. def DumpContainerDocuments(container):
  45. for doc in container.Documents:
  46. import time
  47. timeStr = time.ctime(int(doc.LastUpdated))
  48. print(" %s - updated %s (" % (doc.Name, timeStr), end=" ")
  49. print(doc.LastUpdated, ")") # test the _print_ method?
  50. def TestEngine(engine):
  51. import sys
  52. if len(sys.argv) > 1:
  53. dbName = sys.argv[1]
  54. else:
  55. dbName = "e:\\temp\\TestPython.mdb"
  56. db = engine.OpenDatabase(dbName)
  57. DumpDB(db)
  58. def test():
  59. for progid in ("DAO.DBEngine.36", "DAO.DBEngine.35", "DAO.DBEngine.30"):
  60. try:
  61. ob = win32com.client.gencache.EnsureDispatch(progid)
  62. except pythoncom.com_error:
  63. print(progid, "does not seem to be installed")
  64. else:
  65. TestEngine(ob)
  66. break
  67. if __name__ == "__main__":
  68. test()