Why do this?

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Mon Oct 9 04:17:41 EDT 2006


In message <Xns985755C711158duncanbooth at 127.0.0.1>, Duncan Booth wrote:

> Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
> 
>> I use the above when I can, when I can't I fall back on
>><http://groups.google.co.nz/groups?selm=efc5b3$can$1@lust.ihug.co.nz>,
>><http://groups.google.co.nz/groups?selm=efhn5v$fia$2@lust.ihug.co.nz>.
> 
> Yes, so you said, but you never came up with a convincing use case where
> that function was better than using the parameterised queries.

First of all, the parametrization doesn't handle wildcards, as we discussed
previously.

Secondly, it's less convenient for cases where a dynamic query is being
built. I previously gave the SQLStringList example. If that's not enough,
here's another (simple) one:

Conditions = []
if Name != None :
    Conditions.append("name = %s" % SQLString(Name))
#end if
if Address != None :
    Conditions.append("address = %s" % SQLString(Address))
#end if
if PhoneNr != None :
    Conditions.append("phone_nr = %s" % SQLString(PhoneNr))
#end if
Query = "select * from table"
if len(Conditions) != 0 :
    Query += " where " + " and ".join(Conditions)
#end if



More information about the Python-list mailing list