diff --git a/sqlor/ddl_template_mysql.py b/sqlor/ddl_template_mysql.py index b7a69e2..e85249d 100755 --- a/sqlor/ddl_template_mysql.py +++ b/sqlor/ddl_template_mysql.py @@ -37,7 +37,7 @@ drop table if exists {{summary[0].name}}; CREATE TABLE {{summary[0].name}} ( {% for field in fields %} - {{field.name}} {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}} {%if field.title -%} comment '{{field.title}}'{%- endif %}{%- if not loop.last -%},{%- endif -%} + `{{field.name}}` {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}} {%if field.title -%} comment '{{field.title}}'{%- endif %}{%- if not loop.last -%},{%- endif -%} {% endfor %} {% if summary[0].primary and len(summary[0].primary)>0 %} {{primary()}} diff --git a/sqlor/sor.py b/sqlor/sor.py index a622f90..636d94b 100755 --- a/sqlor/sor.py +++ b/sqlor/sor.py @@ -1,5 +1,6 @@ from traceback import print_exc import os +import decimal from asyncio import coroutine os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' import sys @@ -14,6 +15,11 @@ from appPublic.objectAction import ObjectAction from appPublic.argsConvert import ArgsConvert,ConditionConvert from .filter import DBFilter +def db_type_2_py_type(o): + if isinstance(o,decimal.Decimal): + return float(o) + return o + class SQLorException(Exception,object): def __int__(self,**kvs): supper(SQLException,self).__init__(self,**kvs) @@ -273,7 +279,7 @@ class SQLor(object): while rec is not None: dic = {} for i in range(len(fields)): - dic.update({fields[i]:rec[i]}) + dic.update({fields[i] : db_type_2_py_type(rec[i])}) callback(DictObject(**dic),**kwargs) if self.async_mode: rec = await cur.fetchone() @@ -511,9 +517,7 @@ class SQLor(object): return desc desc = {} summary = [ i for i in await self.tables() if tablename.lower() == i.name ] - print('summary=',summary) pris = await self.primary(tablename) - print('primary key=',pris) primary = [i.name for i in pris ] summary[0]['primary'] = primary desc['summary'] = summary