gistfile1.txt
'''
Created on 2017年8月23日
@author: acer
'''
import json
import re
from collections import Iterable
class Procss(object):
def __init__(self):
f=open("../typemap.json","r");
lines=[];
first=True;
for line in f:
if first:
first=False;
lines.append(line);
j="".join(lines);
jsondata=json.loads(j);
self.mydict=jsondata;
#print(jsondata.get("NUMBER"));
def GetElVal(self,yyj):
re.match(r"\$\{(\w)+\}",yyj );
def CalRealType(self,mysqltype=None):
matcher=re.match(r"(\w+)(\((\d+)(,(\d+))?\))?", mysqltype);
if matcher!=None:
matchTuple=matcher.groups();
size=len(matchTuple);
vartype=None;
datalength=None;
scale=None;
if size>0:
vartype=matchTuple[0];
if size>2:
datalength=matchTuple[2];
if size>4:
scale=matchTuple[4];
maparrs=self.mydict.get(vartype);
if not isinstance(maparrs, Iterable):
return None;
print(vartype+","+str(datalength)+","+str(scale))
for onedict in maparrs:
conditionP=onedict.get("precision");
contitionS=onedict.get("scale");
if (datalength!=None and conditionP!=None) and (not self.compareCondi(conditionP,int(datalength))):
continue;
if (scale!=None and contitionS!=None) and (not self.compareCondi(contitionS, int(scale))):
continue;
return onedict["maptype"];
def compareCondi(self,condition,value=0):
'''
用value来判断是否满足这个条件
'''
if not isinstance(condition, str):
return False;
items=condition.split("_");
if len(items)!=2:
return False;
if items[0]=='all':
return True;
comparstr="%d%s%d";
shell=comparstr%(value,self.getSymbol(items[0]),int(items[1]));
print(shell)
return eval(shell);
def getSymbol(self,symbol):
'''
获取比较符号
'''
if not isinstance(symbol, Iterable):
return None;
symbols=[];
for s in symbol:
if s=='e' or s=='q':
symbols.append("=");
elif s=='g':
symbols.append(">");
elif s=='l':
symbols.append("
if len(symbols)==0:
symbols.append("==");
return "".join(symbols)
if __name__ == '__main__':
p=Procss();
b=p.CalRealType("NUMBER(10,1)");
#b=p.compareCondi("lt_10", 9);
#b=p.getSymbol("eq");
print(b)