0

Is there a pythonistic way available to search all the tables and columns of an Sqlite3 database? The only inputs would be the name of the sqlite DB file or a raw input.

I am trying to write a forensics tool and want to search sqlite files for a specific string.

2
Contributors
2
Replies
56
Views
3 Years
Discussion Span
Last Post by Gribouillis
0

This works for me with sqlalchemy

from sqlalchemy import create_engine
from sqlalchemy.engine import reflection
engine = create_engine('sqlite:///menus.sqlite') # //// for abs path
insp = reflection.Inspector.from_engine(engine)
print insp.get_table_names() # print list of table names
print insp.get_columns(u'menu') # print list of dicts, each containing info about a column in table 'menu'

reflection
connect strings

Edited by Gribouillis

0

Here is another way without sqlalchemy

import sqlite3
conn = sqlite3.connect('menus.sqlite')
cur = conn.cursor()
s = "PRAGMA table_info(`menu`)"
try:
    cur.execute(s)
    print(cur.fetchall())
finally:
    cur.close()
    conn.close()

See table_info and also try the pragma in sqliteman to see the result.

Tables are rows of type 'table' in table sqlite_master.

See also this code snippet.

Edited by Gribouillis

Attachments table_info.png 93.94 KB
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.