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
59
60
61
|
#!/usr/bin/env python3.1
#-*- coding: utf-8 -*-
""" Testing the cmd interface """
import cmd
import sys
import sqlite3
class commandPromt(cmd.Cmd):
""" Testing here """
# init of DB and shit
conn = sqlite3.connect("./awnsers.sqlite")
db = conn.cursor()
startQueryShow = "select * from awnsers where("
startQueryCount = "select count(*) from awnsers 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 = commandPromt.startQueryShow + line + commandPromt.endQuery
try:
result = commandPromt.db.execute(query)
except:
print("Dave, I can not show you that....")
else:
for row in result:
print(row)
def do_count(self,line):
""" counts the query where
IE: select count(*) from <table> where <Command>
example:
count test2 = 1 and test = 1"""
query = commandPromt.startQueryCount + line + commandPromt.endQuery
try:
result = commandPromt.db.execute(query)
except:
print("Dave, I can not count that....")
else:
for row in result:
print(row[0])
#TODO: Add a countAll command, it will show the numbor of each true value in the DB.
#IE:
#gud: 13
#vegan: 4
#etc etc.
def do_exit(self,line):
import awnsers_and_db_edit
print("====== returning to main menu ======")##FIXME: why is this not printed before going into the main menu?
awnsers_and_db_edit.menu()
def de_EOF(self, line):
return(true)
|