-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL.py
executable file
·61 lines (32 loc) · 1.46 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
59
60
61
import sqlite3
class DBConnect:
'''this class makes working with data base easy by taking all the heavy stuff'''
def __init__(self,**kwargs):
self.Data= kwargs
self._db = sqlite3.connect(self.Data['FN'])
self._db.row_factory = sqlite3.Row
self._db.execute("CREATE TABLE IF NOT EXISTS {} {}".format(self.Data['TN'] , self.Data['TC']))
self._db.commit()
def Add(self,TN ,VL, Data):
'''this method for inserting self.data into specific table'''
self._db.execute('INSERT INTO {} VALUES {}'.format(TN,VL)
, (Data))
self._db.commit()
return "Saved"
def Listrequest(self,**kwargs):
'''this method returns the table as Dictionary '''
cursor = self._db.execute('SELECT * FROM {} '.format(self.Data['TN']))
return cursor
def DeleteRecord(self,Table_Name,ID,item):
'''this for deleting items '''
self._db.execute('DELETE FROM {} WHERE {} = ? '.format(Table_Name,ID),(item,))
self._db.commit()
return'Deleted'
def Listrequest2(self,Table_Name,ID,item):
'''this method returns the specified item '''
cursor2 = self._db.execute('SELECT * FROM {} WHERE {} = ? '.format(Table_Name,ID),(item,))
return cursor2
def Update(self,Table_Name , Column , VL1 , Column1 ,VL2):
'''this method for updating items '''
self._db.execute("UPDATE {} SET {} = ? WHERE {} = ? ".format(Table_Name , Column , Column1),(VL1 , VL2))
self._db.commit()