Skip to content

Commit 3799dd9

Browse files
committed
This checks my database to check my master tables are there
It checks the version is ok, then checks the tables exist so I know if anyone has dropped the tables etc
1 parent a62cd83 commit 3799dd9

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

sqlite_table_check.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 ("\nCurrently " + master_db + " is on SQLite version: %s" % data + " - OK -\n")
31+
else:
32+
print ("\nDB On different version than master version - !!!!! \n")
33+
conn.close()
34+
35+
print ("\nCheckling " + 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

Comments
 (0)