mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-02 01:41:16 +02:00
1.7.01.7.0
This commit is contained in:
parent
30b9b529f3
commit
734328840c
@ -1,44 +1,48 @@
|
|||||||
#!/usr/local/bin/perl
|
#!/usr/local/bin/perl
|
||||||
|
|
||||||
# demo script, tested with:
|
# demo script, tested with:
|
||||||
# - PostgreSQL-6.2
|
# - PostgreSQL-6.3
|
||||||
# - apache_1.2.4
|
# - apache_1.3
|
||||||
# - mod_perl-1.00
|
# - mod_perl-1.08
|
||||||
# - perl5.004_03
|
# - perl5.004_04
|
||||||
|
|
||||||
use CGI;
|
use CGI;
|
||||||
use Pg;
|
use Pg;
|
||||||
|
use strict;
|
||||||
|
|
||||||
$query = new CGI;
|
my $query = new CGI;
|
||||||
|
|
||||||
print $query->header,
|
print $query->header,
|
||||||
$query->start_html(-title=>'A Simple Example'),
|
$query->start_html(-title=>'A Simple Example'),
|
||||||
$query->startform,
|
$query->startform,
|
||||||
"<CENTER><H3>Testing Module Pg</H3></CENTER>",
|
"<CENTER><H3>Testing Module Pg</H3></CENTER>",
|
||||||
"Enter database name: ",
|
"<P><CENTER><TABLE CELLPADDING=4 CELLSPACING=2 BORDER=1>",
|
||||||
$query->textfield(-name=>'dbname'),
|
"<TR><TD>Enter conninfo string: </TD>",
|
||||||
"<P>",
|
"<TD>", $query->textfield(-name=>'conninfo', -size=>40, -default=>'dbname=template1 host=localhost'), "</TD>",
|
||||||
"Enter select command: ",
|
"</TR>",
|
||||||
$query->textfield(-name=>'cmd', -size=>40),
|
"<TR><TD>Enter select command: </TD>",
|
||||||
"<P>",
|
"<TD>", $query->textfield(-name=>'cmd', -size=>40), "</TD>",
|
||||||
$query->submit(-value=>'Submit'),
|
"</TR>",
|
||||||
|
"</TABLE></CENTER><P>",
|
||||||
|
"<CENTER>", $query->submit(-value=>'Submit'), "</CENTER>",
|
||||||
$query->endform;
|
$query->endform;
|
||||||
|
|
||||||
if ($query->param) {
|
if ($query->param) {
|
||||||
|
|
||||||
$dbname = $query->param('dbname');
|
my $conninfo = $query->param('conninfo');
|
||||||
$conn = Pg::connectdb("dbname = $dbname");
|
my $conn = Pg::connectdb($conninfo);
|
||||||
$cmd = $query->param('cmd');
|
if ($conn->status == PGRES_CONNECTION_OK) {
|
||||||
$result = $conn->exec($cmd);
|
my $cmd = $query->param('cmd');
|
||||||
print "<TABLE>";
|
my $result = $conn->exec($cmd);
|
||||||
for ($i = 0; $i < $result->ntuples; $i++) {
|
print "<P><CENTER><TABLE CELLPADDING=4 CELLSPACING=2 BORDER=1>\n";
|
||||||
print "<TR>";
|
my @row;
|
||||||
for ($j = 0; $j < $result->nfields; $j++) {
|
while (@row = $result->fetchrow) {
|
||||||
print "<TD>", $result->getvalue($i, $j), "</TD>";
|
print "<TR><TD>", join("</TD><TD>", @row), "</TD></TR>\n";
|
||||||
}
|
}
|
||||||
print "</TR>";
|
print "</TABLE></CENTER><P>\n";
|
||||||
|
} else {
|
||||||
|
print "<CENTER><H2>Connect to database failed</H2></CENTER>\n";
|
||||||
}
|
}
|
||||||
print "</TABLE>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print $query->end_html;
|
print $query->end_html;
|
||||||
|
@ -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
|
# Copyright (c) 1997 Edmund Mergl
|
||||||
#
|
#
|
||||||
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
######################### We start with some black magic to print on failure.
|
######################### 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;}
|
END {print "not ok 1\n" unless $loaded;}
|
||||||
use Pg;
|
use Pg;
|
||||||
$loaded = 1;
|
$loaded = 1;
|
||||||
@ -23,6 +23,7 @@ print "ok 1\n";
|
|||||||
|
|
||||||
$dbmain = 'template1';
|
$dbmain = 'template1';
|
||||||
$dbname = 'pgperltest';
|
$dbname = 'pgperltest';
|
||||||
|
$dbhost = 'localhost';
|
||||||
$trace = '/tmp/pgtrace.out';
|
$trace = '/tmp/pgtrace.out';
|
||||||
$cnt = 2;
|
$cnt = 2;
|
||||||
$DEBUG = 0; # set this to 1 for traces
|
$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
|
######################### create and connect to test database
|
||||||
# 2-4
|
# 2-4
|
||||||
|
|
||||||
$conn = Pg::connectdb("dbname=$dbmain");
|
$conn = Pg::connectdb("dbname=$dbmain host=$dbhost");
|
||||||
cmp_eq(PGRES_CONNECTION_OK, $conn->status);
|
cmp_eq(PGRES_CONNECTION_OK, $conn->status);
|
||||||
|
|
||||||
# might fail if $dbname doesn't exist => don't check resultStatus
|
# 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");
|
$result = $conn->exec("CREATE DATABASE $dbname");
|
||||||
cmp_eq(PGRES_COMMAND_OK, $result->resultStatus);
|
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);
|
cmp_eq(PGRES_CONNECTION_OK, $conn->status);
|
||||||
|
|
||||||
######################### debug, PQtrace
|
######################### debug, PQtrace
|
||||||
@ -200,17 +201,14 @@ for ($k = 0; $k < $result->nfields; $k++) {
|
|||||||
cmp_eq($k, $fnumber);
|
cmp_eq($k, $fnumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($k = 0; $k < $result->ntuples; $k++) {
|
$string = "";
|
||||||
$string = "";
|
while (@row = $result->fetchrow) {
|
||||||
for ($l = 0; $l < $result->nfields; $l++) {
|
$string = join(" ", @row);
|
||||||
$string .= $result->getvalue($k, $l) . " ";
|
|
||||||
}
|
|
||||||
$i = $k + 1;
|
|
||||||
cmp_eq("$i Edmund Mergl ", $string);
|
|
||||||
}
|
}
|
||||||
|
cmp_eq("5 Edmund Mergl", $string);
|
||||||
|
|
||||||
######################### PQnotifies
|
######################### PQnotifies
|
||||||
# 49-51
|
# 44-47
|
||||||
|
|
||||||
if (! defined($pid = fork)) {
|
if (! defined($pid = fork)) {
|
||||||
die "can not fork: $!";
|
die "can not fork: $!";
|
||||||
@ -218,7 +216,7 @@ if (! defined($pid = fork)) {
|
|||||||
# i'm the child
|
# i'm the child
|
||||||
sleep 2;
|
sleep 2;
|
||||||
bless $conn;
|
bless $conn;
|
||||||
$conn = Pg::connectdb("dbname=$dbname");
|
$conn = Pg::connectdb("dbname=$dbname host=$dbhost");
|
||||||
$result = $conn->exec("NOTIFY person");
|
$result = $conn->exec("NOTIFY person");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -236,7 +234,7 @@ while (1) {
|
|||||||
cmp_eq("person", $table);
|
cmp_eq("person", $table);
|
||||||
|
|
||||||
######################### PQprint
|
######################### PQprint
|
||||||
# 52-53
|
# 48-49
|
||||||
|
|
||||||
$result = $conn->exec("SELECT name FROM person WHERE id = 2");
|
$result = $conn->exec("SELECT name FROM person WHERE id = 2");
|
||||||
cmp_eq(PGRES_TUPLES_OK, $result->resultStatus);
|
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: $!";
|
close(PRINT) || die "bad PRINT: $!";
|
||||||
|
|
||||||
######################### PQlo_import, PQlo_export, PQlo_unlink
|
######################### PQlo_import, PQlo_export, PQlo_unlink
|
||||||
# 54-59
|
# 50-55
|
||||||
|
|
||||||
$filename = 'ApachePg.pl';
|
$filename = 'ApachePg.pl';
|
||||||
$cwd = `pwd`;
|
$cwd = `pwd`;
|
||||||
@ -276,9 +274,9 @@ if ($DEBUG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
######################### disconnect and drop test database
|
######################### 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);
|
cmp_eq(PGRES_CONNECTION_OK, $conn->status);
|
||||||
|
|
||||||
$result = $conn->exec("DROP DATABASE $dbname");
|
$result = $conn->exec("DROP DATABASE $dbname");
|
||||||
|
@ -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
|
# Copyright (c) 1997 Edmund Mergl
|
||||||
#
|
#
|
||||||
@ -23,6 +23,7 @@ print "ok 1\n";
|
|||||||
|
|
||||||
$dbmain = 'template1';
|
$dbmain = 'template1';
|
||||||
$dbname = 'pgperltest';
|
$dbname = 'pgperltest';
|
||||||
|
$dbhost = 'localhost';
|
||||||
$trace = '/tmp/pgtrace.out';
|
$trace = '/tmp/pgtrace.out';
|
||||||
$cnt = 2;
|
$cnt = 2;
|
||||||
$DEBUG = 0; # set this to 1 for traces
|
$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
|
######################### create and connect to test database
|
||||||
# 2-4
|
# 2-4
|
||||||
|
|
||||||
$conn = PQsetdb('', '', '', '', $dbmain);
|
$conn = PQsetdb($dbhost, '', '', '', $dbmain);
|
||||||
cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn));
|
cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn));
|
||||||
|
|
||||||
# might fail if $dbname doesn't exist => don't check resultStatus
|
# might fail if $dbname doesn't exist => don't check resultStatus
|
||||||
@ -101,7 +102,7 @@ PQclear($result);
|
|||||||
|
|
||||||
PQfinish($conn);
|
PQfinish($conn);
|
||||||
|
|
||||||
$conn = PQsetdb('', '', '', '', $dbname);
|
$conn = PQsetdb($dbhost, '', '', '', $dbname);
|
||||||
cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn));
|
cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn));
|
||||||
|
|
||||||
######################### debug, PQtrace
|
######################### debug, PQtrace
|
||||||
@ -230,7 +231,7 @@ if (! defined($pid = fork)) {
|
|||||||
} elsif (! $pid) {
|
} elsif (! $pid) {
|
||||||
# i'm the child
|
# i'm the child
|
||||||
sleep 2;
|
sleep 2;
|
||||||
$conn = PQsetdb('', '', '', '', $dbname);
|
$conn = PQsetdb($dbhost, '', '', '', $dbname);
|
||||||
$result = PQexec($conn, "NOTIFY person");
|
$result = PQexec($conn, "NOTIFY person");
|
||||||
PQclear($result);
|
PQclear($result);
|
||||||
PQfinish($conn);
|
PQfinish($conn);
|
||||||
@ -299,7 +300,7 @@ if ($DEBUG) {
|
|||||||
|
|
||||||
PQfinish($conn);
|
PQfinish($conn);
|
||||||
|
|
||||||
$conn = PQsetdb('', '', '', '', $dbmain);
|
$conn = PQsetdb($dbhost, '', '', '', $dbmain);
|
||||||
cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn));
|
cmp_eq(PGRES_CONNECTION_OK, PQstatus($conn));
|
||||||
|
|
||||||
$result = PQexec($conn, "DROP DATABASE $dbname");
|
$result = PQexec($conn, "DROP DATABASE $dbname");
|
||||||
|
Loading…
Reference in New Issue
Block a user