In [1]:
import sqlite3
import os
import sys
print(sqlite3.version)
In [2]:
import platform
print(platform.python_version())
print(platform.python_version_tuple())
In [3]:
sqlitedb = os.path.join(os.path.expanduser('~'),'Box Sync', 'GradSchoolStuff', 'MastersProject', 'mimic_radreports.sqlite')
if not (os.path.exists(sqlitedb)):
print("Specified database does not exist")
sys.exit()
In [4]:
connection = sqlite3.connect(sqlitedb)
with connection:
cursor = connection.cursor()
cursor.execute('select * from sqlite_master')
row = cursor.fetchone()
while row:
print(row)
row = cursor.fetchone()
In [5]:
# PRAGMA allows you to get metadata about a table
with connection:
cur = connection.cursor()
cur.execute('PRAGMA table_info(sqlite_master)')
data = cur.fetchall()
for d in data:
print(d)
In [6]:
with connection:
cursor = connection.cursor()
cursor.execute('select * from sqlite_master')
rows = cursor.fetchall()
for row in rows:
print('-----------------')
print('type: ', row[0])
print('name: ', row[1])
print('tbl_name: ', row[2])
print('rootpage: ', row[3])
print('sql: ', row[4])
#for col in row:
# print(col, end=" ")
#print('')
In [7]:
with connection:
cur = connection.cursor()
cur.execute('select count(*) from reports')
data = cur.fetchall()
print('Total rows in REPORTS table: ', data[0][0])
In [12]:
with connection:
cur = connection.cursor()
cur.execute('select * from reports limit 5')
col_names = [cn[0] for cn in cur.description]
rows = cur.fetchall()
for row in rows:
for i,col in enumerate(row):
print('++++++', col_names[i], ': ', col)
print('----------------- END ROW -----------------')
In [ ]: