error in python and mysql statement - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: error in python and mysql statement (/thread-33230.html) |
error in python and mysql statement - vj78 - Apr-07-2021 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() RE: error in python and mysql statement - vj78 - Apr-07-2021 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 RE: error in python and mysql statement - buran - Apr-08-2021 params that you pass to execute() as second argument must be tuple, even if it is one-element tuple like (2, ) - note the comma
RE: error in python and mysql statement - vj78 - Apr-08-2021 (Apr-08-2021, 05:26 AM)buran Wrote: params that you pass to Now the error message is different: Failed calling stored routine; tuple index out of range RE: error in python and mysql statement - vj78 - Apr-08-2021 (Apr-08-2021, 01:29 PM)vj78 Wrote:(Apr-08-2021, 05:26 AM)buran Wrote: params that you pass to Yes, your answer fixed the problem. |