zby has asked for the wisdom of the Perl Monks concerning the following question:

Does anybody know why I get this error:
DBD::ODBC::st execute failed: [IBM][Client Access Express ODBC Driver +(32-bit)][DB2/400 SQL]Data truncated. (SQL-01004)(DBD: st_execute/SQL +Execute err=-1) at a.pl line 33.
with following code:
use Data::Dumper; use DBI; use strict; my $dbh = DBI->connect('dbi:ODBC:MID', 'midadmin', '*******') or die " +Nie moge sie polaczyc: $!" ; =pod $dbh->{LongTruncOk} = 1; $dbh->{LongReadLen} = 1024; DBI->trace(5); =cut my @kolumny = qw( MIDDELETIONFLAG UMREN MEINH UMREZ LAENG BREIT NOEHE VOLUM VOLEH BRGEW +GEWEI MESUB SYSTEM_ID LEGACY_ID MAKT_MAKTX_PL MAS_IADSC DUP_CHK MAS_I +APACS MARM_MEINS MAS_IANPAL ); my @vals = ("S", "1", "PAL", "1152", "", "", "00337", "1200", "800", " +972", "MM", "933120", "CM3", "313", "KG", "CS", "PLNCPL", "00337", "P +LNCPL", "00337PAL", ); my $cols = join ', ', 'MIDID', @kolumny; my $placeh = join ', ', map {'?'} 'MIDID', @kolumny; my $statement = "INSERT into middbexp.marmtest ($cols) values ($placeh +)"; print $statement, "\n"; my $sth = $dbh->prepare($statement); print "\n\n"; $sth->bind_param(1, 2, 4); for my $nrcol (1 .. $#kolumny + 1){ print "$nrcol, $kolumny[$nrcol - 1], $vals[$nrcol - 1]\n"; $sth->bind_param($nrcol + 1, $vals[$nrcol]); } my $rv = $sth->execute(); print "$rv\n";
Setting the 'Longxxxxx' parameters did not help anything (anyway this is INSERT so this should not apply here). The debugging output:
INSERT into middbexp.marmtest (MIDID, MIDDELETIONFLAG, UMREN, MEINH, U +MREZ, LAENG, BREIT, NOEHE, VOLUM, VOLEH, BRGEW, GEWEI, MESUB, SYSTEM_ +ID, LEGACY_ID, MAKT_MAKTX_PL, MAS_IADSC, DUP_CHK, MAS_IAPACS, MARM_ME +INS, MAS_IANPAL) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?) 1, MIDDELETIONFLAG, S 2, UMREN, 1 3, MEINH, PAL 4, UMREZ, 1152 5, LAENG, 6, BREIT, 7, NOEHE, 00337 8, VOLUM, 1200 9, VOLEH, 800 10, BRGEW, 972 11, GEWEI, MM 12, MESUB, 933120 13, SYSTEM_ID, CM3 14, LEGACY_ID, 313 15, MAKT_MAKTX_PL, KG 16, MAS_IADSC, CS 17, DUP_CHK, PLNCPL 18, MAS_IAPACS, 00337 19, MARM_MEINS, PLNCPL 20, MAS_IANPAL, 00337PAL

Replies are listed 'Best First'.
Re: 'Data truncated' error when INSERTING (DBI)
by ScooterQ (Pilgrim) on Jul 16, 2003 at 19:49 UTC
    What is the data type of the column you are trying to insert data into? Can it handle the length? Are you sure?

    By the way, I had to search a bit to figure out which line was line 33. In the future you might want to highlight the line referenced in the error.

      Thanks a lot to you all.
Re: 'Data truncated' error when INSERTING (DBI)
by cfreak (Chaplain) on Jul 16, 2003 at 19:50 UTC

    My guess would be that you're trying to insert some data that is larger than the field you are trying to put it into, whenever it has happened to me it truncates it and doesn't die, however that may not be true for your database.

    Lobster Aliens Are attacking the world!
Re: 'Data truncated' error when INSERTING (DBI)
by sgifford (Prior) on Jul 16, 2003 at 20:19 UTC
    That error message is coming from your database, not from Perl; Perl is just relaying the message to you. Looking at your database documentation may give you more information about what exactly this error means and what can cause it.