Escaping confusion with Python 3 + MySQL

Νίκος Βέργος me.on.nzt at gmail.com
Sun Mar 26 09:43:17 EDT 2017


Τη Κυριακή, 26 Μαρτίου 2017 - 4:39:44 μ.μ. UTC+3, ο χρήστης MeV έγραψε:
> On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, Νίκος Βέργος wrote:
> > with import cgitb; cgitb.enable()
> > 
> > ProgrammingError(1064, "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 '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1")
> > 
> > that is all i get form error. error_log doesnt produce errors when iam trying
> > 
> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', 
> > 																																			(pID, domain, ref, location, useros, browser, lastvisit, domain) )
> > 
> > WHY the valued aren't getting substituted wi the aeguments i give it in to work with?
> 
> The % construct is Python 2 and no longer supported in Python 3. You should read up on the "{}" and format method.
> 
> https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting

Even with '{}' instead of '%s' iam still receiving similar errors.
And lathough iam using '%s' up until now substituting worked okey.

its htis where LIKE clause that is only failing.



More information about the Python-list mailing list