Thanks for the help Carl and Craig. I tried using placeholders as
Carl suggested, however I still get the same error:
At 2:05 pm +0100 16/3/01, Carl K. Cunningham wrote:
> > DBD::Pg::db do failed: ERROR: Unterminated quoted string
>> Database handle destroyed without explicit disconnect.
>> which seems to be to do with the serialized data, which seems to
>> contain return characters. Is there a way around this?
>
>Use placeholders, they make life _much_ easier. Try this:
>
>$sth = $dbhandle->prepare( "INSERT INTO $table (name, dwarf_list,
>occupations) VALUES(?, ?, ?)" );
>
>$sth->execute($name, $dwarves_str, $occupations_str) ;
This is the script:
#!/usr/bin/perl -w
use strict;
use Storable qw(nfreeze thaw);
use DBI;
use Fcntl;
my $uid = 'training';
my $db_name = 'test';
my $table = 'data_sets';
my $pass = '';
my $data_source = "dbi:Pg:dbname=$db_name";
my ($name, @dwarves, @jobs, %occupations);
my ($dbhandle, $returnvalue, $str, $cursor, @items, );
$name = 'set_1';
@dwarves = qw(Happy Grumpy Dopey Doc);
%occupations = ( Happy => 'Entertainer',
Grumpy=> 'Worker',
Dopey => 'Lecturer',
Doc => 'Manager' );
# freeze arrays and hashes to strings
my $dwarves_str = nfreeze \@dwarves;
my $occupations_str = nfreeze \%occupations;
$dbhandle = DBI->connect( $data_source, $uid, $pass, {
PrintError => 0,
RaiseError => 0,
AutoCommit => 0
});
unless ( defined($dbhandle) ) { warn_and_exit("DBI->connect failed:
$DBI::errstr\n"); }
$dbhandle->do("CREATE TABLE data_sets (name CHAR(10), dwarf_list
CHAR(100), occupations CHAR(200))");
$cursor = $dbhandle->prepare( q{INSERT INTO data_sets (name,
dwarf_list, occupations) VALUES(?, ?, ?)} ) || die $dbhandle->errstr;
$cursor->execute($name, $dwarves_str, $occupations_str) || die
$dbhandle->errstr;
$dbhandle->commit || die $dbhandle->errstr;
$dbhandle->disconnect;
exit 1;
__END__
and this is the error:
ERROR: Unterminated quoted string
Database handle destroyed without explicit disconnect.
I'm sorry, I realise this is drifting off topic, but I don't know
where else to turn. I've read everything I could find on the topic
and am still stuck.
By the way, does anyone know whether the O'Reilly DBI book by
Aligator Descartes addresses this sort of issue?
--
My brain hurts!
SeanC
Mediatek Training Institute
26 Crart Ave., Berea, Durban, South Africa
<-- New Address
phone: +27 (0)31 202 1886 [EMAIL PROTECTED] <--
New Phone Number
fax: +27 (0)31 202 1767
<-- New Fax Number
<http://members.nbci.com/s_carte/>