python - How to display db table names -


the end goal modify firefox cookies.sqlite db before starting firefox.

at present, want display tables in db. copied cookies.sqlite db desktop. i'm working db on desktop.

this first time using sqlite. copied code, i'm not able read tables in db. list of tables, db schema, dump etc using python sqlite3 api

here in terminal. see listing of tables.

me $ ls cookies.sqlite  cookies.sqlite me $ sqlite3 cookies.sqlite sqlite version 3.8.10.2 2015-05-20 18:17:19 enter ".help" usage hints. sqlite> .tables moz_cookies sqlite> .exit me $ # run python script me $ ./sqltutorial.bash  sqlite version: 3.8.10.2 table records... [] more table records... me $ cat dump.sql begin transaction; commit; me $  

python code. want display tables in cookie.sqlite db.

#! /bin/python   import sqlite3 lite import sys  con = lite.connect('cookie.sqlite')  con:      cur = con.cursor()         cur.execute('select sqlite_version()')      data = cur.fetchone()      print ("sqlite version: %s" % data)  print ("table records...")  cursor = con.cursor() cursor.execute("select name sqlite_master type='table';") print(cursor.fetchall())  print ("more table records...")  open('dump.sql', 'w') f:     line in con.iterdump():         f.write('%s\n' % line) 

as noticed, database name cookies.sqlite not cookie.sqlite.

why didn't error? though python error out on. con = lite.connect('cookie.sqlite')

connecting sqlite database either opens existing database file, or creates new 1 if database didn't exist.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -