Question : DBI DBD::ODBC Errors Truncating SQL Server Text Fields

This is driving me crazy and hope someone can help....
My SQLServer db has text(16) fields in it - I guess the equivalent of MS-Access Memo fields. When I try to retrieve data, I get the following:

DBD::ODBC::st fetchall_arrayref failed: [Microsoft][ODBC SQL Server Driver]String data, right truncation (SQL-01004)(DBD: st_fetch/SQLFetch (long truncated DBI attribute LongTruncOk not set and/or LongReadLen too small) err=-1)

I found references to LongTruncOk and LongReadLen in some of the dbi files - but I don't really knwo what I'm doing enough to start modifying....

Answer : DBI DBD::ODBC Errors Truncating SQL Server Text Fields

LongReadLen is an attribute of your database handle. You can set it in the connect string:

      my $db = DBI->connect('connectstring', 'user','password', { LongReadLen => 1000000, LongTruncOk => 1 });

or on the handle itself:

      $db->{LongReadLen} = 1000000;
      $db->{LongTruncOk} = 1;

Note that if you want to _store_ values in a text field, you will have to do more work. You must bind the variable that contains the text to the right parameter in the sql statement:

      my $longtext = 'blablabla';

      my $st = $db->prepare('insert into tablename (textfieldname) values(?)');            # Notice the question mark, that's where our data gets passed into
      $st->bind_param(1, $longtext, DBI::SQL_LONGVARCHAR );                                    # Our value is the first parameter (bind_param starts counting at 1)
      $st->execute($longtext);
Random Solutions  
 
programming4us programming4us