sql - Instead of the set of "?" use an array -


how make request without using lot of characters, , use array instead of them?

inside array @rowcashiergrps numbers "0001,0020,0027,0700";

i tried not work.

first:

use strict; use warnings;  use dbix::simple;  $dbfile='dptdat.db'; $db = dbi->connect("dbi:sqlite:$dbfile", "", "",  $result = $db->query( 'select b.id,cashnum,f1,f2,f3,f4,f5,sum(f6),sum(f7),sum(f8)  ckrdata  inner join ckrdatcashiername b  a.id =b.id , b.cashnum =?  group f1,b.id order b.id,f1', @rowcashiergrps); 

second:

use strict; use warnings;  use dbi;  $dbfile='dptdat.db'; $db = dbi->connect("dbi:sqlite:$dbfile", "", "", {raiseerror => 1, autocommit => 1});  $sqlt = "select b.id,cashnum,f1,f2,f3,f4,f5,sum(f6),sum(f7),sum(f8)  ckrdata inner join ckrdatcashiername b  a.id = b.id , b.cashnum in (" . "join(', ', ('?') x @rowcashiergrps)" . "group f1, b.id order b.id, f1";  $dbqueryalldatackr = $db->prepare($sqlt);  $dbqueryalldatackr->execute(@rowcashiergrps); 

sample data want get:

"001""0002"":0000""xxxxxxxx"":00"":0000"":00""0""0""0.0" "001""0002"":0001""mmmmmmmm"":11"":0000"":00""0""0""0.0" "001""0002"":0002""yyyyyyyy"":26"":0000"":00""0""0""0.0" "001""0002"":0009""zzzzzzzz"":01"":0000"":00""0""0""0.0" "001""0002"":0101""vvvvvvvv"":17"":0086"":00""145""3432""35740099.0" 

your first example doesn't work because don't terminate connect statement

my $db = dbi->connect("dbi:sqlite:$dbfile", "", "", 

and because b.cashnum = ? can compare 1 value passing whole array of values

your second example doesn't work because have

"join(', ', ('?') x @rowcashiergrps)" . 

inside double quotes, copy expression instead of building comma-separated list out of array values

this may work you, haven't shown data i've been unable test it

use strict; use warnings 'all';  use dbi;  $dbfile = 'dptdat.db'; $db = dbi->connect("dbi:sqlite:$dbfile", "", "", { raiseerror => 1, autocommit => 1 });  @row_cashier_grps;  $placeholders = join(', ', ('?') x @row_cashier_grps);  $sqlt = <<end_sql; select cashier.id, cashnum, f1, f2, f3, f4, f5, sum(f6), sum(f7), sum(f8)  ckrdata data inner join ckrdatcashiername cashier  data.id = cashier.id , cashier.cashnum in ($placeholders) group f1, cashier.id order cashier.id, f1 end_sql  $sth = $db->prepare($sqlt);  $sth->execute(@row_cashier_grps); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -