Mercurial > repos > jjohnson > query_tabular
comparison query_db.py @ 22:bed5018e7ae3 draft
Uploaded
author | jjohnson |
---|---|
date | Mon, 17 Jul 2017 15:22:04 -0400 |
parents | 357fe86f245d |
children |
comparison
equal
deleted
inserted
replaced
21:357fe86f245d | 22:bed5018e7ae3 |
---|---|
41 try: | 41 try: |
42 c = conn.cursor() | 42 c = conn.cursor() |
43 tables_query = TABLE_QUERY | 43 tables_query = TABLE_QUERY |
44 rslt = c.execute(tables_query).fetchall() | 44 rslt = c.execute(tables_query).fetchall() |
45 for table, sql in rslt: | 45 for table, sql in rslt: |
46 print("Table %s:" % table, file=sys.stderr) | 46 print("Table %s:" % table, file=outputFile) |
47 try: | 47 try: |
48 col_query = 'SELECT * FROM %s LIMIT 0' % table | 48 col_query = 'SELECT * FROM %s LIMIT 0' % table |
49 cur = conn.cursor().execute(col_query) | 49 cur = conn.cursor().execute(col_query) |
50 cols = [col[0] for col in cur.description] | 50 cols = [col[0] for col in cur.description] |
51 print(" Columns: %s" % cols, file=sys.stderr) | 51 print(" Columns: %s" % cols, file=outputFile) |
52 except Exception as exc: | 52 except Exception as exc: |
53 print("Error: %s" % exc, file=sys.stderr) | 53 print("Warning: %s" % exc, file=sys.stderr) |
54 except Exception as exc: | 54 except Exception as e: |
55 print("Error: %s" % exc, file=sys.stderr) | 55 exit('Error: %s' % (e)) |
56 exit(0) | 56 exit(0) |
57 | 57 |
58 | 58 |
59 def run_query(conn, query, outputFile, no_header=False): | 59 def run_query(conn, query, outputFile, no_header=False): |
60 cur = conn.cursor() | 60 cur = conn.cursor() |