From: | Keith Keller <kkeller-postgres(at)wombat(dot)san-francisco(dot)ca(dot)us> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: perl and postgresql |
Date: | 2003-03-18 23:50:55 |
Message-ID: | 20030318235055.GA22762@wombat.san-francisco.ca.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Tue, Mar 18, 2003 at 02:05:33PM +0200, Ville Jungman wrote:
>
> It's easier if you can call sql-commands just in the same way that you do
> with sql-prompt. For example
>
> @result=$self->kanta("select $a from table where name='$prod'");
>
> is much simpler than same query with placeholders. That's why I like to do
> it with sub like this.
It's not really that much easier, if the sub kanta is written to
handle lists, like so:
@result=$self->kanta("select $a from table where name=?",$prod);
Then:
sub kanta {
my $self=shift;
my $sql=shift;
my @values=(at)_;
# [do stuff]
my $sth=prepare($sql);
$sth->execute(@values);
# [do stuff with $sth to return the result
return @result;
}
It's still easy to use kanta--it even allows you not to use
placeholders, but allows you to migrate to it if you wish.
--keith
--
kkeller(at)speakeasy(dot)net
public key: http://wombat.san-francisco.ca.us/kkeller/kkeller.asc
alt.os.linux.slackware FAQ: http://wombat.san-francisco.ca.us/cgi-bin/fom
From | Date | Subject | |
---|---|---|---|
Next Message | Ville Jungman | 2003-03-19 02:28:42 | Re: perl and postgresql |
Previous Message | Stan Horwitz | 2003-03-18 14:52:26 | Question about installing libraries |