forked from misbah2014/imageprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.py
More file actions
187 lines (160 loc) · 6.47 KB
/
Copy pathDatabase.py
File metadata and controls
187 lines (160 loc) · 6.47 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import sys
import sqlite3
import jsonpickle
from flask import Flask, request, Response, make_response
import requests
import json
class Database:
dataBase_name = 'Data.db'
def __init__(self):
print('In Database class')
pass
def InsertStatus(self,_status): # status 0 => pending , status 1 => In process , status 2 => complete
try:
conn = sqlite3.connect(self.dataBase_name)
cursor = conn.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS statusdb
(STATUS_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
status INTEGER
)""")
cursor.execute(""" INSERT INTO statusdb
( status INTEGER )
VALUES
(?)
""", (_status))
conn.commit()
cursor.close()
conn.close()
return True
except Exception as ex:
print('Error in Data base: Inserting Status values {}'.format(ex))
return False
pass
def UpdateStatus(self,id, _status ):
try:
conn = sqlite3.connect(self.dataBase_name)
cursor = conn.cursor()
cursor.execute(""" UPDATE statusdb SET status = ? WHERE STATUS_ID = ?
""", (id, _status))
conn.commit()
cursor.close()
conn.close()
return True
except Exception as ex:
print('Error in Data base: Updating Status values {}'.format(ex))
return False
def UpdateStudent(self, _rollnumber, _customer_id, _status ):
try:
str_rollnumber = str(_rollnumber)
str_customer_id = str(_customer_id)
conn = sqlite3.connect(self.dataBase_name)
cursor = conn.cursor()
cursor.execute(""" UPDATE studentdb SET Status = ? WHERE RollNumber = ? AND CustomerId = ?
""", (_status, str_rollnumber, str_customer_id))
conn.commit()
cursor.close()
conn.close()
return True
pass
except Exception as error:
print('ERROR in UPDATING STUDENTSDB : {}'.format(error))
return False
pass
def InsertStudent(self, roll_numbner, customer_id , _status):
try:
print('DATA BASE FILE : roll number = {}'.format(roll_numbner))
str_rol_number = str(roll_numbner)
str_id = str(customer_id)
conn = sqlite3.connect(self.dataBase_name)
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS studentdb
(STUDENT_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
RollNumber TEXT,
CustomerId TEXT,
Status INTEGER
)""")
cursor.execute(""" INSERT INTO studentdb
(RollNumber,CustomerId,Status )
VALUES
(?,?,?)
""", (str_rol_number , str_id, _status))
conn.commit()
cursor.close()
conn.close()
return True
except Exception as ex:
print('Error in Data base: Inserting Student Values {}'.format(ex))
return False
def check_id(self, _id):
id = int(_id)
print('checking ID')
conn = sqlite3.connect(self.dataBase_name)
if id < 0:
return False
else:
print('checking Edit id details please wait ')
cursor = conn.cursor()
cursor.execute("SELECT * FROM studentdb WHERE SID = {}".format(id))
val = cursor.fetchall()
if len(val) >= 1:
for x in val:
# print('1 - {} , 2- {} , 3- {}, 4- {} '.format(x[0], x[1], x[2], x[3]))
return x
else:
return 'Null'
def show_users_data(self, id):
try:
str_id = str(id)
record = []
print('In show user database calling')
conn = sqlite3.connect(self.dataBase_name)
sql = 'SELECT RollNumber, Status from studentdb WHERE CustomerId = {}'.format(str_id)
cur = conn.cursor()
cur.execute(sql)
for row in cur:
record.append( json.dumps(row) )
print(record)
conn.commit()
cur.close()
conn.close()
return record
except Exception as error:
print('Error in fetching Users {}'.format(error))
def fetch_new_user_id(self):
try:
print('In fetch_new_user_idcalling')
db = sqlite3.connect(self.dataBase_name)
sql = 'SELECT * from studentdb'
cur = db.cursor()
cur.execute(sql)
record = cur.fetchall()
for x in record:
self.j = x
db.close()
return self.j
except:
print('Error in fetching Users')
return False
def delete_student(self, id):
print('deleting please wait')
conn = sqlite3.connect(self.dataBase_name)
cursor = conn.cursor()
cursor.execute("DELETE FROM studentdb WHERE SID = ?", (id,))
conn.commit()
cursor.close()
conn.close()
return True
def get_all_users(self, _id):
str_id = str(_id)
conn = sqlite3.connect(self.dataBase_name)
conn.row_factory = sqlite3.Row # This enables column access by name: row['column_name']
db = conn.cursor()
#SELECT to_json(result) FROM (SELECT * FROM TABLE table) result)
rows = db.execute('''
SELECT RollNumber, Status from studentdb WHERE CustomerId = ?
''', [str_id]).fetchall()
conn.commit()
conn.close()
print(json.dumps([dict(ix) for ix in rows]))
return json.dumps([dict(ix) for ix in rows]) # CREATE JSON