perl - SQL::Abstract::Limit failing at OR logic -


i'm trying create or logic query using class::dbi/class::dbi::abstractsearch. code looks this:

my $results = example::cdbi::quote->search_where(     {   field_1 => {'like', $search_string},         field_2 => {'like', $search_string}},     {logic => 'or'} ); 

according the documentation should work. says information passed sql::abstract::limit, shows taking logic parameter. unfortunately, mysql shows following in query log (edited brevity, , assuming search of "123"):

select * quote ((field_1 '123' , field_2 '123' )) 

i have trying changing 'or' 'or' (silly, worth shot) did not work. tried hunting down logic in sql::abstract::limit, operator being passed sql::abstract instead.

how sql::abstract::limit accept or logic class::dbi?

how class::dbi calls sql::abstract::limit
able determine how sql::abstract::limit being constructed. put values in instead of variable names easier read.

my $sql = sql::abstract::limit->new({'logic' => 'or'}); my($phrase, @bind) = $sql->where(     {'field_1'=>{'like' => '123'},'field_2'=>{'like'=>'123'}},     undef, undef, undef); 

you can apply or locally this:

use sql::abstract;  $sql = sql::abstract->new; ($stmt, @bind) = $sql->where(     { -or => [ { field_1 => { 'like', 'john' }},                { field_2 => { 'like', 'john' }},              ],     }, []); 

gives in $stmt:

where ( ( field_1 ? or field_2 ? ) )  

the logic property can set in sql::abstract constructor, don't have idea how propagate class::dbi.

edit: don't know if bug or feature, operators changed logic clause seems apply when define arrayrefs. hashrefs, and:

my $sql_and = sql::abstract::limit->new(logic => 'and'); $sql_or  = sql::abstract::limit->new(logic => 'or');  $sql_and->where(['field_1'=>{'like' => '123'},'field_2'=>{'like'=>'123'}]);   # ( ( field_1 ? , field_2 ? ) )  $sql_or->where (['field_1'=>{'like' => '123'},'field_2'=>{'like'=>'123'}]);   # ( ( field_1 ? or field_2 ? ) ) 

or, work class::dbi:

my $results = example::cdbi::quote->search_where(     [   field_1 => {'like', $search_string},         field_2 => {'like', $search_string}],     {logic => 'or'} ); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -