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

In reply to 'Data truncated' error when INSERTING (DBI) by zby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.