I have a script that I copied from one directory to another and modified it to handle some slightly different data, but now it doesn't work. It will allow me to upload a 4K gif, but when I try to upload a 13K jpeg, I can prepare, but not execute, the SQL. Here's a minimal test case:
sub updateFlyer { my $contentType = shift; use DBI qw(:sql_types); my ( $sql, $sth, $dbh, $mimeType, $contentImage ); # Database connection $dbh = DBI->connect("dbi:ODBC:something", 'something', 'somepass', + {RaiseError => 1}) or die DBI->errstr; # Debug stuff if (1) { DBI->trace(2, "trace.txt"); } ( $mimeType, $contentImage ) = uploadImage( $query ); $sql = "UPDATE interface..CustomContent " . "SET contentImage = ?," . " contentImageType = ? ". "WHERE contentType = ?"; $sth = $dbh->prepare( $sql ); # Gotta bind the image $sth->bind_param( 1, $contentImage, SQL_LONGVARBINARY ); $sth->execute ( $contentImage, $mimeType, $contentType ); $sth->finish; $dbh->disconnect; }
The error message is:
DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver][SQL +Server]String or binary data would be truncated. (SQL-22001) [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been +terminated. (SQL-01000)(DBD: st_execute/SQLExecute err=-1) at D:\some +path\cgi-bin\somescript.cgi line 447.
Digging further, I ran a trace with both this script and the working original (I cannot find a significant difference in how they are written) using the same 13K jpeg. The only difference I can see is the following information buried in the trace text:
Failed upload: (size 12723/12724/0, ptype 4, otype 1) Good upload: (size 12723/12724/12723, ptype 4, otype 1)
I'm sure that zero is the source of the problem, but I have no idea what it means.

We're using NT 4.0, service pack six with IIS and MS SQL Server 7.0. The two scripts are writing to separate tables and I have verified that the field is defined the same way in both tables.

Barring anyone having seen this problem before, can you point me to where I can get information on deciphering the DBI->trace() method's output?

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.


In reply to DBI Problem - binding variables by Ovid

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.