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