Hi,

I'm having a problem trying to retrieve a value from a field set as varbinary(MAX) on an MS SQL 2005 backend through DBIx::Simple.

Now I'm not big on DBI but am figuring bits out. I found that inserting and retrieving data worked find if the back was set to varbinary(8000) but since the data would likely exceed 8k varbinary(MAX) was required at which point SELECTs would fail.

I've discovered how to use the LongTruncOk & LongReadLen attributes and these have got me a bit further, I can now retrieve data but the problem I'm having now is that the data always seems to truncate to 1 character.

Can anyone help me retrieve data correctly from a varbinary(MAX)?

On the backend there is a table t_test containing :

Simplified example :

#!perl use strict; use Error qw(:try); use DBIx::Simple; use Sys::Hostname; use DBI; my $dsnString='dbi:ODBC:Driver={SQL Native Client};Server='.hostname.' +;Database=db_simon;Trusted_Connection=yes;'; my $dbh =DBIx::Simple->connect($dsnString,,) || throw Error::Simple("U +nable to connect to Database using DSN String \"".$dsnString."\"."); $dbh->{'dbh'}->{'AutoCommit'} = 0; $dbh->{'dbh'}->{'RowCacheSize'} = 0; $dbh->{'dbh'}->{'LongTruncOk'} = 1; $dbh->{'dbh'}->{'LongReadLen'} = 50000; # actual for varbinary(MAX) = +2147483647 #$dbh->{'dbh'}->{'RaiseError'} = 1; # insert some data my $data = "x" x 1000; $dbh->query('INSERT INTO t_test (c_data) VALUES (?)', $data) or die $d +bh->error; # and retrieve my $results = $dbh->query('SELECT c_id,c_data FROM t_test')->hashes or + die $dbh->error; foreach my $result(@{$results}) { print $result->{'c_id'}."-".substr($result->{'c_data'},0,10)."... +(".length($result->{'c_data'})." chars returned)\n"; } $dbh->disconnect;

Thanks all.

In reply to dbix::simple & varbinary(MAX) by Lyndley

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.