diff options
author | itsme <itsme@xs4all.nl> | 2021-07-13 21:19:25 +0200 |
---|---|---|
committer | itsme <itsme@xs4all.nl> | 2021-07-13 21:19:25 +0200 |
commit | 40b8b1b16a50360f6a6cbd7a65198f0414ce98bf (patch) | |
tree | b99abf6be8915acfd6c34a8388d511dbb1573acb | |
parent | f004854d5f2a0bc246a2524ddb843e369b21de99 (diff) |
example showing how to use db.enumerate
-rw-r--r-- | dumpdbfields.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/dumpdbfields.py b/dumpdbfields.py new file mode 100644 index 0000000..131cfa3 --- /dev/null +++ b/dumpdbfields.py | |||
@@ -0,0 +1,33 @@ | |||
1 | from crodump import Database | ||
2 | import os | ||
3 | import os.path | ||
4 | from hexdump import asasc | ||
5 | |||
6 | class Cls: pass | ||
7 | |||
8 | def main(): | ||
9 | import sys | ||
10 | dbpath = sys.argv[1] if len(sys.argv)>1 else os.path.join(os.getenv("HOME"), "prj/cronos") | ||
11 | args = Cls() | ||
12 | args.verbose = False | ||
13 | |||
14 | for path, _, files in os.walk(dbpath): | ||
15 | if any(_ for _ in files if _.lower()=="crostru.dat"): | ||
16 | print(path) | ||
17 | |||
18 | db = Database(path) | ||
19 | for tab in db.enumerate_tables(): | ||
20 | tab.dump(args) | ||
21 | print("nr=%d" % db.nrofrecords()) | ||
22 | i = 0 | ||
23 | for rec in db.enumerate_records(tab): | ||
24 | # beware to skip tab.fields[0], which is the 'sysnum' | ||
25 | for field, fielddef in zip(rec, tab.fields[1:]): | ||
26 | print(">> %s -- %s" % (fielddef, asasc(field))) | ||
27 | i += 1 | ||
28 | if i>100: break | ||
29 | |||
30 | |||
31 | if __name__=="__main__": | ||
32 | main() | ||
33 | |||