/+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 awnsers_and_db_edit.py

  • Committer: Gustav Hartvigsson
  • Date: 2010-12-20 22:10:56 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20101220221056-qk1b8vcuasp9uz2i
initial code commiinitial code committ

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
import sys
 
3
import sqlite3
 
4
 
 
5
 
 
6
## menu
 
7
def menu():
 
8
        ## menu options
 
9
        menuOptions="""1. show DB
 
10
2. edit DB
 
11
3. add to DB
 
12
4. exit"""
 
13
 
 
14
        print("select an option")
 
15
        print(menuOptions)
 
16
        menuOptionsInput = input(">>>>")
 
17
 
 
18
        #ifs and thens
 
19
        if(menuOptionsInput == 1):
 
20
                dbShow()
 
21
                
 
22
        elif(menuOptionsInput == 2):
 
23
                #run function 2
 
24
                print("test 2")
 
25
        elif(menuOptionsInput == 3):
 
26
                #run function 3
 
27
                print("test 3")
 
28
        elif(menuOptionsInput == 4):
 
29
                exit()
 
30
        else:
 
31
                menu()
 
32
        
 
33
 
 
34
 
 
35
## make connectiot to DB:
 
36
def dbConn():
 
37
        """ This functon connects to the DB and you gain access to its
 
38
        sql cammands via db.*
 
39
        IE: db.execute("insert into knights values('nii', 'sir') ") 
 
40
        the DB file is located in ./awnsers.sqlite"""
 
41
        conn = sqlite3.connect("./awnsers.sqlite") #makes the connection with the db file.
 
42
        db = conn.cursor()
 
43
        
 
44
        ##check if table exists:
 
45
        checkDB = db.execute(""" select 1 from sqlite_master where type='table' and name='awnsers' ;""", )
 
46
        if(checkDB < 1):
 
47
                f = open("./createDB.sql")
 
48
                query = f.read()
 
49
                db.execute(query)
 
50
                f.close()
 
51
        ## debug code
 
52
        #else:
 
53
                #print("db allready exists! conituing.")
 
54
        
 
55
        
 
56
 
 
57
#Show DB Function
 
58
def dbShow():
 
59
        dbConn() ##connect to DB
 
60
        getQuery =""" select * from awnsers; """
 
61
        db.execute(getQuery)
 
62
        
 
63
        for row in db:
 
64
                print row
 
65
        
 
66
        
 
67
        if(getQuery == None):
 
68
                print("No data in table.")
 
69
        
 
70
        menu()
 
71
 
 
72
#main call section
 
73
menu()
 
74