为什么在没有启用ChopBlanks的情况下,从列值中剪掉尾随空格?
use DBI;
my $value = ' string ';
my $db = 'my_mysql_db';
my $dbh = DBI->connect( "dbi:mysql:db=$db", 'user', '*', { RaiseError => 1, ChopBlanks => 0 } ) or die DBI->errstr;
my $table = 'test_mysql';
$dbh->do( "CREATE TABLE IF NOT EXISTS $table (col_1 CHAR(64))" );
my $sth = $dbh->prepare( "DELETE FROM $table WHERE col_1 = ?" );
$sth->execute( $value );
$sth = $dbh->prepare( "INSERT INTO $table (col_1) VALUES( ? )" );
$sth->execute( $value );
$sth = $dbh->prepare( "SELECT * FROM $table" );
$sth->execute();
$sth->dump_results; ' string'
1 rows发布于 2022-06-30 17:04:50
我相信这是一个MySQL问题,而不是DBI问题。来自11.3.2 CHAR和VARCHAR类型
当
CHAR值被存储时,它们将以指定长度的空格填充.检索CHAR值时,除非启用PAD_CHAR_TO_FULL_LENGTHSQL模式,否则将移除尾随空格。
https://stackoverflow.com/questions/72817756
复制相似问题