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

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

From
Jeff Self
Date:
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
connectionnot 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



Re: Is there something wrong with Perl`s dbi and PostgreSQL?

From
greg@turnstep.com
Date:
-----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@turnstep.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-----