[Dbix-class] Search condition on integer data-type column
Hetényi Csaba
csabiwork at tata.hu
Tue Mar 23 14:06:51 GMT 2010
Dear Members
I look for info about in subject.
I have a table, which has an integer data-type column (in the example:
megye).
I'd like to search for specific value (for ex.: nem = 1, megye = 5) and
it works perfectly
with the following code :
my $rs = $c->model('DB::Users')->search(
{
nem => $nem,
megye => $megye,
},
);
BUT, if the user wants to see all of the rows (but the 'nem' clause
still applied) what have to put in
$megye?
(i tried "LIKE", "%" things but it is for text type)
Is there a way to ignore "megye => $megye" line completely in this case,
but remain other clauses in
search ?
In old times (before Catalyst) i have builded a custom sql statement for
every user request with string-based operations:
$sql="SELECT * FROM users WHERE nem = $nem";
$sql = "$sql AND megye = $megye" if $megye != 0;
..
.
but i hope there is a nicer way!
(I readed SQL::Abstract but not find the solution)
Thank You in advance!
Csabi
More information about the DBIx-Class
mailing list