2013-08-29 14:03:45 +02:00
import threading
import Queue
sqlSubmitQueue = Queue . Queue ( ) #SQLITE3 is so thread-unsafe that they won't even let you call it from different threads using your own locks. SQL objects can only be called from one thread.
sqlReturnQueue = Queue . Queue ( )
sqlLock = threading . Lock ( )
2013-08-27 02:00:30 +02:00
def sqlQuery ( sqlStatement , * args ) :
2013-08-29 14:03:45 +02:00
sqlLock . acquire ( )
sqlSubmitQueue . put ( sqlStatement )
2013-08-27 02:00:30 +02:00
if args == ( ) :
2013-08-29 14:03:45 +02:00
sqlSubmitQueue . put ( ' ' )
2013-08-27 02:00:30 +02:00
else :
2013-08-29 14:03:45 +02:00
sqlSubmitQueue . put ( args )
2013-08-27 02:00:30 +02:00
2013-08-29 14:03:45 +02:00
queryreturn = sqlReturnQueue . get ( )
sqlLock . release ( )
2013-08-27 02:00:30 +02:00
return queryreturn
def sqlExecute ( sqlStatement , * args ) :
2013-08-29 14:03:45 +02:00
sqlLock . acquire ( )
sqlSubmitQueue . put ( sqlStatement )
2013-08-27 02:00:30 +02:00
if args == ( ) :
2013-08-29 14:03:45 +02:00
sqlSubmitQueue . put ( ' ' )
2013-08-27 02:00:30 +02:00
else :
2013-08-29 14:03:45 +02:00
sqlSubmitQueue . put ( args )
2013-08-27 02:00:30 +02:00
2013-08-29 14:03:45 +02:00
sqlReturnQueue . get ( )
sqlSubmitQueue . put ( ' commit ' )
sqlLock . release ( )
2013-08-27 02:00:30 +02:00
def sqlStoredProcedure ( procName ) :
2013-08-29 14:03:45 +02:00
sqlLock . acquire ( )
sqlSubmitQueue . put ( procName )
sqlLock . release ( )