-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataBaseControllerFile.py
70 lines (58 loc) · 2.11 KB
/
DataBaseControllerFile.py
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
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import sqlite3
class DatabaseController:
'Common button controller class. takes pin number in constructor'
def __init__(self):
#self.amount = 6
print "Database Controller: Constructor"
def insertInitialValue(self):
print "Database Controller: insert initial value"
self.conn = sqlite3.connect(':memory')
c = self.conn.cursor()
c.execute("INSERT INTO servoposition VALUES('init', 0)")
self.conn.commit()
self.conn.close()
def updateValue(self, pos):
self.conn = sqlite3.connect('localDB.db')
c = self.conn.cursor()
c.execute('''UPDATE servoposition SET position = ?''', (float(pos),))
self.conn.commit()
self.conn.close()
print "Database Controller: updating to ", pos
#self.amount = pos
def deleteValue(self):
self.conn = sqlite3.connect('localDB.db')
print "delete"
c = self.conn.cursor()
c.execute('''DELETE FROM servoposition''')
self.conn.commit()
self.conn.close()
def selectValue(self):
self.conn = sqlite3.connect('localDB.db')
c = self.conn.cursor()
c.execute('''SELECT position FROM servoposition''')
val = c.fetchone()
#print "Database Controller: returning ", val
#return self.amount #
self.conn.close()
return val[0]
def createTable(self):
self.conn = sqlite3.connect('localDB.db')
print "Database Controller: creating table"
c = self.conn.cursor()
c.execute('''CREATE TABLE servoposition(changesource text, position real)''')
self.conn.commit()
self.conn.close()
def dropTable(self):
self.conn = sqlite3.connect('localDB.db')
print "Database Controller: dropping table"
c = self.conn.cursor()
c.execute('''DROP TABLE servoposition ''')
self.conn.commit()
self.conn.close()
#db = DatabaseController()
#db.dropTable()
#db.createTable()
#db.insertInitialValue()
#db.updateValue(7)
#print db.selectValue()