0001 # import dao3032 0002 # No longer imported here - callers responsibility to load 0003 # 0004 import win32com.client 0005 0006 def DumpDB(db, bDeep = 1): 0007 # MUST be a DB object. 0008 DumpTables(db,bDeep) 0009 DumpRelations(db,bDeep) 0010 DumpAllContainers(db,bDeep) 0011 0012 def DumpTables(db, bDeep = 1): 0013 for tab in db.TableDefs: 0014 tab = db.TableDefs(tab.Name) # Redundant lookup for testing purposes. 0015 print "Table %s - Fields: %d, Attributes:%d" % (tab.Name, len(tab.Fields), tab.Attributes) 0016 if bDeep: DumpFields(tab.Fields) 0017 0018 def DumpFields(fields): 0019 for field in fields: 0020 print " %s, size=%d, reqd=%d, type=%d, defVal=%s" % (field.Name, field.Size, field.Required, field.Type, str(field.DefaultValue)) 0021 0022 def DumpRelations(db, bDeep = 1): 0023 for relation in db.Relations: 0024 print "Relation %s - %s->%s" % (relation.Name, relation.Table, relation.ForeignTable) 0025 0026 #### This dont work. TLB says it is a Fields collection, but apparently not! 0027 #### if bDeep: DumpFields(relation.Fields) 0028 0029 def DumpAllContainers(db, bDeep = 1): 0030 for cont in db.Containers: 0031 print "Container %s - %d documents" % (cont.Name, len(cont.Documents)) 0032 if bDeep: DumpContainerDocuments(cont) 0033 0034 def DumpContainerDocuments(container): 0035 for doc in container.Documents: 0036 import time 0037 timeStr = time.ctime(int(doc.LastUpdated)) 0038 print " %s - updated %s (" % (doc.Name, timeStr), 0039 print doc.LastUpdated,")" # test the _print_ method? 0040 0041 def TestEngine(engine): 0042 import sys 0043 if len(sys.argv)>1: 0044 dbName = sys.argv[1] 0045 else: 0046 dbName = "e:\\temp\\TestPython.mdb" 0047 db = engine.OpenDatabase(dbName) 0048 DumpDB(db) 0049 0050 def test(): 0051 import win32com.client.gencache 0052 if win32com.client.gencache.GetModuleForProgID("DAO.DBEngine.35") is None: 0053 print "DAO 3.5 does not seem to be installed or have makepy support" 0054 else: 0055 TestEngine(win32com.client.Dispatch("DAO.DBEngine.35")) 0056 0057 if win32com.client.gencache.GetModuleForProgID("DAO.DBEngine.30") is None: 0058 print "DAO 3.0 does not seem to be installed or have makepy support" 0059 else: 0060 TestEngine(win32com.client.Dispatch("DAO.DBEngine.30")) 0061 0062 0063 if __name__=='__main__': 0064 test() 0065
Generated by PyXR 0.9.4