Im sure this is a really obvious problem but :
self.curs.execute(
"""SELECT * FROM user WHERE login LIKE '%%s%'""", [login]
)
will not work ... gives me an "unsupported format character ''' (0x27)"
escaping the %'s with % as the doco recommends wont work either.
however this :
self.curs.execute(
"""SELECT * FROM user WHERE login LIKE '%dave%'"""
)
does work
so what's the go ?
cheers
Dave 5 19578
Dave Harrison schrieb: Im sure this is a really obvious problem but :
self.curs.execute( """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] )
will not work ... gives me an "unsupported format character ''' (0x27)"
escaping the %'s with % as the doco recommends wont work either.
Why don't you do
self.curs.execute(
"""SELECT * FROM user WHERE login LIKE %s""", ("%"+login+"%", ))
The problem with escaping the % characters is, that MySQLdb converts
self.curs.execute("""SELECT * FROM user WHERE login LIKE '%%%s%%'""" ,
(login,))
to
"SELECT * FROM user WHERE login LIKE '%'dave'%'"
and I don't know how to prevent this. however this :
self.curs.execute( """SELECT * FROM user WHERE login LIKE '%dave%'""" )
does work
so what's the go ? cheers Dave
Torsten Marek wrote: Dave Harrison schrieb:
Im sure this is a really obvious problem but :
self.curs.execute( """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] )
will not work ... gives me an "unsupported format character ''' (0x27)"
escaping the %'s with % as the doco recommends wont work either. Why don't you do self.curs.execute( """SELECT * FROM user WHERE login LIKE %s""", ("%"+login+"%", )) [...]
You're right. Please ignore my previous post in this thread. It
correctly shows how to escape percent signs, but won't work in the SQL
context.
-- Gerhard
> >Im sure this is a really obvious problem but : self.curs.execute( """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] )
will not work ... gives me an "unsupported format character ''' (0x27)"
escaping the %'s with % as the doco recommends wont work either.
Why don't you do self.curs.execute( """SELECT * FROM user WHERE login LIKE %s""", ("%"+login+"%", ))
The problem with escaping the % characters is, that MySQLdb converts self.curs.execute("""SELECT * FROM user WHERE login LIKE '%%%s%%'""" , (login,)) to "SELECT * FROM user WHERE login LIKE '%'dave'%'" and I don't know how to prevent this.
hehe yeah Id been testing what I was doing against my mysql client and couldnt work out why the module kept adding the '', you're solution works a treat, thanks torsten however this :
self.curs.execute( """SELECT * FROM user WHERE login LIKE '%dave%'""" )
does work
so what's the go ? cheers Dave
-- http://mail.python.org/mailman/listinfo/python-list
Dave Harrison <da**@nullcube.com> wrote in message news:<ma**********************************@python. org>... Im sure this is a really obvious problem but :
self.curs.execute( """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] )
will not work ... gives me an "unsupported format character ''' (0x27)"
escaping the %'s with % as the doco recommends wont work either.
however this :
self.curs.execute( """SELECT * FROM user WHERE login LIKE '%dave%'""" )
does work
so what's the go ?
Try
"select * from user where login like %s" % ('%%%s%%' % login)
(same as "select * from user where login like %s" % ('%dave%'))
I think you want the % stuff for LIKE to be part of the substituted in
string, not part of the query string. Make sense?
Dave Harrison <da**@nullcube.com> wrote in message news:<ma**********************************@python. org>... Im sure this is a really obvious problem but :
self.curs.execute( """SELECT * FROM user WHERE login LIKE '%%s%'""", [login] )
will not work ... gives me an "unsupported format character ''' (0x27)"
escaping the %'s with % as the doco recommends wont work either.
however this :
self.curs.execute( """SELECT * FROM user WHERE login LIKE '%dave%'""" )
does work
so what's the go ? cheers Dave
I just posted a reply and realized I made one mistake. I said to use
"select * from user where login like %s" % ('%%%s%%' % login)
But it should be like
"select * from user where login like %s", ('%%%s%%' % login)
as in
self.curs.execute("select * from user where login like %s", ('%%%s%%' % login))
That should work.
-Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Peter Nikolaidis |
last post by:
Greetings,
I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a
Fink distribution of Python 2.2.2. I have seen only a few posts...
|
by: Derek Fountain |
last post by:
I was trying to use MySQLdb to connect to a database. All is OK, except I
can't figure out how to get the details of an error. Suppose I try to...
|
by: Stephen Roderick |
last post by:
Getting weird error, and I was wondering if anyone had any suggestions.
My system appears to satisfy all MySQLdb prerequisities in terms of
python,...
|
by: John Fabiani |
last post by:
Hi,
I'm a newbie and I'm attempting to learn howto create a select statement.
When I use
>>> string1='18 Tadlock Place'
>>>...
|
by: ws Wang |
last post by:
MySQLdb is working fine at command line, however when I tried to use
it with mod_python, it give me a "server not initialized" error.
This is...
|
by: fedor |
last post by:
Hi all,
I have a problem with mysql connections. After about 28000-29000
connections, I get a "Can't connect to MySQL server on '127.0.0.1'"...
|
by: Yi Xing |
last post by:
Hi,
I met the following error when I tried to install MySQLdb. I had no
problem installing numarray, Numeric, Rpy, etc. Does anyone know
what's...
|
by: jgarber |
last post by:
Hello,
I just upgraded MySQLdb to the 1.2.0 version provided by Redhat
Enterprise Linux ES4. At that point I began to get segfaults when...
|
by: Steve Holden |
last post by:
Vaibhav.bhawsar wrote:
imported
The point here is that MySQLdb is a package, not a module. Some packages
have their top-level __init__.py import...
|
by: Nikhil |
last post by:
I am using the MySQLdb python module. I have a table named 'testing'
with few columns, under the 'test' database, what is hosted on a remote
mysql...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |