-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql-to-rabbit-multithreaded.py
63 lines (49 loc) · 1.36 KB
/
mysql-to-rabbit-multithreaded.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import antlr4
from gen.MySQLLexer import MySQLLexer
from gen.MySQLParser import MySQLParser
from threading import Thread
from subprocess import PIPE, Popen
class Handler:
inErrorRecoveryMode = False
def reportError(self, error):
pass
def recover(self, error):
pass
def recoverInline(self, error):
pass
def reportMatch(self, parser):
if self.test == 0:
print "select"
elif self.test == 1:
print "insert"
elif self.test == 2:
print "delete"
elif self.test == 3:
print "alter"
print self.text
if __name__ == "__main__":
def process(data):
s = antlr4.InputStream(data)
l = MySQLLexer(s)
tokens = antlr4.CommonTokenStream(l)
p = MySQLParser(tokens)
p._errHandler = Handler()
try:
p._errHandler.test = 0
p._errHandler.text = data
p.select_clause()
except Exception as e:
pass
try:
p._errHandler.test = 1
p._errHandler.text = data
p.insert_stm()
except:
pass
p = Popen(["python", "test.py"], stdout=PIPE)
while True:
line = p.stdout.readline()
if line != '':
Thread(target=process, args=(line.strip(),)).start()
else:
break