This commit is contained in:
yumoqing 2020-10-15 14:39:31 +08:00
parent 644fd02d38
commit 321ea27da0
6 changed files with 48 additions and 20 deletions

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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 '?'