Compare commits

..

10 Commits

Author SHA1 Message Date
yumoqing
20791b0d71 bugfix 2023-10-09 16:11:02 +08:00
yumoqing
f94373e715 bugfix 2023-07-05 15:05:33 +08:00
yumoqing
df824afb21 bugfix 2023-06-02 12:46:55 +08:00
yumoqing
4d9ef06619 bugfi 2023-06-02 12:46:16 +08:00
yumoqing
49d16ecd58 bugfix 2023-06-01 15:12:01 +08:00
yumoqing
12921c70ca bugfix 2023-06-01 15:06:09 +08:00
yumoqing
2d13889a26 bugfix 2023-05-19 02:22:05 +08:00
yumoqing
86487cbae1 bugfix 2023-05-17 11:02:22 +08:00
yumoqing
4bd0130759 bugfix 2023-05-11 20:27:38 +08:00
yumoqing
7903c00196 bugfix 2023-05-11 16:43:14 +08:00
17 changed files with 36 additions and 52 deletions

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

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

Before

Width:  |  Height:  |  Size: 233 KiB

After

Width:  |  Height:  |  Size: 233 KiB

View File

@ -14,6 +14,8 @@ 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 ]
@ -22,12 +24,6 @@ class CBObject:
rec = convrec(info, rec)
await sor.C(self.tbl, rec)
typesconv = {
"int":int,
"float":float,
"str":str,
}
def getRecord(ws):
names = []
types = []
@ -43,7 +39,6 @@ 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 Normal file → Executable file
View File

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

Before

Width:  |  Height:  |  Size: 181 KiB

After

Width:  |  Height:  |  Size: 181 KiB

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

Before

Width:  |  Height:  |  Size: 200 KiB

After

Width:  |  Height:  |  Size: 200 KiB

2
dataloader/typeconv.py Normal file → Executable 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:
if f is None or value is None:
return value
return f(value)
return value

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

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

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

View File

@ -16,7 +16,7 @@ time
{%- elif type=='datetime' -%}
datetime
{%- elif type=='timestamp' -%}
TIMESTAMP
TIMESTAMP DEFAULT CURRENT_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]$ $[order]$) as _row_id,page_s.*
select row_number() over(order by $[sort]$) as _row_id,page_s.*
from (%s) page_s
) A
where _row_id >= $[from_line]$ and _row_id < $[end_line]$"""

View File

@ -71,35 +71,8 @@ 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]$ $[order]$
return u"""select * from (%s) A order by $[sort]$
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]$
order by $[sort]$
)
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]$
order by $[sort]$
)
where row_id >=$[from_line]$ and row_id < $[end_line]$"""

View File

@ -20,7 +20,8 @@ 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 '%020d' % int(o.timestamp() * 1000)
return str(o)
if isinstance(o, date):
return '%04d-%02d-%02d' % (o.year, o.month, o.day)
return o
@ -165,6 +166,14 @@ 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
@ -172,20 +181,21 @@ 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)
order = NS.get(paging.get('ordername','asc'),'asc')
if isinstance(sort, list):
sort = ','.join(sort)
if not sort:
return sql
if page < 1:
page = 1
from_line = (page - 1) * rows + 1
end_line = page * rows + 1
from_line = (page - 1) * rows
end_line = page * rows
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)
@ -220,15 +230,14 @@ class SQLor(object):
datas = self.dataConvert(datas)
try:
if self.async_mode:
await cursor.execute(markedSQL,datas)
return await cursor.execute(markedSQL,datas)
else:
cursor.execute(markedSQL,datas)
return cursor.execute(markedSQL,datas)
except Exception as e:
print( "markedSQL=",markedSQL,':',datas,':',e)
print_exc()
raise e
return
def maskingSQL(self,org_sql,NS):
"""
@ -276,7 +285,7 @@ class SQLor(object):
async def execute(self,sql,value,callback,**kwargs):
sqltype = self.getSqlType(sql)
cur = self.cursor()
await self.runVarSQL(cur,sql,value)
ret = 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
@ -296,6 +305,7 @@ class SQLor(object):
rec = cur.fetchone()
if sqltype == 'dml':
self.dataChanged = True
return ret
async def executemany(self,sql,values):
cur = self.cursor()
@ -456,12 +466,16 @@ class SQLor(object):
await self.execute(sql,NS,callback)
async def sqlExecute(self,desc,NS):
await self.execute(desc,NS,None)
return await self.execute(desc,NS,None)
async def sqlExe(self,sql,ns):
ret = []
await self.execute(sql,ns,
r = 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):
@ -621,6 +635,8 @@ 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]$ $[order]$ limit $[from_line]$,$[end_line]$"""
sql = u"""select * from (%s) order by $[sort]$ limit $[from_line]$,$[end_line]$"""
return sql
def tablesSQL(self):