Is there something wrong with Perl's dbi and PostgreSQL?

Lists: pgsql-sql
From: Jeff Self <jself(at)nngov(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Is there something wrong with Perl's dbi and PostgreSQL?
Date: 2003-09-29 17:51:56
Message-ID: 1064857916.27970.18.camel@jselfpc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

I just tried running a perl script that I wrote about a year ago. It had
worked for me in the past. Now it doesn't work. I can view data from a
table, but I am unable to either drop a table or create a table. I'm
running PostgreSQL 7.3.4 and DBI 1.35 along with Perl 5.8.1.

Here's my script for creating a table:
#!/usr/bin/perl -w
# createfoo.pl

use strict;
use DBI;

my $dbh = DBI->connect( 'dbi:Pg:dbname=test','dbuser','password',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made:
$DBI::errstr";

my $query = $dbh->prepare(
"CREATE TABLE foo (foo_id INT4," .
"foo_name TEXT)"
);
$query->execute();
$dbh->disconnect();

Has anything changed to DBI? I haven't found anything on google
suggesting that it has.

--
Jeff Self
Dept. of Information Technology
City of Newport News
(757)926-3741


From: greg(at)turnstep(dot)com
To: pgsql-sql(at)postgresql(dot)org
Cc: jself(at)nngov(dot)com
Subject: Re: Is there something wrong with Perl`s dbi and PostgreSQL?
Date: 2003-09-29 18:45:20
Message-ID: a12bbba041a8725c804b028dcc3b0894@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> I just tried running a perl script that I wrote about a year ago. It had
> worked for me in the past. Now it doesn't work.

You have AutoCommit set to off, and never commit the transaction. Therefore,
the table creation is rolled back. Add a

$dbh->commit()

after your execute line and it should work as expected.

Also note that your "die" on connect will not work because you have RaiseError
set: Leave it off for the connect, then turn it on again immediately via:

$dbh->{RaiseError}=1;

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200309291445

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iD8DBQE/eH4AvJuQZxSWSsgRAgkVAJ46YX5iJ1+pbeJOQ6RJYId/6yhOWQCeKy7R
doP2RZN1y353MT+c4KdYywA=
=KUHS
-----END PGP SIGNATURE-----