gpt4 book ai didi

sql - DBD::CSV 和占位符

转载 作者:行者123 更新时间:2023-12-04 20:56:40 25 4
gpt4 key购买 nike

#!/usr/bin/env perl
use warnings;
use strict;
use DBI;

my $dbh = DBI->connect( "DBI:CSV:", '', '', { RaiseError => 1 } ) or die DBI->errstr;

my $table = 'my_test_table_1.csv';
$dbh->do( "CREATE TEMP TABLE $table( id INTEGER, name CHAR(64) )" );

my $sth = $dbh->prepare( "INSERT INTO $table ( id, name ) VALUES( ?, ? )" );
$sth->execute( 1, 'Ruth' );
$sth->execute( 2, 'John' );
$sth->execute( 3, 'Nena' );
$sth->execute( 4, 'Mark' );

$sth = $dbh->prepare( "SELECT * FROM $table WHERE id > ? LIMIT ?" );
$sth->execute( 1, 2 );
$sth->dump_results;

# Bad limit clause! at /usr/local/lib/perl5/site_perl/5.20.1/SQL/Statement.pm line 88.

看起来 LIMIT 子句中的占位符不起作用。

当我使用 DBD::CSV 时,如何判断 SQL 语句中某个地方是否支持占位符?司机?

最佳答案

占位符只能用在需要表达式的地方。 LIMIT 后面必须是行数(不是表达式),所以不能是占位符。

#!/usr/bin/perl
use warnings;
use strict;
use DBI qw( );

my $dbh = DBI->connect("DBI:CSV:", undef, undef, {
PrintError => 0, RaiseError => 1,
} );

{
my $sth = $dbh->prepare( "SELECT 1 LIMIT 1" );
$sth->execute();
$sth->finish();
print "ok\n";
}

{
my $sth = $dbh->prepare( "SELECT 1 LIMIT 0+1" );
$sth->execute();
$sth->finish();
print "ok\n";
}

ok
DBD::CSV::db prepare failed: Bad limit clause! at .../SQL/Statement.pm line 88.
[for Statement "SELECT 1 LIMIT 0+1"] at a.pl line 18.

关于sql - DBD::CSV 和占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28153290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com