-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.py
58 lines (52 loc) · 1.85 KB
/
sql.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
import glob
import sqlite3
from sqlite3 import Error
class SqlProcess:
def __init__(self, databaseName):
try:
sqliteConnection = sqlite3.connect(str(databaseName))
self.connection = sqliteConnection
cursor = sqliteConnection.cursor()
print("Successfully Connected to SQLite")
except sqlite3.Error as error:
print("Error while tring to connect", error)
def execute_query(self, query):
cursor = self.connection.cursor()
try:
cursor.execute(query)
self.connection.commit()
print(cursor.fetchall())
print("Query executed successfully")
except Error as e:
print(f"The error '{e}' occurred")
def insert_data(self, data):
sql = ''' INSERT INTO library_data VALUES(?,?,?,?,?,?,?) '''
cur = self.connection.cursor()
try:
cur.execute(sql, data)
self.connection.commit()
rows = cur.fetchall()
for row in rows:
print(row)
except Error as e:
print(f"The error '{e}' occurred")
def query_tree(self, rgbValues):
rgbValues = (rgbValues[0],rgbValues[0],rgbValues[1],rgbValues[1],rgbValues[2],rgbValues[2])
sql = '''
SELECT * FROM library_data
WHERE Rmin<= ? AND Rmax>= ?
AND Gmin<= ? AND Gmax>= ?
AND Bmin<= ? AND Bmax>= ?;
'''
cursor = self.connection.cursor()
try:
cursor.execute(sql, rgbValues)
self.connection.commit()
rows = cursor.fetchall()
for row in rows:
return row
except Error as e:
print(f"The error '{e}' occurred")
def printDB(self):
query = '''SELECT * FROM library_data'''
self.execute_query(query)