sqlite> .tab
job snmptarget t1 t2 t3
sqlite> select name from sqlite_master where type = 'table';
job
t1
t2
snmptarget
t3
sqlite> .schema job
CREATE TABLE job (
id INTEGER PRIMARY KEY,
data VARCHAR
);
sqlite> select sql from sqlite_master where type = 'table' and name = 'job';
CREATE TABLE job (
id INTEGER PRIMARY KEY,
data VARCHAR
)
# Convert file existing_db.db to SQL dump file dump.sql
import sqlite3, os
con = sqlite3.connect('existing_db.db')
with open('dump.sql', 'w') as f:
for line in con.iterdump():
f.write('%s\n' % line)
con = sqlite3.connect('database.db')
cursor = con.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
print(cursor.fetchall())
$parser = new SqliteTableDefinitionParser;
$parser->parseColumnDefinitions('x INTEGER PRIMARY KEY, y DOUBLE, z DATETIME default \'2011-11-10\', name VARCHAR(100)');
import pandas as pd
import sqlite3
conn = sqlite3.connect("db.sqlite3")
table = pd.read_sql_query("SELECT name FROM sqlite_master WHERE type='table'", conn)
print(table)
conn = sqlite3.connect('example.db')
c = conn.cursor()
def table_info(c, conn):
'''
prints out all of the columns of every table in db
c : cursor object
conn : database connection object
'''
tables = c.execute("SELECT name FROM sqlite_master WHERE type='table';").fetchall()
for table_name in tables:
table_name = table_name[0] # tables is a list of single item tuples
table = pd.read_sql_query("SELECT * from {} LIMIT 0".format(table_name), conn)
print(table_name)
for col in table.columns:
print('\t' + col)
print()
table_info(c, conn)
Results will be:
table1
column1
column2
table2
column1
column2
column3
etc.