1+ # Script Name : sqlite_table_check.py
2+ # Author : Craig Richards
3+ # Created : 07 June 2013
4+ # Last Modified :
5+ # Version : 1.0
6+
7+ # Modifications :
8+
9+ # Description : Checks the main SQLITE database to ensure all the tables should exist
10+
11+
12+ import sqlite3
13+ import sys
14+ import os
15+
16+ dropbox = os .getenv ("dropbox" )
17+ config = os .getenv ("my_config" )
18+ dbfile = ("Databases\jarvis.db" )
19+ listfile = ("sqlite_master_table.lst" )
20+ master_db = os .path .join (dropbox , dbfile )
21+ config_file = os .path .join (config , listfile )
22+ tablelist = open (config_file ,'r' );
23+
24+ conn = sqlite3 .connect (master_db )
25+ cursor = conn .cursor ()
26+ cursor .execute ('SELECT SQLITE_VERSION()' )
27+ data = cursor .fetchone ()
28+
29+ if str (data ) == "(u'3.6.21',)" :
30+ print ("\n Currently " + master_db + " is on SQLite version: %s" % data + " - OK -\n " )
31+ else :
32+ print ("\n DB On different version than master version - !!!!! \n " )
33+ conn .close ()
34+
35+ print ("\n Checkling " + master_db + " against " + config_file + "\n " )
36+
37+ for table in tablelist .readlines ():
38+ conn = sqlite3 .connect (master_db )
39+ cursor = conn .cursor ()
40+ cursor .execute ("select count(*) from sqlite_master where name = ?" ,(table .strip (), ))
41+ res = cursor .fetchone ()
42+
43+ if (res [0 ]):
44+ print ('[+] Table : ' + table .strip () + ' exists [+]' )
45+ else :
46+ print ('[-] Table : ' + table .strip () + ' does not exist [-]' )
47+
0 commit comments