[CDBI] Use Of Placeholders In set_sql() Example of Beginners Guide

hkclark at gmail.com hkclark at gmail.com
Sun Mar 19 19:36:58 GMT 2006


On 3/19/06, Sam Tregar <sam at tregar.com> wrote:
> On Thu, 16 Mar 2006 hkclark at gmail.com wrote:
>
> > However, I can only get any form of substitution to work if use "%s"
> > in the set_sql() and then do something like this to call it:
> >    my $sth = Music::Artist->sql_persons("F");
> >    $sth->execute;
> >    my @persons = Music::Artist->sth_to_objects($sth);
>
> If you use placeholders then you must pass the param to execute()
> instead:
>
>      my $sth = Music::Artist->sql_persons();
>      $sth->execute("F");
>      my @persons = Music::Artist->sth_to_objects($sth);
>
> -sam
>

Thanks for the reply, Sam.  Yeah, it seems to work when I call execute(),
but the example in the Beginners Guide seems to suggest it should work
without that (http://wiki.class-dbi.com/wiki/Beginners_guide#set_sql):

Like in most of CDBI you can also use placeholders or parameters in your
"set_sql" commands to accect runtime arguments. Like:

__PACKAGE__->set_sql(persons => qq {
select artist.artistid
from artist, person
where artist.artistid = person.artistid
and person.gender = ?});

Then in your code you'd call it like:

my @persons = Music::Artist->search_persons("F");

Does the Beginner's Guide need to be updated?

Thanks again,
H
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digitalcraftsmen.net/mailman/private/classdbi/attachments/20060319/ef689b54/attachment.html


More information about the ClassDBI mailing list