1
1
# -------------------------------------------------------
2
2
#
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 $
4
4
#
5
5
# Copyright (c) 1997 Edmund Mergl
6
6
#
7
7
# -------------------------------------------------------
8
8
9
9
package Pg ;
10
10
11
- use strict;
11
+ # use strict;
12
12
use Carp;
13
13
use varsqw( $VERSION @ISA @EXPORT $AUTOLOAD) ;
14
14
@@ -84,7 +84,7 @@ require 5.002;
84
84
PGRES_InvalidOid
85
85
) ;
86
86
87
- $Pg::VERSION =' 1.6.3 ' ;
87
+ $Pg::VERSION =' 1.7.0 ' ;
88
88
89
89
sub AUTOLOAD {
90
90
# This AUTOLOAD is used to 'autoload' constants from the constant()
@@ -115,25 +115,21 @@ sub doQuery {
115
115
my $query =shift ;
116
116
my $array_ref =shift ;
117
117
118
- my ($result ,$status ,$nfields , $ntuples , $ i ,$j );
118
+ my ($result ,$status ,$i ,$j );
119
119
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
+ }
129
127
}
130
128
}
131
-
132
- PQclear($result );
133
-
134
- return 1;
129
+ return $status ;
135
130
}
136
131
132
+
137
133
1;
138
134
139
135
__END__
@@ -192,6 +188,11 @@ about freeing the connection- and result-structures.
192
188
Perl calls the destructor whenever the last reference
193
189
to an object goes away.
194
190
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
+
195
196
=head2 old style
196
197
197
198
All functions and constants are imported into the calling
@@ -205,7 +206,6 @@ to be freed by the user:
205
206
PQsetdb, use PQfinish to free memory.
206
207
PQexec, use PQclear to free memory.
207
208
208
-
209
209
Pg.pm contains one convenience function: doQuery. It fills a
210
210
two-dimensional array with the result of your query. Usage:
211
211
@@ -252,12 +252,14 @@ identification. Before using $conn you should call $conn->status to ensure,
252
252
that the connection was properly made. Use the methods below to access
253
253
the contents of the PGconn structure.
254
254
255
- $conn = Pg::connectdb("option = value")
255
+ $conn = Pg::connectdb("option1=value option2= value ... ")
256
256
257
257
Opens 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.
261
263
Use the methods below to access the contents of the PGconn structure.
262
264
263
265
$Option_ref = Pg::conndefaults()