1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!/usr/bin/env python3.1
""" Testing the cmd interface """
import cmd
import sys
import sqlite3
class cmdTest(cmd.Cmd):
""" Testing here """
# init of DB and shit
conn = sqlite3.connect("./test.sqlite")
db = conn.cursor()
startQueryShow = "select * from test1 where("
startQueryCount = "select count(*) from test1 where("
endQuery =");"
def do_show(self,line):
""" Shows the query where
IE: select * from <table> where <Command>
example:
show test2 = 1 and test = 1"""
query = cmdTest.startQueryShow + line + cmdTest.endQuery
try:
result = cmdTest.db.execute(query)
except:
print("Dave, I can not show you that....")
else:
for row in result:
print(row)
def do_count(self,line):
""" Shows the query where
IE: select count(*) from <table> where <Command>
example:
count test2 = 1 and test = 1"""
query = cmdTest.startQueryCount + line + cmdTest.endQuery
try:
result = cmdTest.db.execute(query)
except:
print("Dave, I can not count that....")
else:
for row in result:
print(row[0])
def do_exit(self,line):
exit()
def de_EOF(self, line):
return(true)
if __name__ == '__main__':
cmdTest().cmdloop()
|