I don't get it ....
i have a few functions that return rows from sqlite tables. Problem is that some sql querys are working while another not. Function that working perfect :
def selectAll(predstavnik_id):
q = "SELECT * FROM ulaz WHERE predstavnik_id = (?)"
cursor.execute(q, str(predstavnik_id))
rows = cursor.fetchall()
if rows is None:
return None
else:
return rows
And the other one that don't return rows:
def selectStanByUlaz(stan_id):
q = "SELECT * FROM stan WHERE ulaz_id = (?)"
cursor.execute(q, str(stan_id))
rows = cursor.fetchall()
if rows is None:
return None
else:
return rows
There is no any errors, just won't return rows ! I tried in sqlite studio with same query syntax and it's working just fine What could be a problem ?
Thanks in advance
Both of these functions don't do what you expect them to do:
The second argument to
cursor.executeis defined to take asequenceof parameters.Notice that
cursor.execute(q, str(predstavnik_id))is not executing withstr(predstavnik_id)being the only parameter:cursor.executeis defined to take a sequence, andstr(predstavnik_id)is a sequence of characters. You probably meantcursor.execute(q, (str(predstavnik_id), ))(notice the tuple), wherestr(predstavnik_id)is the only element of that sequence.The other function suffers from the same problem.
Python should raise a
RuntimeErrorif those strings are not exactly 1 character, yet if youridvalues are small integers (< 10), it will Just Work (tm) without you noticing the bug.