Perl Not Reading Full Values from Database

2019-09-02 01:54发布

问题:

I am currently using the DBI module to connect to my MSSQL Database to pull some data from a table.

The row I am trying to pull contains a lot of text (it is of type ntext and can contain up to 6Mb of text).

My query is a very simple one at the moment:

my $sql = "SELECT TOP 1 [reportRow] from UsageReport";

And I also have LongTruncOk enabled for the Database options.

After I execute the query, I want to display the rows.

while ( my @row = $sth->fetchrow_array ) {
   print "@row\n";
}

Unfortunately it displays the data in a very weird manner with spaces in between every character and it only retrieves the first 40 characters.

< r e p o r t > < r e p o r t h e a d e r > < m o n t h > O c t o b e r   2 0

If I use File::Slurp to output @row to a file, it displays as

Is there a reason the data is being cut off and is being displayed weird?

Edit: How would I convert UTF16 into a format that doesn't insert spaces between characters?

回答1:

You need to set LongReadLen in addition to LongTruncOk. You've told DBI it's ok to cut off long results from the DB, and now you need to tell it how long of a string you're willing to accept.