From 734328840c636d056d6d0a20bdde2af317d4e110 Mon Sep 17 00:00:00 2001 From: Edmund Mergl Date: Fri, 20 Feb 1998 21:26:08 +0000 Subject: [PATCH] 1.7.01.7.0 --- src/interfaces/perl5/eg/ApachePg.pl | 50 +++++++++++++++++--------------- src/interfaces/perl5/eg/example.newstyle | 32 ++++++++++---------- src/interfaces/perl5/eg/example.oldstyle | 11 +++---- 3 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/interfaces/perl5/eg/ApachePg.pl b/src/interfaces/perl5/eg/ApachePg.pl index a43476e5b2..7885369f89 100644 --- a/src/interfaces/perl5/eg/ApachePg.pl +++ b/src/interfaces/perl5/eg/ApachePg.pl @@ -1,44 +1,48 @@ #!/usr/local/bin/perl # demo script, tested with: -# - PostgreSQL-6.2 -# - apache_1.2.4 -# - mod_perl-1.00 -# - perl5.004_03 +# - PostgreSQL-6.3 +# - apache_1.3 +# - mod_perl-1.08 +# - perl5.004_04 use CGI; use Pg; +use strict; -$query = new CGI; +my $query = new CGI; print $query->header, $query->start_html(-title=>'A Simple Example'), $query->startform, "

Testing Module Pg

", - "Enter database name: ", - $query->textfield(-name=>'dbname'), - "

", - "Enter select command: ", - $query->textfield(-name=>'cmd', -size=>40), - "

", - $query->submit(-value=>'Submit'), + "

", + "", + "", + "", + "", + "", + "", + "
Enter conninfo string: ", $query->textfield(-name=>'conninfo', -size=>40, -default=>'dbname=template1 host=localhost'), "
Enter select command: ", $query->textfield(-name=>'cmd', -size=>40), "

", + "

", $query->submit(-value=>'Submit'), "
", $query->endform; if ($query->param) { - $dbname = $query->param('dbname'); - $conn = Pg::connectdb("dbname = $dbname"); - $cmd = $query->param('cmd'); - $result = $conn->exec($cmd); - print ""; - for ($i = 0; $i < $result->ntuples; $i++) { - print ""; - for ($j = 0; $j < $result->nfields; $j++) { - print ""; + my $conninfo = $query->param('conninfo'); + my $conn = Pg::connectdb($conninfo); + if ($conn->status == PGRES_CONNECTION_OK) { + my $cmd = $query->param('cmd'); + my $result = $conn->exec($cmd); + print "

", $result->getvalue($i, $j), "
\n"; + my @row; + while (@row = $result->fetchrow) { + print "\n"; } - print ""; + print "
", join("", @row), "

\n"; + } else { + print "

Connect to database failed

\n"; } - print ""; } print $query->end_html; diff --git a/src/interfaces/perl5/eg/example.newstyle b/src/interfaces/perl5/eg/example.newstyle index 04d2964df7..8b80e94b38 100644 --- a/src/interfaces/perl5/eg/example.newstyle +++ b/src/interfaces/perl5/eg/example.newstyle @@ -2,7 +2,7 @@ #------------------------------------------------------- # -# $Id: example.newstyle,v 1.2 1997/09/25 21:15:02 mergl Exp $ +# $Id: example.newstyle,v 1.3 1998/02/20 21:26:06 mergl Exp $ # # Copyright (c) 1997 Edmund Mergl # @@ -13,7 +13,7 @@ ######################### We start with some black magic to print on failure. -BEGIN { $| = 1; print "1..61\n"; } +BEGIN { $| = 1; print "1..57\n"; } END {print "not ok 1\n" unless $loaded;} use Pg; $loaded = 1; @@ -23,6 +23,7 @@ print "ok 1\n"; $dbmain = 'template1'; $dbname = 'pgperltest'; +$dbhost = 'localhost'; $trace = '/tmp/pgtrace.out'; $cnt = 2; $DEBUG = 0; # set this to 1 for traces @@ -88,7 +89,7 @@ $SIG{PIPE} = sub { print "broken pipe\n" }; ######################### create and connect to test database # 2-4 -$conn = Pg::connectdb("dbname=$dbmain"); +$conn = Pg::connectdb("dbname=$dbmain host=$dbhost"); cmp_eq(PGRES_CONNECTION_OK, $conn->status); # might fail if $dbname doesn't exist => don't check resultStatus @@ -97,7 +98,7 @@ $result = $conn->exec("DROP DATABASE $dbname"); $result = $conn->exec("CREATE DATABASE $dbname"); cmp_eq(PGRES_COMMAND_OK, $result->resultStatus); -$conn = Pg::connectdb("dbname=$dbname"); +$conn = Pg::connectdb("dbname=$dbname host=$dbhost"); cmp_eq(PGRES_CONNECTION_OK, $conn->status); ######################### debug, PQtrace @@ -200,17 +201,14 @@ for ($k = 0; $k < $result->nfields; $k++) { cmp_eq($k, $fnumber); } -for ($k = 0; $k < $result->ntuples; $k++) { - $string = ""; - for ($l = 0; $l < $result->nfields; $l++) { - $string .= $result->getvalue($k, $l) . " "; - } - $i = $k + 1; - cmp_eq("$i Edmund Mergl ", $string); +$string = ""; +while (@row = $result->fetchrow) { + $string = join(" ", @row); } +cmp_eq("5 Edmund Mergl", $string); ######################### PQnotifies -# 49-51 +# 44-47 if (! defined($pid = fork)) { die "can not fork: $!"; @@ -218,7 +216,7 @@ if (! defined($pid = fork)) { # i'm the child sleep 2; bless $conn; - $conn = Pg::connectdb("dbname=$dbname"); + $conn = Pg::connectdb("dbname=$dbname host=$dbhost"); $result = $conn->exec("NOTIFY person"); exit; } @@ -236,7 +234,7 @@ while (1) { cmp_eq("person", $table); ######################### PQprint -# 52-53 +# 48-49 $result = $conn->exec("SELECT name FROM person WHERE id = 2"); cmp_eq(PGRES_TUPLES_OK, $result->resultStatus); @@ -246,7 +244,7 @@ $result->print(PRINT, 0, 0, 0, 0, 1, 0, " ", "", "", "myName"); close(PRINT) || die "bad PRINT: $!"; ######################### PQlo_import, PQlo_export, PQlo_unlink -# 54-59 +# 50-55 $filename = 'ApachePg.pl'; $cwd = `pwd`; @@ -276,9 +274,9 @@ if ($DEBUG) { } ######################### disconnect and drop test database -# 60-61 +# 56-57 -$conn = Pg::connectdb("dbname=$dbmain"); +$conn = Pg::connectdb("dbname=$dbmain host=$dbhost"); cmp_eq(PGRES_CONNECTION_OK, $conn->status); $result = $conn->exec("DROP DATABASE $dbname"); diff --git a/src/interfaces/perl5/eg/example.oldstyle b/src/interfaces/perl5/eg/example.oldstyle index 7f0f46b6f2..6c537af1b8 100644 --- a/src/interfaces/perl5/eg/example.oldstyle +++ b/src/interfaces/perl5/eg/example.oldstyle @@ -2,7 +2,7 @@ #------------------------------------------------------- # -# $Id: example.oldstyle,v 1.2 1997/09/25 21:15:04 mergl Exp $ +# $Id: example.oldstyle,v 1.3 1998/02/20 21:26:08 mergl Exp $ # # Copyright (c) 1997 Edmund Mergl # @@ -23,6 +23,7 @@ print "ok 1\n"; $dbmain = 'template1'; $dbname = 'pgperltest'; +$dbhost = 'localhost'; $trace = '/tmp/pgtrace.out'; $cnt = 2; $DEBUG = 0; # set this to 1 for traces @@ -88,7 +89,7 @@ $SIG{PIPE} = sub { print "broken pipe\n" }; ######################### create and connect to test database # 2-4 -$conn = PQsetdb('', '', '', '', $dbmain); +$conn = PQsetdb($dbhost, '', '', '', $dbmain); cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn)); # might fail if $dbname doesn't exist => don't check resultStatus @@ -101,7 +102,7 @@ PQclear($result); PQfinish($conn); -$conn = PQsetdb('', '', '', '', $dbname); +$conn = PQsetdb($dbhost, '', '', '', $dbname); cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn)); ######################### debug, PQtrace @@ -230,7 +231,7 @@ if (! defined($pid = fork)) { } elsif (! $pid) { # i'm the child sleep 2; - $conn = PQsetdb('', '', '', '', $dbname); + $conn = PQsetdb($dbhost, '', '', '', $dbname); $result = PQexec($conn, "NOTIFY person"); PQclear($result); PQfinish($conn); @@ -299,7 +300,7 @@ if ($DEBUG) { PQfinish($conn); -$conn = PQsetdb('', '', '', '', $dbmain); +$conn = PQsetdb($dbhost, '', '', '', $dbmain); cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn)); $result = PQexec($conn, "DROP DATABASE $dbname"); -- 2.11.0