When the variable NUMBER_OF_ITERATIONS is set to 1, everything works fine…but when I change it to any value greater than 1 I get some problems.
First of all, in this case when i print the value of res i get an huge number (like 18446744073709551615).
Second, but most important, in this case the script can’t process data because the lenght of value is always 0…
if __name__ == '__main__':
NUMBER_OF_ITERATIONS = 2
conn = DBconnection() # return a database connection
for i in range( NUMBER_OF_ITERATIONS ):
cursor = conn.cursor()
res = cursor.execute( 'SELECT field
FROM table
WHERE other_field = 0
LIMIT 10 LOCK IN SHARE MODE' )
print '# of selected rows: ' + str(res)
values = []
for elem in cursor.fetchall():
if elem != None:
values.append( list(elem).pop() )
if len( values ) != 0:
# do something...
else:
print 'NO VALUES AVAILABLE'
cursor.close()
break
conn.close()
print 'DONE'
I’m using the InnoDB storage engine and simultaneously at this script there is another script python that is uploading data on the same table (using the construct LOAD DATA INFILE).
I thought that it could be due to a table lock caused by the load data, but what’s the difference from one to 2 (or more) iterations? With one iteration all works good, while with 2 even the first iteration goes bad. I can’t get the point.
I was unable to reproduce the problem using the following code. Can you modify it to demonstrate the error?
yields