[mod_python] String format in "LIKE" clause

Luis M. Gonzalez luismg at gmx.net
Thu Jan 26 19:34:07 EST 2006


Thanks Graham, but no, this is not what I want to do...
I'll try to explain it better:

Lets say that I want to return a list of companies whose names include the 
word "Co" ("Co" is pased as a parameter to the query), so I can get:

Acme Corporation Ltd.
Barnes Corp.  Inc.
Corporative Management S.A.
Fresh Corpse Foods, Ltd.
etc, etc...

So, how should I include this parameter into the LIKE clause.
I guess it should be enclosed between "%" and "%", but what should I put in 
between?





----- Original Message ----- 
From: "Graham Dumpleton" <grahamd at dscpl.com.au>
To: "Luis M. Gonzalez" <luismg at gmx.net>
Cc: <mod_python at modpython.org>
Sent: Thursday, January 26, 2006 8:46 PM
Subject: Re: [mod_python] String format in "LIKE" clause


> Luis M. Gonzalez wrote ..
>> I tried this:
>> ("select * from customers where company like %s%"  %company ) # doesn't
>> work
>> ("select * from customers where company like '%(%s)%"  %company  # 
>> doesn't
>> work either
>>
>> The question is:
>> How should a include the parameter into de LIKE clause in order to accept
>> only a part of the full company name and return the matching results?
>
> Double up the"%" to get an actual percentage passed through.
>
>  ("select * from customers where company like %s%%"  %company )
>
> At least that would be the problem if it is simply using "%" operator on
> string:
>
>>>> "select * from customers where company like %s%" % "ME"
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> ValueError: incomplete format
>
>>>> "select * from customers where company like %s%%"  % "ME"
> 'select * from customers where company like ME%'
>
> Graham
> 
Thanks Graham, but no, this is not what I want to do...
I'll try to explain it better:

Lets say that I want to return a list of companies whose names include the 
word "Co" ("Co" is pased as a parameter to the query), so I can get:

Acme Corporation Ltd.
Barnes Corp.  Inc.
Corporative Management S.A.
Fresh Corpse Foods, Ltd.
etc, etc...

So, how should I include this parameter into the LIKE clause.
I guess it should be enclosed between "%" and "%", but what should I put in 
between?





----- Original Message ----- 
From: "Graham Dumpleton" <grahamd at dscpl.com.au>
To: "Luis M. Gonzalez" <luismg at gmx.net>
Cc: <mod_python at modpython.org>
Sent: Thursday, January 26, 2006 8:46 PM
Subject: Re: [mod_python] String format in "LIKE" clause


> Luis M. Gonzalez wrote ..
>> I tried this:
>> ("select * from customers where company like %s%"  %company ) # doesn't
>> work
>> ("select * from customers where company like '%(%s)%"  %company  # 
>> doesn't
>> work either
>>
>> The question is:
>> How should a include the parameter into de LIKE clause in order to accept
>> only a part of the full company name and return the matching results?
>
> Double up the"%" to get an actual percentage passed through.
>
>  ("select * from customers where company like %s%%"  %company )
>
> At least that would be the problem if it is simply using "%" operator on
> string:
>
>>>> "select * from customers where company like %s%" % "ME"
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> ValueError: incomplete format
>
>>>> "select * from customers where company like %s%%"  % "ME"
> 'select * from customers where company like ME%'
>
> Graham
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060126/a90694bd/attachment.html


More information about the Mod_python mailing list