The problem is that DBI‘s insert leaves long string truncated when inserting to MS SQL server. Here are my codes:
my $insert = $dbh->prepare("INSERT INTO my_table (field_1, field_2) values (?, ?)");
$insert->execute($value_1, $value_2);
where field_2 has data type of varchar(100) and $value_2 is a text string of 90 characters with spaces but no other special characters.
After the statement is executed, with no error raised, I checked the database and apparently the actual inserted $value_2 is truncated at the 80th character, which is in the middle of a regular English word (i.e. not a special character).
I’ve tried to alter the data type of field_2 to varchar(150) and text. I’ve also used $dbh->quote($value_2) in place of $value_2. But they didn’t help.
Why is this happening? What should I do? Thx!!
If you are using freeTDS it is probably a bug identified in the freeTDS mailing list. See freetds silently truncating text/varchar/etc fields to 80 characters and http://lists.ibiblio.org/pipermail/freetds/2011q2/026943.html and http://lists.ibiblio.org/pipermail/freetds/2011q2/026925.html and http://lists.ibiblio.org/pipermail/freetds/2011q2/026944.html