Spaces:
Runtime error
Runtime error
Update dbQuery.py
Browse files- dbQuery.py +9 -9
dbQuery.py
CHANGED
@@ -26,7 +26,7 @@ def DB_SessionID():
|
|
26 |
|
27 |
# Commit the transaction
|
28 |
db.commit()
|
29 |
-
print("Transaction completed successfully")
|
30 |
session_id = cursor.fetchone()[0]
|
31 |
#print(session_id)
|
32 |
return session_id
|
@@ -34,8 +34,8 @@ def DB_SessionID():
|
|
34 |
except Exception as e:
|
35 |
# Rollback the transaction if any error occurs
|
36 |
db.rollback()
|
37 |
-
print("Transaction failed")
|
38 |
-
print(e)
|
39 |
return 0
|
40 |
|
41 |
finally:
|
@@ -59,23 +59,23 @@ def insertData(session_id, score, question_no):
|
|
59 |
#code for pack-unpack
|
60 |
# Pack two 32-bit integers into a single 64-bit integer
|
61 |
sessionid_qno = packed = (int(session_id) << 32) | question_no
|
62 |
-
print("sqo", sessionid_qno, "question",question_no, "session", session_id)
|
63 |
#directly formatting the string with variables is vulnerable to SQL injection attacks, so using parameterized queries instead of simple one.
|
64 |
sql2 = '''INSERT INTO table2 (session_id, session_question, question_num, question, response, feedback, score)
|
65 |
VALUES (%s, %s, %s, %s, %s, %s, %s)'''
|
66 |
# sql2 = '''insert into table2 (session_id, session_question, question_num, question, response, feedback, score)
|
67 |
#VALUES (2, 3564373, 3, "dsfds", "sdfgsdg", "sfdgg", 4)'''
|
68 |
-
print(type(session_id), session_id, type(sessionid_qno),sessionid_qno, type(question_no),question_no, type(question),question, type(response),response, type(feedback),feedback, type(grade),grade)
|
69 |
try:
|
70 |
# Begin the transaction
|
71 |
db.begin()
|
72 |
-
print("Connection sucessfull 2")
|
73 |
# Execute the SQL queries
|
74 |
cursor.execute(sql2,(session_id, sessionid_qno, question_no, question, response, feedback, grade))
|
75 |
|
76 |
# Commit the transaction
|
77 |
db.commit()
|
78 |
-
print("Transaction 2 completed successfully")
|
79 |
return 1
|
80 |
|
81 |
except Exception as e:
|
@@ -83,8 +83,8 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)'''
|
|
83 |
db.rollback()
|
84 |
#print(session_id)
|
85 |
#print(score_obj_no)
|
86 |
-
print("Transaction 2 failed")
|
87 |
-
print(e)
|
88 |
return 0
|
89 |
|
90 |
finally:
|
|
|
26 |
|
27 |
# Commit the transaction
|
28 |
db.commit()
|
29 |
+
#print("Transaction completed successfully")
|
30 |
session_id = cursor.fetchone()[0]
|
31 |
#print(session_id)
|
32 |
return session_id
|
|
|
34 |
except Exception as e:
|
35 |
# Rollback the transaction if any error occurs
|
36 |
db.rollback()
|
37 |
+
#print("Transaction failed")
|
38 |
+
#print(e)
|
39 |
return 0
|
40 |
|
41 |
finally:
|
|
|
59 |
#code for pack-unpack
|
60 |
# Pack two 32-bit integers into a single 64-bit integer
|
61 |
sessionid_qno = packed = (int(session_id) << 32) | question_no
|
62 |
+
#print("sqo", sessionid_qno, "question",question_no, "session", session_id)
|
63 |
#directly formatting the string with variables is vulnerable to SQL injection attacks, so using parameterized queries instead of simple one.
|
64 |
sql2 = '''INSERT INTO table2 (session_id, session_question, question_num, question, response, feedback, score)
|
65 |
VALUES (%s, %s, %s, %s, %s, %s, %s)'''
|
66 |
# sql2 = '''insert into table2 (session_id, session_question, question_num, question, response, feedback, score)
|
67 |
#VALUES (2, 3564373, 3, "dsfds", "sdfgsdg", "sfdgg", 4)'''
|
68 |
+
#print(type(session_id), session_id, type(sessionid_qno),sessionid_qno, type(question_no),question_no, type(question),question, type(response),response, type(feedback),feedback, type(grade),grade)
|
69 |
try:
|
70 |
# Begin the transaction
|
71 |
db.begin()
|
72 |
+
#print("Connection sucessfull 2")
|
73 |
# Execute the SQL queries
|
74 |
cursor.execute(sql2,(session_id, sessionid_qno, question_no, question, response, feedback, grade))
|
75 |
|
76 |
# Commit the transaction
|
77 |
db.commit()
|
78 |
+
#print("Transaction 2 completed successfully")
|
79 |
return 1
|
80 |
|
81 |
except Exception as e:
|
|
|
83 |
db.rollback()
|
84 |
#print(session_id)
|
85 |
#print(score_obj_no)
|
86 |
+
#print("Transaction 2 failed")
|
87 |
+
#print(e)
|
88 |
return 0
|
89 |
|
90 |
finally:
|