Thread: Inserting null values from Perl DBI

Inserting null values from Perl DBI

From
"David Martínez Cuevas"
Date:
Hi.

I've been dealing with perl, dbi and postgres, but i'm having troubles
while inserting null values.

This is what i'm doing like:

##################################################
$conn_seq = DBI->connect("dbi:Pg:dbname=$bd",'','') or finaliza(
$DBI::errstr);
$conn = DBI->connect("dbi:Pg:dbname=$bd",'','', {AutoCommit => 0}) or
finaliza( $DBI::errstr);
$educacion_ready = $conn->prepare(q{
           insert into educacion (educacion,nombre,
                                 duracion,fecha,
                                 asistentes,constancias,
                                 dependencia,modalidad,
                                 sede,diplomado,
                                 modulos,depponente)
        values (?,?,?,?,?,?,?,?,?,?,?,?)}) or finaliza( $DBI::errstr);
.......

while(<IN_FILE>) {
.......
     # here, i take values from many files. Basically, i need to prevent

     # from bad typing of users. When certain conditions becomes true,
     # i should insert null values into this loop:

    $get_seq = $conn_seq->prepare("select nextval('seq_educacion')") or
finaliza( $DBI::errstr);
    $get_seq->execute;
    $nextval = ($get_seq->fetchrow)[0];
    $educacion_ready->execute($nextval,$nombre,$duracion,$fecha,
                    $asistentes,$constancias,$cve_dep,$modalidad,
                    $sede,$diplomado,$modulos,$depponente) or finaliza(
$DBI::errstr);
}

$conn->commit || finaliza($conn->errstr);
###########################################################

But when placeholders must take a 'null' value, they doesn't work.
I've already tried to fix it using 'undef' values, but i get the same
error:

DBD::Pg::st execute failed: ERROR:  attribute undef not found

What can i do ??

NOTE: Please e-mail-me directly... i'm not suscribed to interfaces
mailing list
Thank you.

                                        David Martínez Cuevas
                                     david@estadistica.unam.mx