On 08/26/2016 04:22 AM, Alan Gauld via Tutor wrote:
On 26/08/16 02:34, Jim Byrnes wrote:

Exception in Tkinter callback
Traceback (most recent call last):
...
   File "tk_pwds.py", line 56, in fill_accounts_lb
     cur.execute('''SELECT Account FROM pwds WHERE Category=? ORDER BY
Account COLLATE NOCASE''', category)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The
current statement uses 1, and there are 8 supplied.

I cut the working statement from pythoncard and pasted it into tkinter
and am curious why it works in the pythoncard version and not the
tkinter version.

Peter has given the solution, but just to be clear this has
nothing whatsoever to do with Tkinter v Pythoncard it is
entirely a Sqlite issue. (As is evidenced in the error message.)
Did you use an older version of Sqlite when you wrote the
Pythoncard code perhaps? You probably also used an older
version of Python?

The real mystery is how it worked in the Pythoncard version,
unless, as Peter suggests, you just got lucky and always
passed a single valued item?

The pythoncard version has been in use for a while so I used a desktop launcher to started it. It wasn't until I tried to run it from a terminal to see if there were any error messages, that I realized it was using python 2.7.6 and I was working with python 3.4.3.

I am guessing that the different version must have caused the problem.

Finally, the string formatting solution is never a good
idea for database queries since it is (a) open to injection
attack and (b) liable to generate an incorrect SQL query
which is hard to debug. (ie the query gets executed but
returns different data to what you expected/wanted)


The DB is local to my machine so I don't think I have had a problem in the past, but now that you and Peter have shown me the correct way, I will be doing it in the future.

Regards,  Jim


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to