diff --git a/sqlor/ddl_template_mysql.py b/sqlor/ddl_template_mysql.py index 2f65690..b7a69e2 100755 --- a/sqlor/ddl_template_mysql.py +++ b/sqlor/ddl_template_mysql.py @@ -39,7 +39,9 @@ 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 -%} {% endfor %} +{% if summary[0].primary and len(summary[0].primary)>0 %} {{primary()}} +{% endif %} ) engine=innodb default charset=utf8 diff --git a/sqlor/ddl_template_oracle.py b/sqlor/ddl_template_oracle.py index c252feb..d71ca84 100755 --- a/sqlor/ddl_template_oracle.py +++ b/sqlor/ddl_template_oracle.py @@ -33,7 +33,9 @@ CREATE TABLE {{summary[0].name}} {% for field in fields %} {{field.name}} {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}}{%- if not loop.last -%},{%- endif -%} {% endfor %} +{% if summary[0].primary and len(summary[0].primary)>0 %} {{primary()}} +{% endif %} ); {% for v in indexes %} CREATE {% if v.idxtype=='unique' %}UNIQUE{% endif %} INDEX {{summary[0].name}}_{{v.name}} ON {{summary[0].name}}({{",".join(v.idxfields)}}); diff --git a/sqlor/ddl_template_postgresql.py b/sqlor/ddl_template_postgresql.py index f4a840f..ac8f358 100755 --- a/sqlor/ddl_template_postgresql.py +++ b/sqlor/ddl_template_postgresql.py @@ -29,9 +29,11 @@ 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)}}, + {{field.name}} {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}}{%- if not loop.last -%},{%- endif -%} {% endfor %} +{% if summary[0].primary and len(summary[0].primary)>0 %} {{primary()}} +{% endif %} ); {% for v in indexes %} CREATE {% if v.idxtype=='unique' %}UNIQUE{% endif %} INDEX {{summary[0].name}}_{{v.name}} ON {{summary[0].name}}({{",".join(v.idxfields)}}); diff --git a/sqlor/ddl_template_sqlserver.py b/sqlor/ddl_template_sqlserver.py index d7731c4..8bc7f6a 100755 --- a/sqlor/ddl_template_sqlserver.py +++ b/sqlor/ddl_template_sqlserver.py @@ -35,7 +35,9 @@ CREATE TABLE dbo.{{summary[0].name}} {% for field in fields %} {{field.name}} {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}}{%- if not loop.last -%},{%- endif -%} {% endfor %} +{% if summary[0].primary and len(summary[0].primary)>0 %} {{primary()}} +{% endif %} ) {% for v in indexes %} CREATE {% if v.idxtype=='unique' %}UNIQUE{% endif %} INDEX {{summary[0].name}}_{{v.name}} ON {{summary[0].name}}({{",".join(v.idxfields)}}); diff --git a/sqlor/sor.py b/sqlor/sor.py index f8cda6c..035f7e1 100755 --- a/sqlor/sor.py +++ b/sqlor/sor.py @@ -1,3 +1,4 @@ +from traceback import print_exc import os from asyncio import coroutine os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' @@ -87,7 +88,9 @@ class SQLor(object): primary = await self.primary(t.name) indexes = concat_idx_info(await self.indexes(t.name)) fields = await self.fields(t.name) - t.primary = [f.field_name for f in primary] + primary_fields = [f.field_name for f in primary] + if len(primary_fields)>0: + t.primary = [f.field_name for f in primary] x = {} x['summary'] = [t] x['indexes'] = indexes @@ -201,7 +204,6 @@ class SQLor(object): markedSQL,datas = self.maskingSQL(sql,NS) datas = self.dataConvert(datas) try: - # markedSQL = markedSQL.encode('utf8') if self.async_mode: await cursor.execute(markedSQL,datas) else: @@ -209,6 +211,7 @@ class SQLor(object): except Exception as e: print( "markedSQL=",markedSQL,':',datas,':',e) + print_exc() raise e return @@ -228,7 +231,7 @@ class SQLor(object): sql1 = cc.convert(sql1,NS) vars = sqlargsAC.findAllVariables(sql1) phnamespace = {} - [phnamespace.update({v:self.placeHolder(v,i)}) for v,i in enumerate(vars)] + [phnamespace.update({v:self.placeHolder(v,i)}) for i,v in enumerate(vars)] m_sql = sqlargsAC.convert(sql1,phnamespace) newdata = [] for v in vars: