Perl的SQLite3:{NAME}无法正常工作?

use*_*879 4 sqlite perl dbi

这是我正在处理的sqlite数据库应用程序的代码片段:

my $query = "select * from pins";
my $sth = $dbh->prepare($query) or die "Couldn't prep: $DBI::errstr";
$sth->execute or die "Exec problem: $DBI::errstr";
my $result = $sth->fetchall_arrayref();
my $names = $sth->{NAME} or die "Name failed: $DBI::errstr";
foreach my $row (@$res) {
    # ... do some row-specific things
    foreach my $cell (@$row) {
        # ... do some cell-specific things
    }
}
Run Code Online (Sandbox Code Playgroud)

查询触发就好了,实际上它会返回正确的结果.但是,由于某种原因,这条线,

my $names = $sth->{NAME} or die "Name failed: $DBI::errstr";
Run Code Online (Sandbox Code Playgroud)

失败.{NAME}永远不会返回我期望的arrayref.如果我把die子句删掉,它运行正常(当然,无论我在哪里使用$ name,都会抛出预期的"使用未初始化的值"警告).

是否有一些明显的原因我错过了{NAME}不会触发,因为查询工作得很好?

谢谢!

use*_*879 5

我身上出现了很大的愚蠢错误.切换两条线以便它

my $names ...
my $result ...
Run Code Online (Sandbox Code Playgroud)

修复它.我想我必须在执行()之后直接抓取{NAME}(或者更确切地说,在$ sth更改之前).我没想到fetchall_arrayref会擦除{NAME}.

现在就行!对不起该帖子.我会把它留给子孙后代,直到有人认定它不值得这个空间.:-)