Skip to content Skip to sidebar Skip to footer

Executemany Confusion

Ok, so I have a function that selects certain rows in a sqlite database based on input from a plugin. I got the plugin to select and fetch rows when just one statement is involved,

Solution 1:

Look at http://www.python.org/dev/peps/pep-0249/

Use of this method for an operation which produces one or more result sets constitutes undefined behavior, and the implementation is permitted

So, executemany can be used for INSERT's and UPDATE's but not for SELECT

You can try following code:

elifisinstance(offset, (tuple, list)):
    offsets=', '.join(offset)
    self.memcursor.execute('''select all id,matbefore,matafter,name,date 
                                       from main as main where name IN (?)''', [offsets])

Solution 2:

I don't think you need executemany here. Try something like this instead:

self.memcursor.execute('''SELECT id, matbefore, matafter, name, date 
                            FROM main 
                           WHERE name IN (%s)''' % 
                       ','.join('?'*len(offset)), (offset,))

Note that the string interpolation is done to place multiple placeholders into the query.

Post a Comment for "Executemany Confusion"