From 321ea27da07129d1f8ab2503cf297fe078e01533 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 15 Oct 2020 14:39:31 +0800 Subject: [PATCH] bugfix --- sqlor/mssqlor.py | 2 +- sqlor/mysqlor.py | 9 ++++++--- sqlor/oracleor.py | 2 +- sqlor/postgresqlor.py | 21 +++++++++------------ sqlor/sor.py | 32 ++++++++++++++++++++++++++++++-- sqlor/sqlite3or.py | 2 +- 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/sqlor/mssqlor.py b/sqlor/mssqlor.py index 31b8bf5..25edad8 100755 --- a/sqlor/mssqlor.py +++ b/sqlor/mssqlor.py @@ -51,7 +51,7 @@ class MsSqlor(SQLor): 'select':select_stmt, } - def placeHolder(self,varname): + def placeHolder(self,varname,pos=None): if varname=='__mainsql__' : return '' return '%s' diff --git a/sqlor/mysqlor.py b/sqlor/mysqlor.py index 58360f8..d68b621 100755 --- a/sqlor/mysqlor.py +++ b/sqlor/mysqlor.py @@ -64,7 +64,7 @@ class MySqlor(SQLor): def _opendb(self): self.conn = connector.connect(**self.dbdesc['kwargs']) - def placeHolder(self,varname): + def placeHolder(self,varname,pos=None): if varname=='__mainsql__' : return '' return '%s' @@ -119,7 +119,7 @@ limit $[from_line]$,$[rows]$""" case when character_maximum_length is null then NUMERIC_PRECISION else character_maximum_length end as length, - NUMERIC_SCALE as dec1, + NUMERIC_SCALE as 'dec', lower(is_nullable) as nullable, column_comment as title, lower(table_name) as table_name @@ -160,7 +160,10 @@ limit $[from_line]$,$[rows]$""" def indexesSQL(self,tablename=None): sqlcmd = """SELECT DISTINCT lower(index_name) as index_name, - NON_UNIQUE as is_unique, + case NON_UNIQUE + when 1 then 'unique' + else '' + end as is_unique, lower(column_name) as column_name FROM information_schema.statistics diff --git a/sqlor/oracleor.py b/sqlor/oracleor.py index 0646943..b7d30ee 100755 --- a/sqlor/oracleor.py +++ b/sqlor/oracleor.py @@ -45,7 +45,7 @@ class Oracleor(SQLor): 'select':select_stmt, } - def placeHolder(self,varname): + def placeHolder(self,varname,pos=None): if varname=='__mainsql__' : return '' return ':%s' % varname diff --git a/sqlor/postgresqlor.py b/sqlor/postgresqlor.py index a606737..15895c1 100755 --- a/sqlor/postgresqlor.py +++ b/sqlor/postgresqlor.py @@ -45,17 +45,16 @@ class PostgreSQLor(SQLor): 'select':select_stmt, } - def placeHolder(self,varname): + def placeHolder(self,varname,i): if varname=='__mainsql__' : return '' - return ':%s' % varname + return '$%d' % i def dataConvert(self,dataList): - if type(dataList) == type({}): - return dataList - d = {} - [ d.update({i['name']:i['value']}) for i in dataList ] - return d + x = super().dataConvert(dataList) + if x == []: + return None + return x def pagingSQLmodel(self): return u"""select * @@ -71,7 +70,7 @@ where row_id >=$[from_line]$ and row_id < $[end_line]$""" from (select a.name,c.oid from - (select lower(tablename) as name from tables where schemaname='public') a + (select lower(tablename) as name from pg_tables where schemaname='public') a, pg_class c where a.name = c.relname) x left join pg_description y @@ -89,13 +88,13 @@ on x.oid=y.objoid else null end as length, case t.typname - when 'numeric' then (a.atttypmod - 4) % 65536 + when 'numeric' then (a.atttypmod - 4) %% 65536 else null end as dec, case a.attnotnull when 't' then 'no' when 'f' then 'yes' - end as nullable + end as nullable, b.description AS title FROM pg_class c, pg_attribute a LEFT JOIN pg_description b @@ -168,7 +167,5 @@ where order by t.relname, i.relname""" % tablename.lower() - if tablename is not None: - sqlcmd += """ and lower(a.table_name) = lower('%s')""" % tablename.lower() return sqlcmd diff --git a/sqlor/sor.py b/sqlor/sor.py index 9558f28..f8cda6c 100755 --- a/sqlor/sor.py +++ b/sqlor/sor.py @@ -67,6 +67,34 @@ class SQLor(object): self.dataChanged = False self.metadatas={} + async def get_schema(self): + def concat_idx_info(idxs): + x = [] + n = None + for i in idxs: + if not n or n.index_name != i.index_name: + if n: + x.append(n) + n = i + n.column_name = [i.column_name] + else: + n.column_name.append(i.column_name) + return x + + tabs = await self.tables() + schemas = [] + for t in tabs: + 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] + x = {} + x['summary'] = [t] + x['indexes'] = indexes + x['fields'] = fields + schemas.append(x) + return schemas + def setMeta(self,tablename,meta): self.metadatas[tablename.lower()] = meta @@ -99,7 +127,7 @@ class SQLor(object): def pagingSQLmodel(self): return u"" - def placeHolder(self,varname): + def placeHolder(self,varname,pos=None): if varname=='__mainsql__' : return '' return '?' @@ -200,7 +228,7 @@ class SQLor(object): sql1 = cc.convert(sql1,NS) vars = sqlargsAC.findAllVariables(sql1) phnamespace = {} - [phnamespace.update({v:self.placeHolder(v)}) for v in vars] + [phnamespace.update({v:self.placeHolder(v,i)}) for v,i in enumerate(vars)] m_sql = sqlargsAC.convert(sql1,phnamespace) newdata = [] for v in vars: diff --git a/sqlor/sqlite3or.py b/sqlor/sqlite3or.py index 5283012..9d96c8f 100755 --- a/sqlor/sqlite3or.py +++ b/sqlor/sqlite3or.py @@ -33,7 +33,7 @@ class SQLite3or(SQLor): def isMe(self,name): return name=='sqlite3' - def placeHolder(self,varname): + def placeHolder(self,varname,pos=None): if varname=='__mainsql__' : return '' return '?'