11# -------------------------------------------------------
22#
3- # $Id: Pg.pm,v 1.4 1997/09/25 21:14:43 mergl Exp $
3+ # $Id: Pg.pm,v 1.5 1998/02/20 21:25:35 mergl Exp $
44#
55# Copyright (c) 1997 Edmund Mergl
66#
77# -------------------------------------------------------
88
99package Pg ;
1010
11- use strict;
11+ # use strict;
1212use Carp;
1313use varsqw( $VERSION @ISA @EXPORT $AUTOLOAD) ;
1414
@@ -84,7 +84,7 @@ require 5.002;
8484PGRES_InvalidOid
8585) ;
8686
87- $Pg::VERSION =' 1.6.3 ' ;
87+ $Pg::VERSION =' 1.7.0 ' ;
8888
8989sub AUTOLOAD {
9090# This AUTOLOAD is used to 'autoload' constants from the constant()
@@ -115,25 +115,21 @@ sub doQuery {
115115my $query =shift ;
116116my $array_ref =shift ;
117117
118- my ($result ,$status ,$nfields , $ntuples , $ i ,$j );
118+ my ($result ,$status ,$i ,$j );
119119
120- $result = PQexec($conn ,$query );
121- $status = PQresultStatus($result );
122- return ($status )if (2 !=$status );
123-
124- $nfields = PQnfields($result );
125- $ntuples = PQntuples($result );
126- for ($i =0;$i <$ntuples ;$i ++) {
127- for ($j =0;$j <$nfields ;$j ++) {
128- $$array_ref [$i ][$j ] = PQgetvalue($result ,$i ,$j );
120+ if ($result =$conn -> exec ($query )) {
121+ if (2 == ($status =$result -> resultStatus)) {
122+ for $i (0..$result -> ntuples - 1) {
123+ for $j (0..$result -> nfields - 1) {
124+ $$array_ref [$i ][$j ] =$result -> getvalue($i ,$j );
125+ }
126+ }
129127 }
130128 }
131-
132- PQclear($result );
133-
134- return 1;
129+ return $status ;
135130}
136131
132+
1371331;
138134
139135__END__
@@ -192,6 +188,11 @@ about freeing the connection- and result-structures.
192188Perl calls the destructor whenever the last reference
193189to an object goes away.
194190
191+ The method fetchrow can be used to fetch the next row from
192+ the server: while (@row = $result->fetchrow).
193+ Columns which have NULL as value will be set toC<undef > .
194+
195+
195196=head2 old style
196197
197198All functions and constants are imported into the calling
@@ -205,7 +206,6 @@ to be freed by the user:
205206 PQsetdb, use PQfinish to free memory.
206207 PQexec, use PQclear to free memory.
207208
208-
209209Pg.pm contains one convenience function: doQuery. It fills a
210210two-dimensional array with the result of your query. Usage:
211211
@@ -252,12 +252,14 @@ identification. Before using $conn you should call $conn->status to ensure,
252252that the connection was properly made. Use the methods below to access
253253the contents of the PGconn structure.
254254
255- $conn = Pg::connectdb("option = value")
255+ $conn = Pg::connectdb("option1=value option2= value ... ")
256256
257257Opens a new connection to the backend using connection information in a string.
258- The connection identifier $conn ( a pointer to the PGconn structure ) must be
259- used in subsequent commands for unique identification. Before using $conn you
260- should call $conn->status to ensure, that the connection was properly made.
258+ Possible options are: dbname, host, user, password, authtype, port, tty, options.
259+ The database-name will be converted to lower-case, unless it is surrounded by
260+ double quotes. The connection identifier $conn (a pointer to the PGconn structure)
261+ must be used in subsequent commands for unique identification. Before using $conn
262+ you should call $conn->status to ensure, that the connection was properly made.
261263Use the methods below to access the contents of the PGconn structure.
262264
263265 $Option_ref = Pg::conndefaults()