Alessio

Thank you for your reply - I'm trying to insert data with up to 4000 
characters in a single column.

Can you have columns defined to allow 4000 characters? More to the point, 
can you insert data into them with DBI::Pg?

The code that produces an error looks like this (trimmed to the bare 
minimum) - the error I have returned for every row (which may or may not be 
relevant) is:

        DBD::Pg::st execute failed: PQsendQuery() -- There is no connection to the 
backend.

----
#!/usr/bin/perl

use strict;
use DBI qw (:sql_types);

my $table= "tblTable";
my $database = 'dbi:Pg:dbname=part';
my $user = 'sa';
my $pass = '';
my $dbh = DBI->connect($database, $user, $pass);
$dbh->{RaiseError} = 1;
$dbh->{LongReadLen} = 4000;
$dbh->{LongTruncOk} = 1;
print "Can't connect to database" unless defined $dbh;

&insert;

$dbh->disconnect();


sub insert
{
        my $filein = "webdata/tblTable.txt"; # on web site
        @ARGV = $filein;
        $_ = <>;
        chomp;
        s/\t/,/g;
        my @column = split ',', $_;
        my $insert_sql = "INSERT INTO tblTable (".join(', ', @column).") VALUES 
(".join(', ', map {'?'} @column).")";
        
        ### This is where I'd like to put the bind parameter so that it will 
insert data of up to 4000 characters
        my $insert_sth->bind_param(5, 'Introduction', SQL_LONGVARCHAR);
        while (<>)
        {
                chomp;
                my @value = split "\t", $_;
                eval { $insert_sth->execute(@value) };
                print "\nINSERT failed:\n$@\n" if $@;
        }
}

----
Ian

Reply via email to