bugfix
This commit is contained in:
parent
644fd02d38
commit
321ea27da0
@ -51,7 +51,7 @@ class MsSqlor(SQLor):
|
|||||||
'select':select_stmt,
|
'select':select_stmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
def placeHolder(self,varname):
|
def placeHolder(self,varname,pos=None):
|
||||||
if varname=='__mainsql__' :
|
if varname=='__mainsql__' :
|
||||||
return ''
|
return ''
|
||||||
return '%s'
|
return '%s'
|
||||||
|
@ -64,7 +64,7 @@ class MySqlor(SQLor):
|
|||||||
def _opendb(self):
|
def _opendb(self):
|
||||||
self.conn = connector.connect(**self.dbdesc['kwargs'])
|
self.conn = connector.connect(**self.dbdesc['kwargs'])
|
||||||
|
|
||||||
def placeHolder(self,varname):
|
def placeHolder(self,varname,pos=None):
|
||||||
if varname=='__mainsql__' :
|
if varname=='__mainsql__' :
|
||||||
return ''
|
return ''
|
||||||
return '%s'
|
return '%s'
|
||||||
@ -119,7 +119,7 @@ limit $[from_line]$,$[rows]$"""
|
|||||||
case when character_maximum_length is null then NUMERIC_PRECISION
|
case when character_maximum_length is null then NUMERIC_PRECISION
|
||||||
else character_maximum_length end
|
else character_maximum_length end
|
||||||
as length,
|
as length,
|
||||||
NUMERIC_SCALE as dec1,
|
NUMERIC_SCALE as 'dec',
|
||||||
lower(is_nullable) as nullable,
|
lower(is_nullable) as nullable,
|
||||||
column_comment as title,
|
column_comment as title,
|
||||||
lower(table_name) as table_name
|
lower(table_name) as table_name
|
||||||
@ -160,7 +160,10 @@ limit $[from_line]$,$[rows]$"""
|
|||||||
def indexesSQL(self,tablename=None):
|
def indexesSQL(self,tablename=None):
|
||||||
sqlcmd = """SELECT DISTINCT
|
sqlcmd = """SELECT DISTINCT
|
||||||
lower(index_name) as index_name,
|
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
|
lower(column_name) as column_name
|
||||||
FROM
|
FROM
|
||||||
information_schema.statistics
|
information_schema.statistics
|
||||||
|
@ -45,7 +45,7 @@ class Oracleor(SQLor):
|
|||||||
'select':select_stmt,
|
'select':select_stmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
def placeHolder(self,varname):
|
def placeHolder(self,varname,pos=None):
|
||||||
if varname=='__mainsql__' :
|
if varname=='__mainsql__' :
|
||||||
return ''
|
return ''
|
||||||
return ':%s' % varname
|
return ':%s' % varname
|
||||||
|
@ -45,17 +45,16 @@ class PostgreSQLor(SQLor):
|
|||||||
'select':select_stmt,
|
'select':select_stmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
def placeHolder(self,varname):
|
def placeHolder(self,varname,i):
|
||||||
if varname=='__mainsql__' :
|
if varname=='__mainsql__' :
|
||||||
return ''
|
return ''
|
||||||
return ':%s' % varname
|
return '$%d' % i
|
||||||
|
|
||||||
def dataConvert(self,dataList):
|
def dataConvert(self,dataList):
|
||||||
if type(dataList) == type({}):
|
x = super().dataConvert(dataList)
|
||||||
return dataList
|
if x == []:
|
||||||
d = {}
|
return None
|
||||||
[ d.update({i['name']:i['value']}) for i in dataList ]
|
return x
|
||||||
return d
|
|
||||||
|
|
||||||
def pagingSQLmodel(self):
|
def pagingSQLmodel(self):
|
||||||
return u"""select *
|
return u"""select *
|
||||||
@ -71,7 +70,7 @@ where row_id >=$[from_line]$ and row_id < $[end_line]$"""
|
|||||||
from
|
from
|
||||||
(select a.name,c.oid
|
(select a.name,c.oid
|
||||||
from
|
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
|
pg_class c
|
||||||
where a.name = c.relname) x
|
where a.name = c.relname) x
|
||||||
left join pg_description y
|
left join pg_description y
|
||||||
@ -89,13 +88,13 @@ on x.oid=y.objoid
|
|||||||
else null
|
else null
|
||||||
end as length,
|
end as length,
|
||||||
case t.typname
|
case t.typname
|
||||||
when 'numeric' then (a.atttypmod - 4) % 65536
|
when 'numeric' then (a.atttypmod - 4) %% 65536
|
||||||
else null
|
else null
|
||||||
end as dec,
|
end as dec,
|
||||||
case a.attnotnull
|
case a.attnotnull
|
||||||
when 't' then 'no'
|
when 't' then 'no'
|
||||||
when 'f' then 'yes'
|
when 'f' then 'yes'
|
||||||
end as nullable
|
end as nullable,
|
||||||
b.description AS title
|
b.description AS title
|
||||||
FROM pg_class c, pg_attribute a
|
FROM pg_class c, pg_attribute a
|
||||||
LEFT JOIN pg_description b
|
LEFT JOIN pg_description b
|
||||||
@ -168,7 +167,5 @@ where
|
|||||||
order by
|
order by
|
||||||
t.relname,
|
t.relname,
|
||||||
i.relname""" % tablename.lower()
|
i.relname""" % tablename.lower()
|
||||||
if tablename is not None:
|
|
||||||
sqlcmd += """ and lower(a.table_name) = lower('%s')""" % tablename.lower()
|
|
||||||
return sqlcmd
|
return sqlcmd
|
||||||
|
|
||||||
|
32
sqlor/sor.py
32
sqlor/sor.py
@ -67,6 +67,34 @@ class SQLor(object):
|
|||||||
self.dataChanged = False
|
self.dataChanged = False
|
||||||
self.metadatas={}
|
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):
|
def setMeta(self,tablename,meta):
|
||||||
self.metadatas[tablename.lower()] = meta
|
self.metadatas[tablename.lower()] = meta
|
||||||
|
|
||||||
@ -99,7 +127,7 @@ class SQLor(object):
|
|||||||
def pagingSQLmodel(self):
|
def pagingSQLmodel(self):
|
||||||
return u""
|
return u""
|
||||||
|
|
||||||
def placeHolder(self,varname):
|
def placeHolder(self,varname,pos=None):
|
||||||
if varname=='__mainsql__' :
|
if varname=='__mainsql__' :
|
||||||
return ''
|
return ''
|
||||||
return '?'
|
return '?'
|
||||||
@ -200,7 +228,7 @@ class SQLor(object):
|
|||||||
sql1 = cc.convert(sql1,NS)
|
sql1 = cc.convert(sql1,NS)
|
||||||
vars = sqlargsAC.findAllVariables(sql1)
|
vars = sqlargsAC.findAllVariables(sql1)
|
||||||
phnamespace = {}
|
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)
|
m_sql = sqlargsAC.convert(sql1,phnamespace)
|
||||||
newdata = []
|
newdata = []
|
||||||
for v in vars:
|
for v in vars:
|
||||||
|
@ -33,7 +33,7 @@ class SQLite3or(SQLor):
|
|||||||
def isMe(self,name):
|
def isMe(self,name):
|
||||||
return name=='sqlite3'
|
return name=='sqlite3'
|
||||||
|
|
||||||
def placeHolder(self,varname):
|
def placeHolder(self,varname,pos=None):
|
||||||
if varname=='__mainsql__' :
|
if varname=='__mainsql__' :
|
||||||
return ''
|
return ''
|
||||||
return '?'
|
return '?'
|
||||||
|
Loading…
Reference in New Issue
Block a user