-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (39 loc) · 1.25 KB
/
main.py
File metadata and controls
48 lines (39 loc) · 1.25 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
from src.parse import parser, set_parse_object
from src.sqliteInt import Parse, sqlite
from src.dto.selectQueryDTO import *
from src.dto.response import *
import os
import re
import copy
def runParser(parse: Parse, sql: str):
set_parse_object(parse)
parser.parse(sql, debug=False)
def execute_sql(db, sql):
parse = Parse(db)
check = ['select', 'insert', 'update', 'delete', 'create', 'drop']
s = sql.split()
if s[0].lower() not in check:
sql = s[-1] + " " + " ".join(s[:-1])
runParser(parse, sql)
def main():
db = sqlite.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'db'))
while True:
try:
s = input('sql > ')
if not s:
continue
except EOFError:
break
try:
execute_sql(db, s)
if dto.getFlag():
data = {'column_names': copy.deepcopy(dto.columnNames), 'rows': copy.deepcopy(dto.rows)}
print(data)
dto.clearDto()
return Response(200, None, data)
else:
return Response(200, None, None)
except Exception as e:
return Response(400, str(e), None)
if __name__ == '__main__':
main()