[Dbix-class] order by field?

Octavian Rasnita orasnita at gmail.com
Tue Dec 18 08:53:25 GMT 2012


From: "Peter Rabbitson" <rabbit+dbic at rabbit.us>

> On Mon, Dec 17, 2012 at 11:04:22AM +0100, QE :: Felix Ostmann wrote:
>> I am doing such a order with the following SQL:
>> 
>> ...
>> ORDER BY
>>   (department = 'Marketing') DESC,
>>   (department = 'Sales') DESC,
>>   (department = 'Financial') DESC,
>>   (department = 'IT') DESC,
>>   (department = 'Operations') DESC,
>>   ...
>> 
>> But there is no special way to use this with DBIx::Class :-/
>> 
> 
> Can you elaborate? You can always do:
> 
> order_by => \' anything you feel like goes here'.
> 
> Is this not sufficient?
> 
> Cheers
> 



I can do:

order_by => \'field(department, "Marketing", "Sales", "IT")',

But the problem is that those names of the departments should be manually cleaned/escaped before inserting them in that script, to avoid SQL injection.

And another problem might be that the syntax above won't be portable to other databases.

I was wondering if there is a more portable method, similar to 'page' and 'rows' keys that makes the select ... limit X,y query portable to all databases, no matter if they support the 'limit' keyword or not.

Octavian




More information about the DBIx-Class mailing list