summaryrefslogtreecommitdiff
path: root/trunk/dimbola-info
blob: 095e470f3bc0d13ce857d531bfb0a8e2d901b375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
# Copyright (C) 2009  Lars Wirzenius <liw@liw.fi>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


'''Self-standing program to dump information about a Dimbola database.'''


import sqlite3
import sys


def dbinfo(filename):
    conn = sqlite3.connect(filename)
    c = conn.cursor()
    
    c.execute('select tbl_name, sql from sqlite_master where type="table"')
    tbl_names = []
    for tbl_name, sql in c:
        tbl_names.append(tbl_name)
        print sql
        print

    for tbl_name in tbl_names:
        print 'table:', tbl_name
        c.execute('select * from %s' % tbl_name)
        print 'columns:', ' '.join(t[0] for t in c.description)
        for row in c:
            for col in row:
                print repr(col),
            print
        print


def main():
    for filename in sys.argv[1:]:
        dbinfo(filename)


if __name__ == '__main__':
    main()