简体   繁体   English

使用 perl DBI 插入截断的文本

[英]text truncated using perl DBI insert

The problem is that DBI 's insert leaves long string truncated when inserting to MS SQL server.问题是DBIinsert在插入 MS SQL 服务器时会截断长字符串。 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.其中field_2的数据类型为varchar(100)$value_2是一个包含空格但没有其他特殊字符的 90 个字符的文本字符串。

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 (ie not a special character).执行语句后,没有出现错误,我检查了数据库,显然实际插入的$value_2在第80 个字符处被截断,该字符位于常规英文单词的中间(即不是特殊字符)。

I've tried to alter the data type of field_2 to varchar(150) and text .我试图将field_2的数据类型更改为varchar(150)text I've also used $dbh->quote($value_2) in place of $value_2 .我还使用$dbh->quote($value_2)代替$value_2 But they didn't help.但他们没有帮助。

Why is this happening?为什么会这样? What should I do?我应该怎么办? Thx!!谢谢!!

I'd say try various strings to see if they all behave the same way.我会说尝试各种字符串,看看它们是否都表现相同。 It's probably an encoding issue as davorg suggests.正如 davorg 所暗示的,这可能是一个编码问题。 The default collation in MySQL is Swedish or Latin1 as I recall, so in MySQL you'll probably want to change your collation to utf8_general_ci.我记得 MySQL 中的默认排序规则是瑞典语或拉丁语 1,所以在 MySQL 中,您可能希望将排序规则更改为 utf8_general_ci。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM