Compare commits

..

No commits in common. "20791b0d713dfb0e853a19ab84bbd27dcefb8412" and "c5fe11f3d0f52ac2cbb5f6e06ae6e46cd323996e" have entirely different histories.

17 changed files with 52 additions and 36 deletions

0
dataloader/README.md Executable file → Normal file
View File

0
dataloader/database.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 233 KiB

After

Width:  |  Height:  |  Size: 233 KiB

View File

@ -14,8 +14,6 @@ class CBObject:
async def handle(self,ws):
db = DBPools()
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)
for rec in getRecord(ws):
r = [ v for v in rec.values() if v is not None ]
@ -24,6 +22,12 @@ class CBObject:
rec = convrec(info, rec)
await sor.C(self.tbl, rec)
typesconv = {
"int":int,
"float":float,
"str":str,
}
def getRecord(ws):
names = []
types = []
@ -39,6 +43,7 @@ def getRecord(ws):
else:
dic = {}
for j,c in enumerate(r):
# tf = typesconv.get(types[j],None)
v = c.value
dic[names[j]] = v
yield dic

0
dataloader/macos/dataloader.spec Executable file → Normal file
View File

0
dataloader/table1.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 181 KiB

After

Width:  |  Height:  |  Size: 181 KiB

0
dataloader/table2.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 200 KiB

After

Width:  |  Height:  |  Size: 200 KiB

2
dataloader/typeconv.py Executable file → Normal file
View File

@ -14,7 +14,7 @@ def conv(info, name, value):
for f in fields:
if f['name'] == name:
f = convfuncs.get(f['type'], None)
if f is None or value is None:
if f is None:
return value
return f(value)
return value

0
dataloader/ubuntu/dataloader.spec Executable file → Normal file
View File

0
dataloader/windows/dataloader.spec Executable file → Normal file
View File

0
sqlor/const.py Executable file → Normal file
View File

View File

@ -16,7 +16,7 @@ time
{%- elif type=='datetime' -%}
datetime
{%- elif type=='timestamp' -%}
TIMESTAMP DEFAULT CURRENT_TIMESTAMP
TIMESTAMP
{%- elif type=='text' -%}
longtext
{%- elif type=='bin' -%}

View File

@ -66,7 +66,7 @@ class MsSqlor(SQLor):
def pagingSQLmodel(self):
return u"""select *
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
) A
where _row_id >= $[from_line]$ and _row_id < $[end_line]$"""

View File

@ -71,8 +71,35 @@ class MySqlor(SQLor):
d = [ i['value'] for i in dataList]
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):
return u"""select * from (%s) A order by $[sort]$
return u"""select * from (%s) A order by $[sort]$ $[order]$
limit $[from_line]$,$[rows]$"""
def tablesSQL(self):

View File

@ -62,7 +62,7 @@ class Oracleor(SQLor):
from (
select page_s.*,rownum row_id
from (%s) page_s
order by $[sort]$
order by $[sort]$ $[order]$
)
where row_id >=$[from_line]$ and row_id < $[end_line]$"""

View File

@ -61,7 +61,7 @@ class PostgreSQLor(SQLor):
from (
select page_s.*,rownum row_id
from (%s) page_s
order by $[sort]$
order by $[sort]$ $[order]$
)
where row_id >=$[from_line]$ and row_id < $[end_line]$"""

View File

@ -20,8 +20,7 @@ def db_type_2_py_type(o):
if isinstance(o,decimal.Decimal):
return float(o)
if isinstance(o,datetime):
# return '%020d' % int(o.timestamp() * 1000)
return str(o)
return '%020d' % int(o.timestamp() * 1000)
if isinstance(o, date):
return '%04d-%02d-%02d' % (o.year, o.month, o.day)
return o
@ -166,14 +165,6 @@ class SQLor(object):
ret = u"""select count(*) rcnt from (%s) rowcount_table""" % sql
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):
"""
default it not support paging
@ -181,21 +172,20 @@ class SQLor(object):
page = int(NS.get(paging['pagename'],1))
rows = int(NS.get(paging['rowsname'],ROWS))
sort = NS.get(paging.get('sortname','sort'),None)
if isinstance(sort, list):
sort = ','.join(sort)
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
from_line = (page - 1) * rows + 1
end_line = page * rows + 1
psql = self.pagingSQLmodel()
ns={
'from_line':from_line,
'end_line':end_line,
'rows':rows,
'sort':sort,
'order':'',
'order':order,
}
ac = ArgsConvert('$[',']$')
psql = ac.convert(psql,ns)
@ -230,14 +220,15 @@ class SQLor(object):
datas = self.dataConvert(datas)
try:
if self.async_mode:
return await cursor.execute(markedSQL,datas)
await cursor.execute(markedSQL,datas)
else:
return cursor.execute(markedSQL,datas)
cursor.execute(markedSQL,datas)
except Exception as e:
print( "markedSQL=",markedSQL,':',datas,':',e)
print_exc()
raise e
return
def maskingSQL(self,org_sql,NS):
"""
@ -285,7 +276,7 @@ class SQLor(object):
async def execute(self,sql,value,callback,**kwargs):
sqltype = self.getSqlType(sql)
cur = self.cursor()
ret = await self.runVarSQL(cur,sql,value)
await self.runVarSQL(cur,sql,value)
if sqltype == 'qry' and callback is not None:
fields = [ i[0].lower() for i in cur.description ]
rec = None
@ -305,7 +296,6 @@ class SQLor(object):
rec = cur.fetchone()
if sqltype == 'dml':
self.dataChanged = True
return ret
async def executemany(self,sql,values):
cur = self.cursor()
@ -466,16 +456,12 @@ class SQLor(object):
await self.execute(sql,NS,callback)
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):
ret = []
r = await self.execute(sql,ns,
await self.execute(sql,ns,
callback=lambda x:ret.append(x))
sqltype = self.getSqlType(sql)
if sqltype == 'dml':
return r
return ret
async def sqlPaging(self,sql,ns):
@ -635,8 +621,6 @@ class SQLor(object):
'rows':rows
}
else:
if ns.get('sort'):
sql = self.sortSQL(sql, ns)
return await self.sqlExe(sql,ns)
async def U(self,tablename,ns):

View File

@ -38,7 +38,7 @@ class SQLite3or(SQLor):
return tuple(d)
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
def tablesSQL(self):