Chunking helper for sql statements with too many variables

- preparation for #1081
This commit is contained in:
Peter Šurda 2017-11-30 19:39:31 +01:00
parent 52162046bd
commit 6ce3ce6b22
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -21,6 +21,24 @@ def sqlQuery(sqlStatement, *args):
return queryreturn return queryreturn
def sqlExecuteChunked(sqlStatement, idCount, *args):
#SQLITE_MAX_VARIABLE_NUMBER, unfortunately getting/setting isn't exposed to python
sqlExecuteChunked.chunkSize = 999
if idCount == 0 or idCount > len(args):
return 0
totalRowCount = 0
with sqlLock:
for i in range(len(args)-idCount, len(args), sqlExecuteChunked.chunkSize - (len(args)-idCount)):
sqlSubmitQueue.put(sqlStatement)
# first static args, and then iterative chunk
sqlSubmitQueue.put(args[0:len(args)-idCount] + args[i:i+sqlExecuteChunked.chunkSize - len(args)-idCount])
retVal = sqlReturnQueue.get()
totalRowCount += retVal[1]
sqlSubmitQueue.put('commit')
return totalRowCount
def sqlExecute(sqlStatement, *args): def sqlExecute(sqlStatement, *args):
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement) sqlSubmitQueue.put(sqlStatement)