Re: SQL Generation ( was Re: prefixing table names?)

[prev] [thread] [next] [Date index for 2004/10/19]

From: merlyn (Randal L. Schwartz)
Subject: Re: SQL Generation ( was Re: prefixing table names?)
Date: 09:46 on 19 Oct 2004
>>>>> "jason" == jason scott gessner <jason@xxxxxxxx.xxx> writes:

jason> What i am specifically interested in seeing for C::DBI is something
jason> along the lines of a less monolithic structure for the generation of the
jason> SQL statements.  This would be useful for databases that have custom SQL
jason> features that would be otherwise hard to use from C::DBI.  If there was
jason> a short method chain in C::DBI that would generate the SQL, then it
jason> would be easier to override only the part that you would like.  For
jason> example, my C::DBI::Mysql patch added a limit clause to the
jason> search_params object:
jason> 	my @rows = $class->search( category => 5, { order_by => "name", limit
jason> => "10, 20" };

jason> This was a pain to do because i had to override the entire SQL
jason> generation function from C::DBI to add 4 lines of code that doesn't
jason> belong in the core.  It belongs only in the MySQL module.  

Oddly enough, you could have used this (although I peeked to construct it):

package Class::DBI::mysql;

sub _do_search {
  for ($_[-1]) { # alias for easy access
    if (ref $_ eq "HASH") {
      if (defined(my $limit = $_->{limit})) {
        $_->{order_by} .= " LIMIT $limit";
        delete $_->{limit};
      }
    }
  }
  goto &{$class->can("SUPER::_do_search")};
}

Basically, frozz a bit with the arg list before passing it along.  Turns
out the "order_by" class is inserted literally at the end, hence the
sorta-cool hook.

        -- 
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@xxxxxxxxxx.xxx> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

(message missing)

prefixing table names?
bowen 15:20 on 15 Oct 2004

Re: prefixing table names?
jason 15:36 on 15 Oct 2004

Re: prefixing table names?
Tony Bowden 18:45 on 15 Oct 2004

SQL Generation ( was Re: prefixing table names?)
jason scott gessner 00:08 on 19 Oct 2004

Re: SQL Generation ( was Re: prefixing table names?)
merlyn (Randal L. Schwartz) 09:46 on 19 Oct 2004

Re: SQL Generation ( was Re: prefixing table names?)
merlyn (Randal L. Schwartz) 10:00 on 19 Oct 2004

Re: prefixing table names?
Tony Bowden 15:36 on 15 Oct 2004

Re: prefixing table names?
Bowen Dwelle 22:05 on 15 Oct 2004

Re: prefixing table names?
Bradley K. Embree 22:16 on 15 Oct 2004

Re: prefixing table names?
Bowen Dwelle 22:48 on 15 Oct 2004

Re: prefixing table names?
Bowen Dwelle 23:20 on 15 Oct 2004

Re: prefixing table names?
Perrin Harkins 16:44 on 15 Oct 2004

FromCGI and Untaint question
Peter Speltz 17:23 on 19 Oct 2004

Re: prefixing table names?
Bowen Dwelle 01:31 on 02 Nov 2004

Re: prefixing table names?
Bowen Dwelle 16:36 on 02 Nov 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52