How to browse an in memory sqlite database in python -


i need use in memory sqlite database following constructor:

db = sqlite3.connect(':memory:') 

but in debugging, find inconvenient because unlike file-based database, cannot browse database in debugger.

is there way browse database on fly?

you can write python scripts in debugger perform queries. example, consider following program:

import pdb import sqlite3 con = sqlite3.connect(':memory:') cur = con.cursor() cur.execute('create table abc (id int, sal int)') cur.execute('insert abc values(1,1)') cur.execute('select * abc') data = cur.fetchone() print (data) pdb.set_trace() x = "y" 

once enter debugging (pdb), can write queries following:

d:\sandbox\misc>python pyd.py (1, 1) > d:\sandbox\misc\pyd.py(11)<module>() -> x = "y" (pdb) cur.execute('insert abc values(2,2)') <sqlite3.cursor object @ 0x02bb04e0> (pdb) cur.execute('insert abc values(3,3)') <sqlite3.cursor object @ 0x02bb04e0> (pdb) cur.execute('select * abc') <sqlite3.cursor object @ 0x02bb04e0> (pdb) rows = cur.fetchall() (pdb) row in rows:    print (row) (1, 1) (2, 2) (3, 3) (pdb) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -