/+junk/Dataanalys

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/Dataanalys

« back to all changes in this revision

Viewing changes to cmd_test.py

  • Committer: Gustav Hartvigsson
  • Date: 2010-12-22 18:59:19 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20101222185919-xa4ot5ytlbiepf4w
Added a camand line interface, and finished up the awnser sheet thingy...

Show diffs side-by-side

added added

removed removed

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