[PATCH] SQL::Abstract: ORDER BY clause with with placeholders and bind values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] SQL::Abstract: ORDER BY clause with with placeholders and bind values

fabrizio.ge
Hello,
I'd like to generate some SQL like:

WHERE age >= 25
ORDER BY dept_id = ? DESC, name ASC

The intention is, for example, to have all records with dept_id=10 on top (so the boolean expression dept_id=10 has value 1), then the others.

I could not do it with SQL::Abstract without patching it: the patch is attached.

This is the code

my $a = SQL::Abstract->new;
my $id=10;
my ($b,@bind)=$a->where({age => {">=", 25 }},
[
{ -desc => \["dept_id=?" => ($id)] },
{ -asc => 'name' }
]);
print $b . "\n" . qq(@bind) . "\n"

With the patch, @bind is (25, 10), the desired result, without the patch it is (25).

Could you please apply the patch? Or specify a different solution not involving patching the code?

Regards,
Fabrizio



Connetti gratis il mondo con la nuova indoona: hai la chat, le chiamate, le video chiamate e persino le chiamate di gruppo.
E chiami gratis anche i numeri fissi e mobili nel mondo!
Scarica subito l’app Vai su https://www.indoona.com/


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...

abstract.patch (536 bytes) Download Attachment