after a bit of debugging, i've figured this out (code + sql below)
conceivably, the first option would work ( IN (?,?,?) )-- i fear that
different DBs treat IN differently though, and i won't get expected
behavior on postgres. i'll have to search that.
what i did notice was a lot of confusion i had from the docs: the
only place I could find OR / AND under the Manager was in reference
to update/delete, in which the parameters are specifically nested in
a where clause. in a get, everything is where- so when i was nesting
things in 'where', it was just ignoring all of the parameters- so it
should have not been nested (thats in the tutorial, but not in the
manager)
perhaps an and/or statement can be added to one of the manager get
examples ?
---------------------
function:
get_items( user_id=> 1001 , type_id=> [ 1,2,3]);
excpected behaviour: SELECT * FROM __table__ WHERE
useraccount_Id=
1001 AND ( type_id= 1 OR type_id= 2 , OR type_id= 3);
Attempt 1;
my $results= $class->get_useraccount_items(
query=> [
useraccount_id=> $args{'user_id'},
is_deleted=> 0,
type_id=> $args{'type_id'}
],
db=> $args{db}
----
SELECT __cols__ FROM __table__ WHERE type_id IN ( ? , ? , ? ) AND
is_deleted= ? AND useraccount_id= ?
( 1,2,3,0,1001)
Attempt 2;
my @ors;
foreach my $_or ( @{$args{'type_id'}} ) {
push ( @ors , { 'type_id'=> $_or });
}
my $results= $class->get_useraccount_items(
query=> [
resource=> $args{resource} ,
is_deleted=> 0,
or=> [EMAIL PROTECTED]
],
db=> $args{db}
);
----
SELECT __cols__ FROM __table__ WHERE ( ) AND is_deleted = ? AND
useraccount_id = ?
(0,1001)
This will cause a DBI error
Attempt 3;
my @ors;
foreach my $_or ( @{$args{'type_id'}} ) {
push ( @ors , 'type_id'=> $_or );
}
my $results= $class->get_useraccount_items(
query=> [
resource=> $args{resource} ,
is_deleted=> 0,
or=> [EMAIL PROTECTED]
],
db=> $args{db}
);
----
SELECT __cols__ FROM __table__ WHERE ( type_id= ? OR type_id= ? OR
type_id= ? ) AND is_deleted = ? AND useraccount_id = ?
(1,2,3,0,1001)
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object