[Dbix-class] retrieve_from_sql

Emanuele Zeppieri ema_zep at libero.it
Thu Aug 4 17:48:53 CEST 2005

> -----Original Message-----
> From: dbix-class-bounces at lists.rawmode.org 
> [mailto:dbix-class-bounces at lists.rawmode.org] On Behalf Of 
> Krzysztof Krzyzaniak
> Sent: Thursday, August 04, 2005 1:28 PM
> To: dbix-class at lists.rawmode.org
> Subject: Re: [Dbix-class] retrieve_from_sql
> Matt S Trout wrote:
> [..]
> >>Seriously, I can do even more: if you prefer a more formal 
> approach, I
> >>can supply also some quite complete SQL grammar definition 
> files, that
> >>can provide a good reference to check if some SQL construct is not
> >>handled.
> > 
> > 
> > In that direction you might be better off looking at Darren Duncan's
> > Rosetta + SQL::Routine code; he's already gone the formal 
> grammar approach
> > so we're likely to use that for an implementation at some stage.
> > 
> Fix me if am I wrong. I wonder if any of abstract sql modules support 
> functions (builded or defined by user) - I mean something 
> like "SELECT 
> function1(field), function2(field) WHERE function3(field) = NULL;

Syntactically-wise, SQL::Abstract can handle such cases, since it does
not perform any syntactic check on the field names, so (once fixed the
missing FROM clause) your query becomes:

my @fields = ( 'function1(field)', 'function2(field)' );
my %where = (
	'function3(field)' => 'NULL',
my($stmt, @bind) = $sql->select('t', \@fields, \%where);
print "$stmt\n"; # if you wanna see it

(assuming that your NULL comparison is permitted by the DBMS).

Rather, SQL::Abstract can't handle much simpler cases, such as when two
(or more) fields are involved in the same subexpression, like this:

SELECT f1 FROM t WHERE t.f1 < t.f2

In such cases SQL::Abstract permits (and forces) you to resort to
literal SQL in some parts of the search condition, thus losing some info
on the syntactic structure of the query.

Having said that, Matt clearly said he's developing an extended
Abstract-like syntax, more powerful than SQL::Abstract.


More information about the Dbix-class mailing list