-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInter.py
More file actions
42 lines (40 loc) · 1.17 KB
/
Inter.py
File metadata and controls
42 lines (40 loc) · 1.17 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
# coding=utf-8
#Filename interpreter.py
import sys
import re
def interpreter():
def select_clause(s):
if "from" not in s:
print "No table are seleceted!"
elif "where" in s:
m = re.match(r"select(.*)from(.*)where(.*)$", s)
if m:
s1=m.group(1).replace(" ","")
s2=m.group(2).replace(" ","")
s3=m.group(3).replace(" ","")
s1=s1.replace(",",".");
s3=s3.replace("and","&");
s3=s3.replace("or","|");
s="21"+s1+","+s2+","+s3
return s
else:
m = re.match(r"select(.*)from(.*)$", s)
s1=m.group(1).replace(" ","")
s2=m.group(2).replace(" ","")
s1=s1.replace(",",".");
s="20"+s1+","+s2
return s
sql=""
sql=raw_input(">>")
while True:
if '$' in sql: #$为结束字符
break
s=raw_input()
sql+=" "
sql+=s
# print sql
if "select" in sql:
sql=select_clause(sql)
#print sql
return sql
#interpreter()