在此上下文中将 undef 传递给 DBI 的“do”方法的目的是什么?

What is the purpose of passing undef to DBI's `do` method in this context?

我不明白 undef 在这段代码中做了什么:

$dbh->do (qq {
            INSERT INTO todo SET t = NOW(), status = 'open', content = ?
        }, undef, $content);

有人可以解释一下吗?我想我理解了整个代码,但不是它的来源。

use warnings;
use strict;
use lib q(/data/TEST/perl/lib);
use CGI qw(:standard);
use WebDB;

sub insert_item {
    my $content = shift;
    my $dbh;
    $content =~ s/^\s+//;
    $content =~ s/^\s+$//;
    if ($content ne "") {
        $dbh = WebDB::connect();
        $dbh->do (qq {
            INSERT INTO todo SET t = NOW(), status = 'open', content = ?
        }, undef, $content);
        $dbh->disconnect();
    }
}

sub display_entry_form {
    print start_form(-action=> url()),
    "To-do item:", br (),
    textarea ( -name => "content",
               -value => "",
               -override => 1,
               -rows =>3,
               -columns => 80),
    br (),
    submit(-name=> "choice", -value => "Submit"),
    end_form();
}

print header(), start_html(-title=>"To-Do List", -bgcolor => "white"), h2("To-Do List");

my $choice = lc(param ("choice"));

if ($choice eq "") {
    display_entry_form();
} elsif ( $choice eq "submit" ) {
    insert_item(param("content"));
    display_entry_form();
} else {
    print p ("Logic error, unknown choice: $choice");
}

do() 方法有 3 个参数:查询、查询属性和绑定数据。您示例中的 undef 表示没有要应用的属性。

参见"do()" in DBI on CPAN

$rows = $dbh->do($statement)           or die $dbh->errstr;
$rows = $dbh->do($statement, \%attr)   or die $dbh->errstr;
$rows = $dbh->do($statement, \%attr, @bind_values) or die ...