gpt4 book ai didi

sql - 除了 ?s 之外的 Perl DBI 占位符

转载 作者:行者123 更新时间:2023-12-05 08:43:24 24 4
gpt4 key购买 nike

我正在尝试为插入 SQL 编写准备语句,它有很多行要一次插入。所以当前的 prepare 语句如下所示,

my $sth = $dbh->prepare("INSERT INTO queues_details (id,keyword,data,flags) VALUES 
(?,'penaltymemberslimit','0','0'),
(?,'answered_elsewhere','0','0'),
(?,'timeoutpriority','app','0'),
(?,'timeoutrestart','no','0'),
(?,'memberdelay','0','0'),
(?,'servicelevel','60','0'),
(?,'reportholdtime','no','0'),
(?,'ringinuse','yes','0'),
(?,'weight','0','0'),
(?,'autofill','no','0'),
(?,'eventmemberstatus','no','0'),
(?,'eventwhencalled','no','0'),
(?,'monitor-join','yes','0'),
(?,'monitor-format','','0'),
(?,'periodic-announce-frequency','0','0'),
(?,'queue-thankyou','queue-thankyou','0'),
(?,'queue-callswaiting','queue-callswaiting','0'),
(?,'queue-thereare','queue-thereare','0'),
(?,'maxlen','0','0'),
(?,'joinempty','yes','0'),
(?,'leavewhenempty','no','0'),
(?,'strategy','ringall','0'),
(?,'timeout','15','0'),
(?,'retry','5','0'),
(?,'wrapuptime','0','0'),
(?,'announce-frequency','60','0'),
(?,'announce-holdtime','no','0'),
(?,'announce-position','yes','0'),
(?,'queue-youarenext','queue-youarenext','0');");

请注意,所有 ? 值都是相同的 id。

维护起来很复杂,并且很难从 prepareexecute 中添加/删除行。这些占位符 (?s) 是否有某种编号方法,以便我可以轻松找到需要更改的行。

谢谢!

最佳答案

只使用占位符

my $sql = "INSERT INTO queues_detail (id,keyword,data,flags) VALUES ";
$sql .= join ', ', ("(?,?,?,?)") x @data;

$dbh->do($sql, $undef, map { $id, @$_ } @data);

或者根本不使用任何

my $sql = "INSERT INTO queues_detail (id,keyword,data,flags) VALUES ";
$sql .= join(', ', map { "(" . join(', ', map $dbh->quote($_), $id, @$_) . ")" } @data);

$dbh->do($sql);

以上使用以下内容:

my @data = (
[ 'penaltymemberslimit', '0', 0 ],
[ 'answered_elsewhere', '0', 0 ],
[ 'timeoutpriority', 'app', 0 ],
[ 'timeoutrestart', 'no', 0 ],
[ 'memberdelay', '0', 0 ],
[ 'servicelevel', '60', 0 ],
[ 'reportholdtime', 'no', 0 ],
[ 'ringinuse', 'yes', 0 ],
[ 'weight', '0', 0 ],
[ 'autofill', 'no', 0 ],
[ 'eventmemberstatus', 'no', 0 ],
[ 'eventwhencalled', 'no', 0 ],
[ 'monitor-join', 'yes', 0 ],
[ 'monitor-format', '', 0 ],
[ 'periodic-announce-frequency', '0', 0 ],
[ 'queue-thankyou', 'queue-thankyou', 0 ],
[ 'queue-callswaiting', 'queue-callswaiting', 0 ],
[ 'queue-thereare', 'queue-thereare', 0 ],
[ 'maxlen', '0', 0 ],
[ 'joinempty', 'yes', 0 ],
[ 'leavewhenempty', 'no', 0 ],
[ 'strategy', 'ringall', 0 ],
[ 'timeout', '15', 0 ],
[ 'retry', '5', 0 ],
[ 'wrapuptime', '0', 0 ],
[ 'announce-frequency', '60', 0 ],
[ 'announce-holdtime', 'no', 0 ],
[ 'announce-position', 'yes', 0 ],
[ 'queue-youarenext', 'queue-youarenext', 0 ],
);

关于sql - 除了 ?s 之外的 Perl DBI 占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30449216/

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