VERSIONS: AIX=v5.3.7.0, DB2=v9.1.0.6, Perl=v5.8.8, DBD::DB2.pm v1.78

I am trying to update a DB2 table using a PREPARED statement with placeholders that has a where clause containing 1xCHAR column and 4xINTEGER columns. I cannot get past the fatal error msg "CLI0112E Error in assignment".

By process of elimination I have determined that is it definitely the integer values that are causing the problem. If I hard-code some integer values into the execute() statement the update works. If I build a new SQL statement for each iteration and use $dbh->do($upd_sql_stmt) that works too.

However with hundreds, and potentially thousands, of updates to do per file processed it would be far more efficient to be able to execute a pre-prepared statement with place holders than do an implicit prepare/execute for each loop.

The integer values to be plugged into the update sql are extracted from a Base36 encoded numeric string. However when used in placeholders the DBI/DB2 module just refuses to accept them as integer values instead of strings and thus the update aborts.

So far I have tried, individually and collectively, the following strategies to "force" the interpretation of the numeric variable values are integers:

my $update_idx1 = "update root.$current_table set UUID = ?" . "where DOC_NAME = ? " . "and DOC_OFF = ? and DOC_LEN = ? " . "and COMP_OFF = ? and COMP_LEN = ?"; my $upd_idx1 = $dbh->prepare($update_idx1) or die "Cannot prepare upd_idx1: $dbh->errstr"; my ($comp_off, $comp_len, $doc_off, $doc_len) = (0, 0, 0, 0); my @array = map { Base36::decode_base36($_) + 0 } ($enc_comp_off, $enc_comp_len, $enc_doc_off, $enc_doc_len); $comp_off=($array[0] / 1); $comp_len=($array[1] / 1); $doc_off =($array[2] / 1); $doc_len =($array[3] / 1); $upd_idx1->bind_param(1, $uuid) or die "Bind failed for UUID: $dbh->errstr"; $upd_idx1->bind_param(2, $doc_name) or die "Bind failed for doc_name: $dbh->errstr"; $upd_idx1->bind_param(3, int($doc_off), { TYPE => SQL_INTEGER }) or die "Bind failed for doc_off: $dbh->errstr"; $upd_idx1->bind_param(4, int($doc_len), { TYPE => SQL_INTEGER }) or die "Bind failed for doc_len: $dbh->errstr"; $upd_idx1->bind_param(5, int($comp_off), { TYPE => SQL_INTEGER }) or die "Bind failed for comp_off: $dbh->errstr"; $upd_idx1->bind_param(6, int($comp_len), { TYPE => SQL_INTEGER }) or die "Bind failed for comp_len: $dbh->errstr"; my $row_count = $upd_idx1->execute();

Since the API seems determined to interpret the passed numeric value as a string I have also tried changing the SQL to use the CHAR() function thus:

 "CHAR(DOC_OFF) = ?"

for each of the integer fields. This at least prevents a fatal error, but it also results in no rows being found to update (Yes, I tried this WITHOUT doing the bind as INTEGER!).

So no matter what combination of some or all of these strategies (add ZERO, divide by ONE, use INT function on variable, bind as TYPE SQL_INTEGER) to try and force values to be interpreted as integers, the execute() statement still fails with "Error in assignment" on the integer values.

Is there a solution to this problem, or is it just a "feature" of the DBD::DB2 module that you cannot use integers in placeholders?


In reply to DBI Placeholders and DB2 Integers by Anonymous Monk

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.