Escaping confusion with Python 3 + MySQL

alister alister.ware at ntlworld.com
Sun Mar 26 13:58:45 EDT 2017


On Sun, 26 Mar 2017 07:43:51 -0700, Νίκος Βέργος wrote:

> Τη Κυριακή, 26 Μαρτίου 2017 - 5:38:57 μ.μ. UTC+3, ο χρήστης alister
> έγραψε:
>> On Sun, 26 Mar 2017 07:24:49 -0700, Νίκος Βέργος wrote:
>> 
>> > Τη Κυριακή, 26 Μαρτίου 2017 - 5:19:27 μ.μ. UTC+3, ο χρήστης Ian
>> > έγραψε:
>> > 
>> >> You need to change the placeholders back. The poster who told you to
>> >> replace them was misinformed.
>> > 
>> > okey altered them back to
>> > 
>> > 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) )
>> > 
>> > but now the problem is how to exact;y type the Where HOST like "%%%"
>> > 
>> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character.
>> 
>> 
>> as a quick thought (untested) it is probably best to have %s as your
>> parameter for the Like clause & ad the sql wild-cards (% symbols) to
>> the data you pass in as I think the expansion of %s adds quote marks
>> which will certainly cause the sql parser issues.
> 
> How do you propose writing that cur.execute statement Alister?


cur.execute('''UPDATE visitors SET (pagesID, host, ref, location,
>> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE
>> > host LIKE %s '''

but you will need to amend the data  you pass so that the last element 
has the surrounding % characters .


-- 
T-1's congested due to porn traffic to the news server.



More information about the Python-list mailing list