gpt4 book ai didi

postgresql - Perl PostgreSQL 查询执行两次

转载 作者:行者123 更新时间:2023-11-29 11:56:53 26 4
gpt4 key购买 nike

我试图理解为什么会这样,但找不到。 SQL 查询执行两次。

我的脚本片段:

my $driver = "Pg"; # Driver Name
my $database = $ARGV[0]; # First argument will be database name
my $dsn = "DBI:$driver:dbname=$database;host=127.0.0.1;port=5432";
my $userid = $ARGV[1]; # second argument will be username
my $password = $ARGV[2]; # third argument will be passwd
my $dbh = DBI->connect($dsn,$userid,$password, {RaiseError => 1 }) or die $DBI::errstr;

sub f_createUser {
if (scalar @_ != 3 ) {
return;
}
my $query = $dbh->prepare(qq{ SELECT createUserWithPassword(?,?) });
#my $result = $dbh->do($query) < 0 ? say "$DBI::errstr" : "# >>> Query worked successfully";
$query->execute($_[1],$_[2]);
}

&f_createUser(@revelantArray);

当我执行脚本时,我得到:

DBD::Pg::st execute failed: ERROR: role "tesstt" already exists CONTEXT: SQL statement "CREATE USER tesstt WITH PASSWORD '123'" PL/pgSQL function createuserwithpassword(character varying,character varying) line 3 at EXECUTE statement at homework2.pl line 39, line 1. DBD::Pg::st execute failed: ERROR: role "tesstt" already exists CONTEXT: SQL statement "CREATE USER tesstt WITH PASSWORD '123'" PL/pgSQL function createuserwithpassword(character varying,character varying) line 3 at EXECUTE statement at homework2.pl line 39, line 1.

为什么会这样?我错过了什么?

提前致谢...

最佳答案

您有 PrintError => 1,它会在出错时打印一条错误消息。

您有 RaiseError => 1,它会抛出一个包含错误消息的异常。未捕获的异常在程序结束时打印出来。

PrintError => 0 添加到传递给 DBI->connect 的选项。

关于postgresql - Perl PostgreSQL 查询执行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30221100/

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