Compare commits
No commits in common. "20791b0d713dfb0e853a19ab84bbd27dcefb8412" and "c5fe11f3d0f52ac2cbb5f6e06ae6e46cd323996e" have entirely different histories.
20791b0d71
...
c5fe11f3d0
0
dataloader/README.md
Executable file → Normal file
0
dataloader/README.md
Executable file → Normal file
0
dataloader/database.png
Executable file → Normal file
0
dataloader/database.png
Executable file → Normal file
Before Width: | Height: | Size: 233 KiB After Width: | Height: | Size: 233 KiB |
@ -14,8 +14,6 @@ class CBObject:
|
|||||||
async def handle(self,ws):
|
async def handle(self,ws):
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext(self.db) as sor:
|
async with db.sqlorContext(self.db) as sor:
|
||||||
delete_sql = "TRUNCATE TABLE %s" % self.tbl
|
|
||||||
await sor.sqlExe(delete_sql, {})
|
|
||||||
info = await sor.I(self.tbl)
|
info = await sor.I(self.tbl)
|
||||||
for rec in getRecord(ws):
|
for rec in getRecord(ws):
|
||||||
r = [ v for v in rec.values() if v is not None ]
|
r = [ v for v in rec.values() if v is not None ]
|
||||||
@ -24,6 +22,12 @@ class CBObject:
|
|||||||
rec = convrec(info, rec)
|
rec = convrec(info, rec)
|
||||||
await sor.C(self.tbl, rec)
|
await sor.C(self.tbl, rec)
|
||||||
|
|
||||||
|
typesconv = {
|
||||||
|
"int":int,
|
||||||
|
"float":float,
|
||||||
|
"str":str,
|
||||||
|
}
|
||||||
|
|
||||||
def getRecord(ws):
|
def getRecord(ws):
|
||||||
names = []
|
names = []
|
||||||
types = []
|
types = []
|
||||||
@ -39,6 +43,7 @@ def getRecord(ws):
|
|||||||
else:
|
else:
|
||||||
dic = {}
|
dic = {}
|
||||||
for j,c in enumerate(r):
|
for j,c in enumerate(r):
|
||||||
|
# tf = typesconv.get(types[j],None)
|
||||||
v = c.value
|
v = c.value
|
||||||
dic[names[j]] = v
|
dic[names[j]] = v
|
||||||
yield dic
|
yield dic
|
||||||
|
0
dataloader/macos/dataloader.spec
Executable file → Normal file
0
dataloader/macos/dataloader.spec
Executable file → Normal file
0
dataloader/table1.png
Executable file → Normal file
0
dataloader/table1.png
Executable file → Normal file
Before Width: | Height: | Size: 181 KiB After Width: | Height: | Size: 181 KiB |
0
dataloader/table2.png
Executable file → Normal file
0
dataloader/table2.png
Executable file → Normal file
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 200 KiB |
2
dataloader/typeconv.py
Executable file → Normal file
2
dataloader/typeconv.py
Executable file → Normal file
@ -14,7 +14,7 @@ def conv(info, name, value):
|
|||||||
for f in fields:
|
for f in fields:
|
||||||
if f['name'] == name:
|
if f['name'] == name:
|
||||||
f = convfuncs.get(f['type'], None)
|
f = convfuncs.get(f['type'], None)
|
||||||
if f is None or value is None:
|
if f is None:
|
||||||
return value
|
return value
|
||||||
return f(value)
|
return f(value)
|
||||||
return value
|
return value
|
||||||
|
0
dataloader/ubuntu/dataloader.spec
Executable file → Normal file
0
dataloader/ubuntu/dataloader.spec
Executable file → Normal file
0
dataloader/windows/dataloader.spec
Executable file → Normal file
0
dataloader/windows/dataloader.spec
Executable file → Normal file
0
sqlor/const.py
Executable file → Normal file
0
sqlor/const.py
Executable file → Normal file
@ -16,7 +16,7 @@ time
|
|||||||
{%- elif type=='datetime' -%}
|
{%- elif type=='datetime' -%}
|
||||||
datetime
|
datetime
|
||||||
{%- elif type=='timestamp' -%}
|
{%- elif type=='timestamp' -%}
|
||||||
TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
TIMESTAMP
|
||||||
{%- elif type=='text' -%}
|
{%- elif type=='text' -%}
|
||||||
longtext
|
longtext
|
||||||
{%- elif type=='bin' -%}
|
{%- elif type=='bin' -%}
|
||||||
|
@ -66,7 +66,7 @@ class MsSqlor(SQLor):
|
|||||||
def pagingSQLmodel(self):
|
def pagingSQLmodel(self):
|
||||||
return u"""select *
|
return u"""select *
|
||||||
from (
|
from (
|
||||||
select row_number() over(order by $[sort]$) as _row_id,page_s.*
|
select row_number() over(order by $[sort]$ $[order]$) as _row_id,page_s.*
|
||||||
from (%s) page_s
|
from (%s) page_s
|
||||||
) A
|
) A
|
||||||
where _row_id >= $[from_line]$ and _row_id < $[end_line]$"""
|
where _row_id >= $[from_line]$ and _row_id < $[end_line]$"""
|
||||||
|
@ -71,8 +71,35 @@ class MySqlor(SQLor):
|
|||||||
d = [ i['value'] for i in dataList]
|
d = [ i['value'] for i in dataList]
|
||||||
return tuple(d)
|
return tuple(d)
|
||||||
|
|
||||||
|
def pagingSQL(self,sql,paging,NS):
|
||||||
|
"""
|
||||||
|
default it not support paging
|
||||||
|
"""
|
||||||
|
page = int(NS.get(paging['pagename'],1))
|
||||||
|
rows = int(NS.get(paging['rowsname'],ROWS))
|
||||||
|
sort = NS.get(paging.get('sortname','sort'),None)
|
||||||
|
order = NS.get(paging.get('ordername','asc'),'asc')
|
||||||
|
if not sort:
|
||||||
|
return sql
|
||||||
|
if page < 1:
|
||||||
|
page = 1
|
||||||
|
from_line = (page - 1) * rows
|
||||||
|
end_line = page * rows + 1
|
||||||
|
psql = self.pagingSQLmodel()
|
||||||
|
ns={
|
||||||
|
'from_line':from_line,
|
||||||
|
'end_line':end_line,
|
||||||
|
'rows':rows,
|
||||||
|
'sort':sort,
|
||||||
|
'order':order,
|
||||||
|
}
|
||||||
|
ac = ArgsConvert('$[',']$')
|
||||||
|
psql = ac.convert(psql,ns)
|
||||||
|
retSQL=psql % sql
|
||||||
|
return retSQL
|
||||||
|
|
||||||
def pagingSQLmodel(self):
|
def pagingSQLmodel(self):
|
||||||
return u"""select * from (%s) A order by $[sort]$
|
return u"""select * from (%s) A order by $[sort]$ $[order]$
|
||||||
limit $[from_line]$,$[rows]$"""
|
limit $[from_line]$,$[rows]$"""
|
||||||
|
|
||||||
def tablesSQL(self):
|
def tablesSQL(self):
|
||||||
|
@ -62,7 +62,7 @@ class Oracleor(SQLor):
|
|||||||
from (
|
from (
|
||||||
select page_s.*,rownum row_id
|
select page_s.*,rownum row_id
|
||||||
from (%s) page_s
|
from (%s) page_s
|
||||||
order by $[sort]$
|
order by $[sort]$ $[order]$
|
||||||
)
|
)
|
||||||
where row_id >=$[from_line]$ and row_id < $[end_line]$"""
|
where row_id >=$[from_line]$ and row_id < $[end_line]$"""
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class PostgreSQLor(SQLor):
|
|||||||
from (
|
from (
|
||||||
select page_s.*,rownum row_id
|
select page_s.*,rownum row_id
|
||||||
from (%s) page_s
|
from (%s) page_s
|
||||||
order by $[sort]$
|
order by $[sort]$ $[order]$
|
||||||
)
|
)
|
||||||
where row_id >=$[from_line]$ and row_id < $[end_line]$"""
|
where row_id >=$[from_line]$ and row_id < $[end_line]$"""
|
||||||
|
|
||||||
|
38
sqlor/sor.py
38
sqlor/sor.py
@ -20,8 +20,7 @@ def db_type_2_py_type(o):
|
|||||||
if isinstance(o,decimal.Decimal):
|
if isinstance(o,decimal.Decimal):
|
||||||
return float(o)
|
return float(o)
|
||||||
if isinstance(o,datetime):
|
if isinstance(o,datetime):
|
||||||
# return '%020d' % int(o.timestamp() * 1000)
|
return '%020d' % int(o.timestamp() * 1000)
|
||||||
return str(o)
|
|
||||||
if isinstance(o, date):
|
if isinstance(o, date):
|
||||||
return '%04d-%02d-%02d' % (o.year, o.month, o.day)
|
return '%04d-%02d-%02d' % (o.year, o.month, o.day)
|
||||||
return o
|
return o
|
||||||
@ -166,14 +165,6 @@ class SQLor(object):
|
|||||||
ret = u"""select count(*) rcnt from (%s) rowcount_table""" % sql
|
ret = u"""select count(*) rcnt from (%s) rowcount_table""" % sql
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def sortSQL(self, sql, NS):
|
|
||||||
sort = NS.get('sort',None)
|
|
||||||
if sort is None:
|
|
||||||
return sql
|
|
||||||
if isinstance(sort, list):
|
|
||||||
sort = ','.join(sort)
|
|
||||||
return sql + ' ORDER BY ' + sort
|
|
||||||
|
|
||||||
def pagingSQL(self,sql,paging,NS):
|
def pagingSQL(self,sql,paging,NS):
|
||||||
"""
|
"""
|
||||||
default it not support paging
|
default it not support paging
|
||||||
@ -181,21 +172,20 @@ class SQLor(object):
|
|||||||
page = int(NS.get(paging['pagename'],1))
|
page = int(NS.get(paging['pagename'],1))
|
||||||
rows = int(NS.get(paging['rowsname'],ROWS))
|
rows = int(NS.get(paging['rowsname'],ROWS))
|
||||||
sort = NS.get(paging.get('sortname','sort'),None)
|
sort = NS.get(paging.get('sortname','sort'),None)
|
||||||
if isinstance(sort, list):
|
order = NS.get(paging.get('ordername','asc'),'asc')
|
||||||
sort = ','.join(sort)
|
|
||||||
if not sort:
|
if not sort:
|
||||||
return sql
|
return sql
|
||||||
if page < 1:
|
if page < 1:
|
||||||
page = 1
|
page = 1
|
||||||
from_line = (page - 1) * rows
|
from_line = (page - 1) * rows + 1
|
||||||
end_line = page * rows
|
end_line = page * rows + 1
|
||||||
psql = self.pagingSQLmodel()
|
psql = self.pagingSQLmodel()
|
||||||
ns={
|
ns={
|
||||||
'from_line':from_line,
|
'from_line':from_line,
|
||||||
'end_line':end_line,
|
'end_line':end_line,
|
||||||
'rows':rows,
|
'rows':rows,
|
||||||
'sort':sort,
|
'sort':sort,
|
||||||
'order':'',
|
'order':order,
|
||||||
}
|
}
|
||||||
ac = ArgsConvert('$[',']$')
|
ac = ArgsConvert('$[',']$')
|
||||||
psql = ac.convert(psql,ns)
|
psql = ac.convert(psql,ns)
|
||||||
@ -230,14 +220,15 @@ class SQLor(object):
|
|||||||
datas = self.dataConvert(datas)
|
datas = self.dataConvert(datas)
|
||||||
try:
|
try:
|
||||||
if self.async_mode:
|
if self.async_mode:
|
||||||
return await cursor.execute(markedSQL,datas)
|
await cursor.execute(markedSQL,datas)
|
||||||
else:
|
else:
|
||||||
return cursor.execute(markedSQL,datas)
|
cursor.execute(markedSQL,datas)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print( "markedSQL=",markedSQL,':',datas,':',e)
|
print( "markedSQL=",markedSQL,':',datas,':',e)
|
||||||
print_exc()
|
print_exc()
|
||||||
raise e
|
raise e
|
||||||
|
return
|
||||||
|
|
||||||
def maskingSQL(self,org_sql,NS):
|
def maskingSQL(self,org_sql,NS):
|
||||||
"""
|
"""
|
||||||
@ -285,7 +276,7 @@ class SQLor(object):
|
|||||||
async def execute(self,sql,value,callback,**kwargs):
|
async def execute(self,sql,value,callback,**kwargs):
|
||||||
sqltype = self.getSqlType(sql)
|
sqltype = self.getSqlType(sql)
|
||||||
cur = self.cursor()
|
cur = self.cursor()
|
||||||
ret = await self.runVarSQL(cur,sql,value)
|
await self.runVarSQL(cur,sql,value)
|
||||||
if sqltype == 'qry' and callback is not None:
|
if sqltype == 'qry' and callback is not None:
|
||||||
fields = [ i[0].lower() for i in cur.description ]
|
fields = [ i[0].lower() for i in cur.description ]
|
||||||
rec = None
|
rec = None
|
||||||
@ -305,7 +296,6 @@ class SQLor(object):
|
|||||||
rec = cur.fetchone()
|
rec = cur.fetchone()
|
||||||
if sqltype == 'dml':
|
if sqltype == 'dml':
|
||||||
self.dataChanged = True
|
self.dataChanged = True
|
||||||
return ret
|
|
||||||
|
|
||||||
async def executemany(self,sql,values):
|
async def executemany(self,sql,values):
|
||||||
cur = self.cursor()
|
cur = self.cursor()
|
||||||
@ -466,16 +456,12 @@ class SQLor(object):
|
|||||||
await self.execute(sql,NS,callback)
|
await self.execute(sql,NS,callback)
|
||||||
|
|
||||||
async def sqlExecute(self,desc,NS):
|
async def sqlExecute(self,desc,NS):
|
||||||
return await self.execute(desc,NS,None)
|
await self.execute(desc,NS,None)
|
||||||
|
|
||||||
async def sqlExe(self,sql,ns):
|
async def sqlExe(self,sql,ns):
|
||||||
ret = []
|
ret = []
|
||||||
r = await self.execute(sql,ns,
|
await self.execute(sql,ns,
|
||||||
callback=lambda x:ret.append(x))
|
callback=lambda x:ret.append(x))
|
||||||
sqltype = self.getSqlType(sql)
|
|
||||||
if sqltype == 'dml':
|
|
||||||
return r
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def sqlPaging(self,sql,ns):
|
async def sqlPaging(self,sql,ns):
|
||||||
@ -635,8 +621,6 @@ class SQLor(object):
|
|||||||
'rows':rows
|
'rows':rows
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
if ns.get('sort'):
|
|
||||||
sql = self.sortSQL(sql, ns)
|
|
||||||
return await self.sqlExe(sql,ns)
|
return await self.sqlExe(sql,ns)
|
||||||
|
|
||||||
async def U(self,tablename,ns):
|
async def U(self,tablename,ns):
|
||||||
|
@ -38,7 +38,7 @@ class SQLite3or(SQLor):
|
|||||||
return tuple(d)
|
return tuple(d)
|
||||||
|
|
||||||
def pagingSQLmodel(self):
|
def pagingSQLmodel(self):
|
||||||
sql = u"""select * from (%s) order by $[sort]$ limit $[from_line]$,$[end_line]$"""
|
sql = u"""select * from (%s) order by $[sort]$ $[order]$ limit $[from_line]$,$[end_line]$"""
|
||||||
return sql
|
return sql
|
||||||
|
|
||||||
def tablesSQL(self):
|
def tablesSQL(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user