Re: [Templates] Passing a list to DBI execute? (solved)

[prev] [thread] [next] [Date index for 2004/12/08]

From: Harald Joerg
Subject: Re: [Templates] Passing a list to DBI execute? (solved)
Date: 08:33 on 08 Dec 2004
Vivek Khera writes:

> On Dec 6, 2004, at 5:55 PM, Larry Leszczynski wrote:
>
>> Thanks for the idea Harald!  I had previously tried using eval but
>> without
>> success.  It now works using the following:
>>
>>    [%
>>       sth  = DBI.prepare(query);
>>       params_list = "'" _ bind_params.join("','") _ "'";
>>       "[% rows = sth.execute($params_list) %" _ "]" FILTER eval;
>>       FOREACH row IN rows;
>>          ...do stuff...
>>       END;
>>    -%]
>
> I hope your bind_params have no funky SQL characters in them,
> especially single quotes.  You really should call the DBI's quote()
> method on each value, then join that result with just a comma.

I admit that I've been too lazy to prepare a sample with DBI and that
I've been sloppy in quoting.

However, I'd doubt that DBI's quote method Does The Right Thing in
this case.  It does SQL-compliant escaping, typically by replacing
q(a'b) with q('a''b').  But TT2 isn't SQL when it comes to parsing.

I've just tested it: TT2's parser converts q('a''b') to two separate
parameters 'a' and 'b'.  So, if you have funky SQL characters, you'd
*really* better wait for TT3 :-)
        -- 
        Cheers,
haj

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] Passing a list to DBI execute?
Larry Leszczynski 18:14 on 06 Dec 2004

Re: [Templates] Passing a list to DBI execute?
Andy Wardley 18:19 on 06 Dec 2004

Re: [Templates] Passing a list to DBI execute?
Harald Joerg 21:34 on 06 Dec 2004

Re: [Templates] Passing a list to DBI execute? (solved)
Larry Leszczynski 22:55 on 06 Dec 2004

Re: [Templates] Passing a list to DBI execute? (solved)
Harald Joerg 08:33 on 08 Dec 2004

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52