Lists: | pgsql-general |
---|
From: | John Frank <jrf(at)segovia(dot)mit(dot)edu> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | perl use of cursors and fetch forward |
Date: | 2001-01-29 14:37:15 |
Message-ID: | Pine.LNX.4.30.0101290936550.4023-100000@segovia.mit.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Can someone tell me how to use Postgres cursors through perl? A sample is
below. Is there some way to keep the transaction active between
$conn-exec calls?
#!/usr/local/bin/perl
use Pg;
my $conn = Pg::connectdb("dbname = test");
my $result = $conn->exec("begin work; declare c1 cursor for select fld1
from tbl1 ; ");
$result = $conn->exec("fetch forward 1 in c1;");
print "Hurray, I fetched a row: " . $result->fetchrow . "\n";
$result = $conn->exec("end work;");
jrf(at)roog:~/$ perl test_cursor.pl
NOTICE: PerformPortalFetch: portal "c1" not found
Hurray, I fetched a row:
NOTICE: COMMIT: no transaction in progress
jrf(at)roog:~/$
From: | John Frank <jrf(at)segovia(dot)mit(dot)edu> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: perl use of cursors and fetch forward |
Date: | 2001-01-29 16:54:59 |
Message-ID: | Pine.LNX.4.30.0101291153300.4035-100000@segovia.mit.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
dooh. never mind.
this works if the "begin work;" and "declare ...;" are in separate exec
requests.
On Mon, 29 Jan 2001, John Frank wrote:
>
> Can someone tell me how to use Postgres cursors through perl? A sample is
> below. Is there some way to keep the transaction active between
> $conn-exec calls?
>
> #!/usr/local/bin/perl
> use Pg;
> my $conn = Pg::connectdb("dbname = test");
>
> my $result = $conn->exec("begin work; declare c1 cursor for select fld1
> from tbl1 ; ");
>
> $result = $conn->exec("fetch forward 1 in c1;");
> print "Hurray, I fetched a row: " . $result->fetchrow . "\n";
>
> $result = $conn->exec("end work;");
>
>
>
> jrf(at)roog:~/$ perl test_cursor.pl
> NOTICE: PerformPortalFetch: portal "c1" not found
> Hurray, I fetched a row:
> NOTICE: COMMIT: no transaction in progress
> jrf(at)roog:~/$
>
>
>
>
>
>
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | John Frank <jrf(at)segovia(dot)mit(dot)edu> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Re: perl use of cursors and fetch forward |
Date: | 2001-01-29 17:17:18 |
Message-ID: | 25060.980788638@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
John Frank <jrf(at)segovia(dot)mit(dot)edu> writes:
> this works if the "begin work;" and "declare ...;" are in separate exec
> requests.
This is fixed for 7.1. The problem in 7.0 is that the check for "are we
inside a transaction block?" is done at the wrong time, ie, during
initial parsing of the query string ...
regards, tom lane