Python Forum

Full Version: error in python and mysql statement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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
params that you pass to execute() as second argument must be tuple, even if it is one-element tuple like (2, ) - note the comma
(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
(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.