From: | Patricio Muñoz <adivisi(at)gmail(dot)com> |
---|---|
To: | "Alvaro Herrera" <alvherre(at)commandprompt(dot)com> |
Cc: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | Re: Perl y Cursores |
Date: | 2007-10-04 14:27:10 |
Message-ID: | b82041200710040727m61f249a0x3178ffb28a91d9f3@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
El día 3/10/07, Alvaro Herrera <alvherre(at)commandprompt(dot)com> escribió:
>
> Patricio Muñoz escribió:
> > Estimados,
> > Alguien sabe si es posible utilizar cursores desde Perl utilizando dbi ?
> >
> > Según la documentacion del modulo DBD:Pg, aparece una seccion dedicada a
> > cursores, la expongo
> >
> > Cursors
> > <http://search.cpan.org/%7Edbdpg/DBD-Pg-1.49/Pg.pm#___top>
> >
> > "Although PostgreSQL has a cursor concept, it has not been used in the
> > current implementation. Cursors in PostgreSQL can only be used inside a
> > transaction block. Because only one transaction block at a time is
> allowed,
> > this would have implied the restriction not to use any nested
> > SELECTstatements. Hence the
> > execute method fetches all data at once into data structures located in
> the
> > front-end application. This approach must to be considered when
> selecting
> > large amounts of data!"
> > Según lo que lei y entendi no es soportado ?
>
> No directamente, pero hasta donde veo, puedes desactivar AutoCommit y
> luego usar DECLARE y FETCH para manipular los cursores directamente.
> Observa que tienes que abrir una transaccion primero, y terminarla
> despues de agotar el cursor.
>
> --
> Alvaro Herrera Valdivia, Chile ICBM: S 39º 49' 18.1", W 73º 13'
> 56.4"
> "Lo esencial es invisible para los ojos" (A. de Saint Exúpery)
>
Gracias Alvaro por lo indicado,
Al seguir en la busqueda, encontre una solucion, la expongo por si a alguien
le sirve:
$SERVER = "192.168.0.10";
$STRING = "dbi:Pg:dbname=";
$BASE_DATO = "database";
$PG_BASE = $STRING . $BASE_DATO . ";host=" . $SERVER;
$PG_USER = "user";
$PG_PASSWORD = "pasword";
use DBI;
$dbh = DBI->connect($PG_BASE, $PG_USER, $PG_PASSWORD,{AutoCommit => 0});
$sql = "SELECT * FROM foo";
$dbh->do("DECLARE cur CURSOR WITH HOLD FOR $sql");
while (1) {
my $sth = $dbh->prepare("FETCH 10 FROM cur");
$sth->execute;
last if 0 == $sth->rows;
while (my @row = $sth->fetchrow_array) {
print "@row \n";
}
}
$dbh->do("CLOSE cur");
Saludos cordiales
From | Date | Subject | |
---|---|---|---|
Next Message | José Alberto Sánchez Nieto | 2007-10-04 14:38:33 | Re: Error en Drop Tablespace |
Previous Message | Jenaro Centeno Gomez | 2007-10-04 14:17:48 | Re: Modelador |