[667a13]: generate / run / template-sqlite-filter.py Maximize Restore History

Download this file

template-sqlite-filter.py    70 lines (60 with data), 1.4 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python
from __future__ import print_function
import sys
import re
import string
u1=r'\sUNSIGNED'
u2=r''
s1=r'\s(?=\b)SIGNED(?=\b)'
s2=r''
i10=r'INT \(1\)'
i20=r'INTEGER'
i1=r'(?=\b)INT(?=\b)'
i2=r'INTEGER'
mi1=r'MEDIUMINT'
mi2=r'INTEGER'
ti1=r'TINYINT'
ti2=r'SMALLINT'
mt1=r'MEDIUMTEXT'
mt2=r'TEXT'
d1=r'DATETIME'
d2=r'INTEGER'
en10=r'position ENUM \([^\)]*\)'
en20=r'position CHARACTER (2)'
en1=r'ENUM \([^\)]*\)'
en2=r'CHARACTER (1)'
pk1=r'^([^=]*).create=(.*)PRIMARY KEY(.*)$'
pk2=r'\1.create=\2CONSTRAINT pk_%\1.table% PRIMARY KEY\3'
bc1=r'\sBINARY COLLATE utf8_bin'
bc2=r''
def outputdata(data):
print("%s" % (data))
return
def replace(s1,s2,line):
line2=re.sub(s1,s2,line)
if re.search(s1,line):
print("matches [%s] %s" % (s1,line),file=sys.stderr)
if line != line2:
print('\t>%s' % line, file=sys.stderr)
print('\t<%s' % line2, file=sys.stderr)
#exit()
pass
return line2
print("DIFF", file=sys.stderr)
lines=sys.__stdin__.readlines()
for i in range(len(lines)):
line=lines[i].strip()
if re.match("^.*=CREATE TABLE.*$", line):
line=replace(u1,u2,line)
line=replace(s1,s2,line)
line=replace(i10,i20,line)
line=replace(i1,i2,line)
line=replace(mi1,mi2,line)
line=replace(ti1,ti2,line)
line=replace(mt1,mt2,line)
line=replace(pk1,pk2,line)
line=replace(en10,en20,line)
line=replace(en1,en2,line)
line=replace(d1,d2,line)
line=replace(bc1,bc2,line)
outputdata(line)