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/

--- /System/Library/Perl/Extras/5.16/SQL/Abstract.pm	2013-10-31 07:46:01.000000000 +0100
+++ astrus/SQL/Abstract.pm	2015-01-05 09:22:54.000000000 +0100
@@ -405,7 +405,9 @@
 
   # order by?
   if ($order) {
-    $sql .= $self->_order_by($order);
+    my ($sql2, @bind2) = $self->_order_by($order);
+    $sql .= $sql2;
+    push @bind, @bind2;
   }
 
   return wantarray ? ($sql, @bind) : $sql;
_______________________________________________
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@lists.scsys.co.uk

Reply via email to