Python Forum
error in python and mysql statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error in python and mysql statement
#1
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s AND usertimeout IS NULL DESC LIMIT 1' at line 1

mysql = "SELECT usertimein FROM userstimeclock WHERE userid = %s AND usertimeout IS NULL DESC LIMIT 1"
            myparams = str( myresult2[0])
            mycursor.execute(mysql, myparams)
            myresult = mycursor.fetchone()
Reply
#2
I updated the SQL Statement it complains on %s. If I hard code the value 2 it works?

SELECT usertimein FROM userstimeclock WHERE userid = %s AND usertimeout IS NULL ORDER BY timeclockid DESC LIMIT 1
Reply
#3
params that you pass to execute() as second argument must be tuple, even if it is one-element tuple like (2, ) - note the comma
vj78 likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(Apr-08-2021, 05:26 AM)buran Wrote: params that you pass to execute() as second argument must be tuple, even if it is one-element tuple like (2, ) - note the comma

Now the error message is different: Failed calling stored routine; tuple index out of range
Reply
#5
(Apr-08-2021, 01:29 PM)vj78 Wrote:
(Apr-08-2021, 05:26 AM)buran Wrote: params that you pass to execute() as second argument must be tuple, even if it is one-element tuple like (2, ) - note the comma

Now the error message is different: Failed calling stored routine; tuple index out of range

Yes, your answer fixed the problem.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python and MYSQL Resultset vj78 2 2,665 Apr-02-2021, 12:41 AM
Last Post: vj78
  error when inserting list statement from python to MySQL ADBYITMS 0 1,797 Nov-10-2019, 10:44 AM
Last Post: ADBYITMS
  mysql database error brecht83 1 5,389 Dec-14-2018, 01:25 PM
Last Post: jeanMichelBain

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020