Re: perl and postgresql - Mailing list pgsql-novice

From Keith Keller
Subject Re: perl and postgresql
Date
Msg-id 20030318235055.GA22762@wombat.san-francisco.ca.us
Whole thread Raw
In response to Re: perl and postgresql  ("Ville Jungman" <ville_jungman@hotmail.com>)
List 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=@_;
    # [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@speakeasy.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


pgsql-novice by date:

Previous
From: "Ville Jungman"
Date:
Subject: Re: perl and postgresql
Next
From: "Ville Jungman"
Date:
Subject: Re: perl and postgresql