-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryExecutor.py
46 lines (32 loc) · 1.56 KB
/
QueryExecutor.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
import sqlite3
class QueryExecutor:
def __init__(self, query):
sql_con = sqlite3.connect("T:\\2018++\\BE\\LP\\LP2\\Data Mining\\dataset\\database.sqlite")
self.cursor = sql_con.cursor()
print("Connected to database")
print(type(query))
self.cursor.execute(query)
'''
def print(self):
for row in self.cursor:
print([row[i] for i in range(0, len(row))])
'''
def save_to_html(self):
with open("T:\\2018++\\BE\\LP\\LP2\\trial and error\\templates\\sqloutput.html", "w", encoding="utf-8") as file:
file.write("<html>")
file.write("<head>")
file.write("<title>SQL Query Output</title>")
file.write("</head>")
file.write("<body>")
with open("T:\\2018++\\BE\\LP\\LP2\\trial and error\\templates\\sqloutput.html", "a", encoding="utf-8") as file:
for row in self.cursor:
file.write("<p>" + ''.join([f"{(row[i])} | " for i in range(0, len(row))]) + "</p>")
file.write("<p>---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</p>")
with open("T:\\2018++\\BE\\LP\\LP2\\trial and error\\templates\\sqloutput.html", "a", encoding="utf-8") as file:
file.write("</body")
file.write("</html>")
'''
query = input("Enter query :")
obj = QueryExecutor(query)
obj.save_to_html()
'''