From 6ce3ce6b2226c829b7778e6231b2563f86e35de8 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 30 Nov 2017 19:39:31 +0100 Subject: [PATCH] Chunking helper for sql statements with too many variables - preparation for #1081 --- src/helper_sql.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/helper_sql.py b/src/helper_sql.py index d27401cf..086cebfe 100644 --- a/src/helper_sql.py +++ b/src/helper_sql.py @@ -21,6 +21,24 @@ def sqlQuery(sqlStatement, *args): 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): sqlLock.acquire() sqlSubmitQueue.put(sqlStatement)