-6

This code is stucks:

c.execute("select * from table_name where num=?", a)

And this is not:

c.execute("select * from table_name where num={}".format(a))

So what is wrong? Colmn in table is int and a is int too

  • 2
    So how big is the database? And why the nested query; why not just use `c.execute("select count(*) from users where id=? and lvl=?", (id, lvl))` (using sql parameters to avoid SQL injection)? – Martijn Pieters Oct 12 '16 at 11:47
  • Data base is not too big, about 50 rows with ~9 columns id and lvl source is safe. Anyway i'll use '?' in future, thx – Grizzly Bear Oct 12 '16 at 11:49
  • 1
    How have you determined it is 'stuck'? Just executing this query won't actually fetch any rows yet, for example. – Martijn Pieters Oct 12 '16 at 11:51
  • print("1") below is not shown – Grizzly Bear Oct 12 '16 at 11:52
  • And you are certain the `c.execute()` itself is reached? – Martijn Pieters Oct 12 '16 at 11:54
  • 2
    There's no way anyone is going to be able to help you with only the information provided. Please see [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask). – glibdud Oct 12 '16 at 12:20
  • Hmm i think i got my problem. I cant use '?' mark. This code is works: `c.execute("select * from accounts where num={}".format(num))` And this is not: `c.execute("select * from accounts where num=?", num)` – Grizzly Bear Oct 12 '16 at 19:47
  • Solved (there is invalid type, should be typle): http://stackoverflow.com/questions/16856647/sqlite3-programmingerror-incorrect-number-of-bindings-supplied-the-current-sta – Grizzly Bear Oct 14 '16 at 18:12

1 Answers1

-2

I'm not sure if it works the same on sqlite, but in mysql in order to use the select from select form, you must give each table an alias, like this:

select count(*) from (select * from users as b where id=ID and lvl=LVL) as a

This might be the source of your problem.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Blackbeard
  • 107
  • 3