[Dbix-class] [OT][ANNOUNCE] SQL Generation with SQL::DB

Matija Grabnar matija at serverflow.com
Thu Sep 6 14:29:02 GMT 2007


Mark Lawrence wrote:
> The perldoc for SQL::Abstract itself shows just how difficult this is
> even for relatively simple cases:
>
>     %where = (
>         lname => {like => '%son%'},
>         age   => [-and => {'>=', 10}, {'<=', 20}],
>     );
>
>     Again, remember that the -and goes inside the arrayref.
>
> There is another *implicit* AND between the two conditions. At first
> (and second glance) this is very different from the actual intended SQL,
> not to mention the complexity of other artifical constructs like -nest.
> A much better mapping can be obtained with Perl's built-in logic operators.
>   
Actually, for a project I needed to write a parser from simple search 
expressions
into DBIx::Class. I was surprised by how simple it was to write the 
actions that got me a DBIx::Class search hash from a grammar with 
comparison operators, and, or and not. (Not was the hardest, because 
SQL::Abstract doesn't directly support it, but even then it was just a 
couple of hours).

Matija



More information about the DBIx-Class mailing list