1 package SQL::Abstract; # see doc at end of file
6 use Module::Runtime qw(use_module);
11 $VERSION = eval $VERSION;
14 my($func) = (caller(1))[3];
15 Carp::carp "[$func] Warning: ", @_;
19 my($func) = (caller(1))[3];
20 Carp::croak "[$func] Fatal: ", @_;
23 has converter => (is => 'lazy', clearer => 'clear_converter');
26 is => 'ro', coerce => sub { $_[0] eq 'lower' ? 'lower' : undef }
30 is => 'ro', coerce => sub { uc($_[0]) }, default => sub { 'OR' }
34 is => 'ro', default => sub { 'normal' }
37 has cmp => (is => 'ro', default => sub { '=' });
39 has sqltrue => (is => 'ro', default => sub { '1=1' });
40 has sqlfalse => (is => 'ro', default => sub { '0=1' });
42 has special_ops => (is => 'ro', default => sub { [] });
43 has unary_ops => (is => 'ro', default => sub { [] });
46 # need to guard against ()'s in column names too, but this will break tons of
47 # hacks... ideas anyone?
49 has injection_guard => (
60 has renderer => (is => 'lazy', clearer => 'clear_renderer');
63 is => 'rw', default => sub { '.' },
65 $_[0]->clear_renderer;
66 $_[0]->clear_converter;
73 $_[0]->clear_renderer;
74 $_[0]->clear_converter;
78 has collapse_aliases => (
84 is => 'rw', default => sub { 1 },
86 $_[0]->clear_renderer;
87 $_[0]->clear_converter;
91 has convert => (is => 'ro');
93 has array_datatypes => (is => 'ro');
95 has converter_class => (
96 is => 'ro', default => sub { 'SQL::Abstract::Converter' }
99 has renderer_class => (
100 is => 'ro', default => sub { 'Data::Query::Renderer::SQL::Naive' }
103 sub _converter_args {
105 Scalar::Util::weaken($self);
107 lower_case => $self->case,
108 default_logic => $self->logic,
109 bind_meta => not($self->bindtype eq 'normal'),
110 identifier_sep => $self->name_sep,
111 (map +($_ => $self->$_), qw(
112 cmp sqltrue sqlfalse injection_guard convert array_datatypes
116 my $sub = $_->{handler};
119 handler => sub { $self->$sub(@_) }
121 } @{$self->special_ops}
123 renderer_will_quote => (
124 defined($self->quote_char) and $self->always_quote
129 sub _build_converter {
131 use_module($self->converter_class)->new($self->_converter_args);
137 for ($self->quote_char) {
138 $chars = defined() ? (ref() ? $_ : [$_]) : ['',''];
141 quote_chars => $chars, always_quote => $self->always_quote,
142 identifier_sep => $self->name_sep,
143 collapse_aliases => $self->collapse_aliases,
144 ($self->case ? (lc_keywords => 1) : ()), # always 'lower' if it exists
148 sub _build_renderer {
150 use_module($self->renderer_class)->new($self->_renderer_args);
154 my ($self, $dq) = @_;
158 my ($sql, @bind) = @{$self->renderer->render($dq)};
160 ($self->{bindtype} eq 'normal'
161 ? ($sql, map $_->{value}, @bind)
162 : ($sql, map [ $_->{value_meta}, $_->{value} ], @bind)
168 my ($self, $type, @args) = @_;
169 $self->_render_dq($self->converter->${\"_${type}_to_dq"}(@args));
172 sub insert { shift->_render_sqla(insert => @_) }
174 sub update { shift->_render_sqla(update => @_) }
176 sub select { shift->_render_sqla(select => @_) }
178 sub delete { shift->_render_sqla(delete => @_) }
181 my ($self, $where, $order) = @_;
187 ($sql, @bind) = $self->_recurse_where($where) if defined($where);
188 $sql = $sql ? $self->_sqlcase(' where ') . "( $sql )" : '';
192 $sql .= $self->_order_by($order);
195 return wantarray ? ($sql, @bind) : $sql;
198 sub _recurse_where { shift->_render_sqla(where => @_) }
201 my ($self, $arg) = @_;
202 if (my $dq = $self->converter->_order_by_to_dq($arg)) {
203 # SQLA generates ' ORDER BY foo'. The hilarity.
205 ? do { my @r = $self->_render_dq($dq); $r[0] = ' '.$r[0]; @r }
206 : ' '.$self->_render_dq($dq);
212 # highly optimized, as it's called way too often
214 # my ($self, $label) = @_;
216 return '' unless defined $_[1];
217 return ${$_[1]} if ref($_[1]) eq 'SCALAR';
219 unless ($_[0]->{quote_char}) {
220 $_[0]->_assert_pass_injection_guard($_[1]);
224 my $qref = ref $_[0]->{quote_char};
227 ($l, $r) = ( $_[0]->{quote_char}, $_[0]->{quote_char} );
229 elsif ($qref eq 'ARRAY') {
230 ($l, $r) = @{$_[0]->{quote_char}};
233 puke "Unsupported quote_char format: $_[0]->{quote_char}";
236 # parts containing * are naturally unquoted
237 return join( $_[0]->{name_sep}||'', map
238 { $_ eq '*' ? $_ : $l . $_ . $r }
239 ( $_[0]->{name_sep} ? split (/\Q$_[0]->{name_sep}\E/, $_[1] ) : $_[1] )
243 sub _assert_pass_injection_guard {
244 if ($_[1] =~ $_[0]->{injection_guard}) {
245 my $class = ref $_[0];
246 die "Possible SQL injection attempt '$_[1]'. If this is indeed a part of the
248 . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own
250 . "{injection_guard} attribute to ${class}->new()"
254 # Conversion, if applicable
256 #my ($self, $arg) = @_;
258 # LDNOTE : modified the previous implementation below because
259 # it was not consistent : the first "return" is always an array,
260 # the second "return" is context-dependent. Anyway, _convert
261 # seems always used with just a single argument, so make it a
263 # return @_ unless $self->{convert};
264 # my $conv = $self->_sqlcase($self->{convert});
265 # my @ret = map { $conv.'('.$_.')' } @_;
266 # return wantarray ? @ret : $ret[0];
267 if ($_[0]->{convert}) {
268 return $_[0]->_sqlcase($_[0]->{convert}) .'(' . $_[1] . ')';
275 #my ($self, $col, @vals) = @_;
277 #LDNOTE : changed original implementation below because it did not make
278 # sense when bindtype eq 'columns' and @vals > 1.
279 # return $self->{bindtype} eq 'columns' ? [ $col, @vals ] : @vals;
281 # called often - tighten code
282 return $_[0]->{bindtype} eq 'columns'
283 ? map {[$_[1], $_]} @_[2 .. $#_]
288 # Dies if any element of @bind is not in [colname => value] format
289 # if bindtype is 'columns'.
290 sub _assert_bindval_matches_bindtype {
291 # my ($self, @bind) = @_;
293 if ($self->{bindtype} eq 'columns') {
295 if (!defined $_ || ref($_) ne 'ARRAY' || @$_ != 2) {
296 puke "bindtype 'columns' selected, you need to pass: [column_name => bind_value]"
302 # Fix SQL case, if so requested
304 # LDNOTE: if $self->{case} is true, then it contains 'lower', so we
305 # don't touch the argument ... crooked logic, but let's not change it!
306 return $_[0]->{case} ? $_[1] : uc($_[1]);
311 my $data = shift || return;
312 puke "Argument to ", __PACKAGE__, "->values must be a \\%hash"
313 unless ref $data eq 'HASH';
316 foreach my $k ( sort keys %$data ) {
318 local our $Cur_Col_Meta = $k;
319 my ($sql, @bind) = $self->_render_sqla(
322 push @all_bind, @bind;
331 my(@sql, @sqlq, @sqlv);
335 if ($ref eq 'HASH') {
336 for my $k (sort keys %$_) {
339 my $label = $self->_quote($k);
341 # literal SQL with bind
342 my ($sql, @bind) = @$v;
343 $self->_assert_bindval_matches_bindtype(@bind);
344 push @sqlq, "$label = $sql";
346 } elsif ($r eq 'SCALAR') {
347 # literal SQL without bind
348 push @sqlq, "$label = $$v";
350 push @sqlq, "$label = ?";
351 push @sqlv, $self->_bindtype($k, $v);
354 push @sql, $self->_sqlcase('set'), join ', ', @sqlq;
355 } elsif ($ref eq 'ARRAY') {
356 # unlike insert(), assume these are ONLY the column names, i.e. for SQL
359 if ($r eq 'ARRAY') { # literal SQL with bind
360 my ($sql, @bind) = @$v;
361 $self->_assert_bindval_matches_bindtype(@bind);
364 } elsif ($r eq 'SCALAR') { # literal SQL without bind
365 # embedded literal SQL
372 push @sql, '(' . join(', ', @sqlq) . ')';
373 } elsif ($ref eq 'SCALAR') {
377 # strings get case twiddled
378 push @sql, $self->_sqlcase($_);
382 my $sql = join ' ', @sql;
384 # this is pretty tricky
385 # if ask for an array, return ($stmt, @bind)
386 # otherwise, s/?/shift @sqlv/ to put it inline
388 return ($sql, @sqlv);
390 1 while $sql =~ s/\?/my $d = shift(@sqlv);
391 ref $d ? $d->[1] : $d/e;
403 SQL::Abstract - Generate SQL from Perl data structures
409 my $sql = SQL::Abstract->new;
411 my($stmt, @bind) = $sql->select($table, \@fields, \%where, \@order);
413 my($stmt, @bind) = $sql->insert($table, \%fieldvals || \@values);
415 my($stmt, @bind) = $sql->update($table, \%fieldvals, \%where);
417 my($stmt, @bind) = $sql->delete($table, \%where);
419 # Then, use these in your DBI statements
420 my $sth = $dbh->prepare($stmt);
421 $sth->execute(@bind);
423 # Just generate the WHERE clause
424 my($stmt, @bind) = $sql->where(\%where, \@order);
426 # Return values in the same order, for hashed queries
427 # See PERFORMANCE section for more details
428 my @bind = $sql->values(\%fieldvals);
432 This module was inspired by the excellent L<DBIx::Abstract>.
433 However, in using that module I found that what I really wanted
434 to do was generate SQL, but still retain complete control over my
435 statement handles and use the DBI interface. So, I set out to
436 create an abstract SQL generation module.
438 While based on the concepts used by L<DBIx::Abstract>, there are
439 several important differences, especially when it comes to WHERE
440 clauses. I have modified the concepts used to make the SQL easier
441 to generate from Perl data structures and, IMO, more intuitive.
442 The underlying idea is for this module to do what you mean, based
443 on the data structures you provide it. The big advantage is that
444 you don't have to modify your code every time your data changes,
445 as this module figures it out.
447 To begin with, an SQL INSERT is as easy as just specifying a hash
448 of C<key=value> pairs:
451 name => 'Jimbo Bobson',
452 phone => '123-456-7890',
453 address => '42 Sister Lane',
455 state => 'Louisiana',
458 The SQL can then be generated with this:
460 my($stmt, @bind) = $sql->insert('people', \%data);
462 Which would give you something like this:
464 $stmt = "INSERT INTO people
465 (address, city, name, phone, state)
466 VALUES (?, ?, ?, ?, ?)";
467 @bind = ('42 Sister Lane', 'St. Louis', 'Jimbo Bobson',
468 '123-456-7890', 'Louisiana');
470 These are then used directly in your DBI code:
472 my $sth = $dbh->prepare($stmt);
473 $sth->execute(@bind);
475 =head2 Inserting and Updating Arrays
477 If your database has array types (like for example Postgres),
478 activate the special option C<< array_datatypes => 1 >>
479 when creating the C<SQL::Abstract> object.
480 Then you may use an arrayref to insert and update database array types:
482 my $sql = SQL::Abstract->new(array_datatypes => 1);
484 planets => [qw/Mercury Venus Earth Mars/]
487 my($stmt, @bind) = $sql->insert('solar_system', \%data);
491 $stmt = "INSERT INTO solar_system (planets) VALUES (?)"
493 @bind = (['Mercury', 'Venus', 'Earth', 'Mars']);
496 =head2 Inserting and Updating SQL
498 In order to apply SQL functions to elements of your C<%data> you may
499 specify a reference to an arrayref for the given hash value. For example,
500 if you need to execute the Oracle C<to_date> function on a value, you can
501 say something like this:
505 date_entered => \["to_date(?,'MM/DD/YYYY')", "03/02/2003"],
508 The first value in the array is the actual SQL. Any other values are
509 optional and would be included in the bind values array. This gives
512 my($stmt, @bind) = $sql->insert('people', \%data);
514 $stmt = "INSERT INTO people (name, date_entered)
515 VALUES (?, to_date(?,'MM/DD/YYYY'))";
516 @bind = ('Bill', '03/02/2003');
518 An UPDATE is just as easy, all you change is the name of the function:
520 my($stmt, @bind) = $sql->update('people', \%data);
522 Notice that your C<%data> isn't touched; the module will generate
523 the appropriately quirky SQL for you automatically. Usually you'll
524 want to specify a WHERE clause for your UPDATE, though, which is
525 where handling C<%where> hashes comes in handy...
527 =head2 Complex where statements
529 This module can generate pretty complicated WHERE statements
530 easily. For example, simple C<key=value> pairs are taken to mean
531 equality, and if you want to see if a field is within a set
532 of values, you can use an arrayref. Let's say we wanted to
533 SELECT some data based on this criteria:
537 worker => ['nwiger', 'rcwe', 'sfz'],
538 status => { '!=', 'completed' }
541 my($stmt, @bind) = $sql->select('tickets', '*', \%where);
543 The above would give you something like this:
545 $stmt = "SELECT * FROM tickets WHERE
546 ( requestor = ? ) AND ( status != ? )
547 AND ( worker = ? OR worker = ? OR worker = ? )";
548 @bind = ('inna', 'completed', 'nwiger', 'rcwe', 'sfz');
550 Which you could then use in DBI code like so:
552 my $sth = $dbh->prepare($stmt);
553 $sth->execute(@bind);
559 The functions are simple. There's one for each major SQL operation,
560 and a constructor you use first. The arguments are specified in a
561 similar order to each function (table, then fields, then a where
562 clause) to try and simplify things.
567 =head2 new(option => 'value')
569 The C<new()> function takes a list of options and values, and returns
570 a new B<SQL::Abstract> object which can then be used to generate SQL
571 through the methods below. The options accepted are:
577 If set to 'lower', then SQL will be generated in all lowercase. By
578 default SQL is generated in "textbook" case meaning something like:
580 SELECT a_field FROM a_table WHERE some_field LIKE '%someval%'
582 Any setting other than 'lower' is ignored.
586 This determines what the default comparison operator is. By default
587 it is C<=>, meaning that a hash like this:
589 %where = (name => 'nwiger', email => 'nate@wiger.org');
591 Will generate SQL like this:
593 WHERE name = 'nwiger' AND email = 'nate@wiger.org'
595 However, you may want loose comparisons by default, so if you set
596 C<cmp> to C<like> you would get SQL such as:
598 WHERE name like 'nwiger' AND email like 'nate@wiger.org'
600 You can also override the comparsion on an individual basis - see
601 the huge section on L</"WHERE CLAUSES"> at the bottom.
603 =item sqltrue, sqlfalse
605 Expressions for inserting boolean values within SQL statements.
606 By default these are C<1=1> and C<1=0>. They are used
607 by the special operators C<-in> and C<-not_in> for generating
608 correct SQL even when the argument is an empty array (see below).
612 This determines the default logical operator for multiple WHERE
613 statements in arrays or hashes. If absent, the default logic is "or"
614 for arrays, and "and" for hashes. This means that a WHERE
618 event_date => {'>=', '2/13/99'},
619 event_date => {'<=', '4/24/03'},
622 will generate SQL like this:
624 WHERE event_date >= '2/13/99' OR event_date <= '4/24/03'
626 This is probably not what you want given this query, though (look
627 at the dates). To change the "OR" to an "AND", simply specify:
629 my $sql = SQL::Abstract->new(logic => 'and');
631 Which will change the above C<WHERE> to:
633 WHERE event_date >= '2/13/99' AND event_date <= '4/24/03'
635 The logic can also be changed locally by inserting
636 a modifier in front of an arrayref :
638 @where = (-and => [event_date => {'>=', '2/13/99'},
639 event_date => {'<=', '4/24/03'} ]);
641 See the L</"WHERE CLAUSES"> section for explanations.
645 This will automatically convert comparisons using the specified SQL
646 function for both column and value. This is mostly used with an argument
647 of C<upper> or C<lower>, so that the SQL will have the effect of
648 case-insensitive "searches". For example, this:
650 $sql = SQL::Abstract->new(convert => 'upper');
651 %where = (keywords => 'MaKe iT CAse inSeNSItive');
653 Will turn out the following SQL:
655 WHERE upper(keywords) like upper('MaKe iT CAse inSeNSItive')
657 The conversion can be C<upper()>, C<lower()>, or any other SQL function
658 that can be applied symmetrically to fields (actually B<SQL::Abstract> does
659 not validate this option; it will just pass through what you specify verbatim).
663 This is a kludge because many databases suck. For example, you can't
664 just bind values using DBI's C<execute()> for Oracle C<CLOB> or C<BLOB> fields.
665 Instead, you have to use C<bind_param()>:
667 $sth->bind_param(1, 'reg data');
668 $sth->bind_param(2, $lots, {ora_type => ORA_CLOB});
670 The problem is, B<SQL::Abstract> will normally just return a C<@bind> array,
671 which loses track of which field each slot refers to. Fear not.
673 If you specify C<bindtype> in new, you can determine how C<@bind> is returned.
674 Currently, you can specify either C<normal> (default) or C<columns>. If you
675 specify C<columns>, you will get an array that looks like this:
677 my $sql = SQL::Abstract->new(bindtype => 'columns');
678 my($stmt, @bind) = $sql->insert(...);
681 [ 'column1', 'value1' ],
682 [ 'column2', 'value2' ],
683 [ 'column3', 'value3' ],
686 You can then iterate through this manually, using DBI's C<bind_param()>.
688 $sth->prepare($stmt);
691 my($col, $data) = @$_;
692 if ($col eq 'details' || $col eq 'comments') {
693 $sth->bind_param($i, $data, {ora_type => ORA_CLOB});
694 } elsif ($col eq 'image') {
695 $sth->bind_param($i, $data, {ora_type => ORA_BLOB});
697 $sth->bind_param($i, $data);
701 $sth->execute; # execute without @bind now
703 Now, why would you still use B<SQL::Abstract> if you have to do this crap?
704 Basically, the advantage is still that you don't have to care which fields
705 are or are not included. You could wrap that above C<for> loop in a simple
706 sub called C<bind_fields()> or something and reuse it repeatedly. You still
707 get a layer of abstraction over manual SQL specification.
709 Note that if you set L</bindtype> to C<columns>, the C<\[$sql, @bind]>
710 construct (see L</Literal SQL with placeholders and bind values (subqueries)>)
711 will expect the bind values in this format.
715 This is the character that a table or column name will be quoted
716 with. By default this is an empty string, but you could set it to
717 the character C<`>, to generate SQL like this:
719 SELECT `a_field` FROM `a_table` WHERE `some_field` LIKE '%someval%'
721 Alternatively, you can supply an array ref of two items, the first being the left
722 hand quote character, and the second the right hand quote character. For
723 example, you could supply C<['[',']']> for SQL Server 2000 compliant quotes
724 that generates SQL like this:
726 SELECT [a_field] FROM [a_table] WHERE [some_field] LIKE '%someval%'
728 Quoting is useful if you have tables or columns names that are reserved
729 words in your database's SQL dialect.
733 This is the character that separates a table and column name. It is
734 necessary to specify this when the C<quote_char> option is selected,
735 so that tables and column names can be individually quoted like this:
737 SELECT `table`.`one_field` FROM `table` WHERE `table`.`other_field` = 1
739 =item injection_guard
741 A regular expression C<qr/.../> that is applied to any C<-function> and unquoted
742 column name specified in a query structure. This is a safety mechanism to avoid
743 injection attacks when mishandling user input e.g.:
745 my %condition_as_column_value_pairs = get_values_from_user();
746 $sqla->select( ... , \%condition_as_column_value_pairs );
748 If the expression matches an exception is thrown. Note that literal SQL
749 supplied via C<\'...'> or C<\['...']> is B<not> checked in any way.
751 Defaults to checking for C<;> and the C<GO> keyword (TransactSQL)
753 =item array_datatypes
755 When this option is true, arrayrefs in INSERT or UPDATE are
756 interpreted as array datatypes and are passed directly
758 When this option is false, arrayrefs are interpreted
759 as literal SQL, just like refs to arrayrefs
760 (but this behavior is for backwards compatibility; when writing
761 new queries, use the "reference to arrayref" syntax
767 Takes a reference to a list of "special operators"
768 to extend the syntax understood by L<SQL::Abstract>.
769 See section L</"SPECIAL OPERATORS"> for details.
773 Takes a reference to a list of "unary operators"
774 to extend the syntax understood by L<SQL::Abstract>.
775 See section L</"UNARY OPERATORS"> for details.
781 =head2 insert($table, \@values || \%fieldvals, \%options)
783 This is the simplest function. You simply give it a table name
784 and either an arrayref of values or hashref of field/value pairs.
785 It returns an SQL INSERT statement and a list of bind values.
786 See the sections on L</"Inserting and Updating Arrays"> and
787 L</"Inserting and Updating SQL"> for information on how to insert
788 with those data types.
790 The optional C<\%options> hash reference may contain additional
791 options to generate the insert SQL. Currently supported options
798 Takes either a scalar of raw SQL fields, or an array reference of
799 field names, and adds on an SQL C<RETURNING> statement at the end.
800 This allows you to return data generated by the insert statement
801 (such as row IDs) without performing another C<SELECT> statement.
802 Note, however, this is not part of the SQL standard and may not
803 be supported by all database engines.
807 =head2 update($table, \%fieldvals, \%where)
809 This takes a table, hashref of field/value pairs, and an optional
810 hashref L<WHERE clause|/WHERE CLAUSES>. It returns an SQL UPDATE function and a list
812 See the sections on L</"Inserting and Updating Arrays"> and
813 L</"Inserting and Updating SQL"> for information on how to insert
814 with those data types.
816 =head2 select($source, $fields, $where, $order)
818 This returns a SQL SELECT statement and associated list of bind values, as
819 specified by the arguments :
825 Specification of the 'FROM' part of the statement.
826 The argument can be either a plain scalar (interpreted as a table
827 name, will be quoted), or an arrayref (interpreted as a list
828 of table names, joined by commas, quoted), or a scalarref
829 (literal table name, not quoted), or a ref to an arrayref
830 (list of literal table names, joined by commas, not quoted).
834 Specification of the list of fields to retrieve from
836 The argument can be either an arrayref (interpreted as a list
837 of field names, will be joined by commas and quoted), or a
838 plain scalar (literal SQL, not quoted).
839 Please observe that this API is not as flexible as for
840 the first argument C<$table>, for backwards compatibility reasons.
844 Optional argument to specify the WHERE part of the query.
845 The argument is most often a hashref, but can also be
846 an arrayref or plain scalar --
847 see section L<WHERE clause|/"WHERE CLAUSES"> for details.
851 Optional argument to specify the ORDER BY part of the query.
852 The argument can be a scalar, a hashref or an arrayref
853 -- see section L<ORDER BY clause|/"ORDER BY CLAUSES">
859 =head2 delete($table, \%where)
861 This takes a table name and optional hashref L<WHERE clause|/WHERE CLAUSES>.
862 It returns an SQL DELETE statement and list of bind values.
864 =head2 where(\%where, \@order)
866 This is used to generate just the WHERE clause. For example,
867 if you have an arbitrary data structure and know what the
868 rest of your SQL is going to look like, but want an easy way
869 to produce a WHERE clause, use this. It returns an SQL WHERE
870 clause and list of bind values.
873 =head2 values(\%data)
875 This just returns the values from the hash C<%data>, in the same
876 order that would be returned from any of the other above queries.
877 Using this allows you to markedly speed up your queries if you
878 are affecting lots of rows. See below under the L</"PERFORMANCE"> section.
880 =head2 generate($any, 'number', $of, \@data, $struct, \%types)
882 Warning: This is an experimental method and subject to change.
884 This returns arbitrarily generated SQL. It's a really basic shortcut.
885 It will return two different things, depending on return context:
887 my($stmt, @bind) = $sql->generate('create table', \$table, \@fields);
888 my $stmt_and_val = $sql->generate('create table', \$table, \@fields);
890 These would return the following:
893 $stmt = "CREATE TABLE test (?, ?)";
894 @bind = (field1, field2);
896 # Second calling form
897 $stmt_and_val = "CREATE TABLE test (field1, field2)";
899 Depending on what you're trying to do, it's up to you to choose the correct
900 format. In this example, the second form is what you would want.
904 $sql->generate('alter session', { nls_date_format => 'MM/YY' });
908 ALTER SESSION SET nls_date_format = 'MM/YY'
910 You get the idea. Strings get their case twiddled, but everything
911 else remains verbatim.
917 This module uses a variation on the idea from L<DBIx::Abstract>. It
918 is B<NOT>, repeat I<not> 100% compatible. B<The main logic of this
919 module is that things in arrays are OR'ed, and things in hashes
922 The easiest way to explain is to show lots of examples. After
923 each C<%where> hash shown, it is assumed you used:
925 my($stmt, @bind) = $sql->where(\%where);
927 However, note that the C<%where> hash can be used directly in any
928 of the other functions as well, as described above.
930 =head2 Key-value pairs
932 So, let's get started. To begin, a simple hash:
936 status => 'completed'
939 Is converted to SQL C<key = val> statements:
941 $stmt = "WHERE user = ? AND status = ?";
942 @bind = ('nwiger', 'completed');
944 One common thing I end up doing is having a list of values that
945 a field can be in. To do this, simply specify a list inside of
950 status => ['assigned', 'in-progress', 'pending'];
953 This simple code will create the following:
955 $stmt = "WHERE user = ? AND ( status = ? OR status = ? OR status = ? )";
956 @bind = ('nwiger', 'assigned', 'in-progress', 'pending');
958 A field associated to an empty arrayref will be considered a
959 logical false and will generate 0=1.
961 =head2 Tests for NULL values
963 If the value part is C<undef> then this is converted to SQL <IS NULL>
972 $stmt = "WHERE user = ? AND status IS NULL";
975 To test if a column IS NOT NULL:
979 status => { '!=', undef },
982 =head2 Specific comparison operators
984 If you want to specify a different type of operator for your comparison,
985 you can use a hashref for a given column:
989 status => { '!=', 'completed' }
992 Which would generate:
994 $stmt = "WHERE user = ? AND status != ?";
995 @bind = ('nwiger', 'completed');
997 To test against multiple values, just enclose the values in an arrayref:
999 status => { '=', ['assigned', 'in-progress', 'pending'] };
1001 Which would give you:
1003 "WHERE status = ? OR status = ? OR status = ?"
1006 The hashref can also contain multiple pairs, in which case it is expanded
1007 into an C<AND> of its elements:
1011 status => { '!=', 'completed', -not_like => 'pending%' }
1014 # Or more dynamically, like from a form
1015 $where{user} = 'nwiger';
1016 $where{status}{'!='} = 'completed';
1017 $where{status}{'-not_like'} = 'pending%';
1019 # Both generate this
1020 $stmt = "WHERE user = ? AND status != ? AND status NOT LIKE ?";
1021 @bind = ('nwiger', 'completed', 'pending%');
1024 To get an OR instead, you can combine it with the arrayref idea:
1028 priority => [ { '=', 2 }, { '>', 5 } ]
1031 Which would generate:
1033 $stmt = "WHERE ( priority = ? OR priority > ? ) AND user = ?";
1034 @bind = ('2', '5', 'nwiger');
1036 If you want to include literal SQL (with or without bind values), just use a
1037 scalar reference or array reference as the value:
1040 date_entered => { '>' => \["to_date(?, 'MM/DD/YYYY')", "11/26/2008"] },
1041 date_expires => { '<' => \"now()" }
1044 Which would generate:
1046 $stmt = "WHERE date_entered > "to_date(?, 'MM/DD/YYYY') AND date_expires < now()";
1047 @bind = ('11/26/2008');
1050 =head2 Logic and nesting operators
1052 In the example above,
1053 there is a subtle trap if you want to say something like
1054 this (notice the C<AND>):
1056 WHERE priority != ? AND priority != ?
1058 Because, in Perl you I<can't> do this:
1060 priority => { '!=', 2, '!=', 1 }
1062 As the second C<!=> key will obliterate the first. The solution
1063 is to use the special C<-modifier> form inside an arrayref:
1065 priority => [ -and => {'!=', 2},
1069 Normally, these would be joined by C<OR>, but the modifier tells it
1070 to use C<AND> instead. (Hint: You can use this in conjunction with the
1071 C<logic> option to C<new()> in order to change the way your queries
1072 work by default.) B<Important:> Note that the C<-modifier> goes
1073 B<INSIDE> the arrayref, as an extra first element. This will
1074 B<NOT> do what you think it might:
1076 priority => -and => [{'!=', 2}, {'!=', 1}] # WRONG!
1078 Here is a quick list of equivalencies, since there is some overlap:
1081 status => {'!=', 'completed', 'not like', 'pending%' }
1082 status => [ -and => {'!=', 'completed'}, {'not like', 'pending%'}]
1085 status => {'=', ['assigned', 'in-progress']}
1086 status => [ -or => {'=', 'assigned'}, {'=', 'in-progress'}]
1087 status => [ {'=', 'assigned'}, {'=', 'in-progress'} ]
1091 =head2 Special operators : IN, BETWEEN, etc.
1093 You can also use the hashref format to compare a list of fields using the
1094 C<IN> comparison operator, by specifying the list as an arrayref:
1097 status => 'completed',
1098 reportid => { -in => [567, 2335, 2] }
1101 Which would generate:
1103 $stmt = "WHERE status = ? AND reportid IN (?,?,?)";
1104 @bind = ('completed', '567', '2335', '2');
1106 The reverse operator C<-not_in> generates SQL C<NOT IN> and is used in
1109 If the argument to C<-in> is an empty array, 'sqlfalse' is generated
1110 (by default : C<1=0>). Similarly, C<< -not_in => [] >> generates
1111 'sqltrue' (by default : C<1=1>).
1113 In addition to the array you can supply a chunk of literal sql or
1114 literal sql with bind:
1117 customer => { -in => \[
1118 'SELECT cust_id FROM cust WHERE balance > ?',
1121 status => { -in => \'SELECT status_codes FROM states' },
1127 customer IN ( SELECT cust_id FROM cust WHERE balance > ? )
1128 AND status IN ( SELECT status_codes FROM states )
1134 Another pair of operators is C<-between> and C<-not_between>,
1135 used with an arrayref of two values:
1139 completion_date => {
1140 -not_between => ['2002-10-01', '2003-02-06']
1146 WHERE user = ? AND completion_date NOT BETWEEN ( ? AND ? )
1148 Just like with C<-in> all plausible combinations of literal SQL
1152 start0 => { -between => [ 1, 2 ] },
1153 start1 => { -between => \["? AND ?", 1, 2] },
1154 start2 => { -between => \"lower(x) AND upper(y)" },
1155 start3 => { -between => [
1157 \["upper(?)", 'stuff' ],
1164 ( start0 BETWEEN ? AND ? )
1165 AND ( start1 BETWEEN ? AND ? )
1166 AND ( start2 BETWEEN lower(x) AND upper(y) )
1167 AND ( start3 BETWEEN lower(x) AND upper(?) )
1169 @bind = (1, 2, 1, 2, 'stuff');
1172 These are the two builtin "special operators"; but the
1173 list can be expanded : see section L</"SPECIAL OPERATORS"> below.
1175 =head2 Unary operators: bool
1177 If you wish to test against boolean columns or functions within your
1178 database you can use the C<-bool> and C<-not_bool> operators. For
1179 example to test the column C<is_user> being true and the column
1180 C<is_enabled> being false you would use:-
1184 -not_bool => 'is_enabled',
1189 WHERE is_user AND NOT is_enabled
1191 If a more complex combination is required, testing more conditions,
1192 then you should use the and/or operators:-
1199 -not_bool => 'four',
1205 WHERE one AND two AND three AND NOT four
1208 =head2 Nested conditions, -and/-or prefixes
1210 So far, we've seen how multiple conditions are joined with a top-level
1211 C<AND>. We can change this by putting the different conditions we want in
1212 hashes and then putting those hashes in an array. For example:
1217 status => { -like => ['pending%', 'dispatched'] },
1221 status => 'unassigned',
1225 This data structure would create the following:
1227 $stmt = "WHERE ( user = ? AND ( status LIKE ? OR status LIKE ? ) )
1228 OR ( user = ? AND status = ? ) )";
1229 @bind = ('nwiger', 'pending', 'dispatched', 'robot', 'unassigned');
1232 Clauses in hashrefs or arrayrefs can be prefixed with an C<-and> or C<-or>
1233 to change the logic inside :
1239 -and => [ workhrs => {'>', 20}, geo => 'ASIA' ],
1240 -or => { workhrs => {'<', 50}, geo => 'EURO' },
1247 WHERE ( user = ? AND (
1248 ( workhrs > ? AND geo = ? )
1249 OR ( workhrs < ? OR geo = ? )
1252 =head3 Algebraic inconsistency, for historical reasons
1254 C<Important note>: when connecting several conditions, the C<-and->|C<-or>
1255 operator goes C<outside> of the nested structure; whereas when connecting
1256 several constraints on one column, the C<-and> operator goes
1257 C<inside> the arrayref. Here is an example combining both features :
1260 -and => [a => 1, b => 2],
1261 -or => [c => 3, d => 4],
1262 e => [-and => {-like => 'foo%'}, {-like => '%bar'} ]
1267 WHERE ( ( ( a = ? AND b = ? )
1268 OR ( c = ? OR d = ? )
1269 OR ( e LIKE ? AND e LIKE ? ) ) )
1271 This difference in syntax is unfortunate but must be preserved for
1272 historical reasons. So be careful : the two examples below would
1273 seem algebraically equivalent, but they are not
1275 {col => [-and => {-like => 'foo%'}, {-like => '%bar'}]}
1276 # yields : WHERE ( ( col LIKE ? AND col LIKE ? ) )
1278 [-and => {col => {-like => 'foo%'}, {col => {-like => '%bar'}}]]
1279 # yields : WHERE ( ( col LIKE ? OR col LIKE ? ) )
1282 =head2 Literal SQL and value type operators
1284 The basic premise of SQL::Abstract is that in WHERE specifications the "left
1285 side" is a column name and the "right side" is a value (normally rendered as
1286 a placeholder). This holds true for both hashrefs and arrayref pairs as you
1287 see in the L</WHERE CLAUSES> examples above. Sometimes it is necessary to
1288 alter this behavior. There are several ways of doing so.
1292 This is a virtual operator that signals the string to its right side is an
1293 identifier (a column name) and not a value. For example to compare two
1294 columns you would write:
1297 priority => { '<', 2 },
1298 requestor => { -ident => 'submitter' },
1303 $stmt = "WHERE priority < ? AND requestor = submitter";
1306 If you are maintaining legacy code you may see a different construct as
1307 described in L</Deprecated usage of Literal SQL>, please use C<-ident> in new
1312 This is a virtual operator that signals that the construct to its right side
1313 is a value to be passed to DBI. This is for example necessary when you want
1314 to write a where clause against an array (for RDBMS that support such
1315 datatypes). For example:
1318 array => { -value => [1, 2, 3] }
1323 $stmt = 'WHERE array = ?';
1324 @bind = ([1, 2, 3]);
1326 Note that if you were to simply say:
1332 the result would porbably be not what you wanted:
1334 $stmt = 'WHERE array = ? OR array = ? OR array = ?';
1339 Finally, sometimes only literal SQL will do. To include a random snippet
1340 of SQL verbatim, you specify it as a scalar reference. Consider this only
1341 as a last resort. Usually there is a better way. For example:
1344 priority => { '<', 2 },
1345 requestor => { -in => \'(SELECT name FROM hitmen)' },
1350 $stmt = "WHERE priority < ? AND requestor IN (SELECT name FROM hitmen)"
1353 Note that in this example, you only get one bind parameter back, since
1354 the verbatim SQL is passed as part of the statement.
1358 Never use untrusted input as a literal SQL argument - this is a massive
1359 security risk (there is no way to check literal snippets for SQL
1360 injections and other nastyness). If you need to deal with untrusted input
1361 use literal SQL with placeholders as described next.
1363 =head3 Literal SQL with placeholders and bind values (subqueries)
1365 If the literal SQL to be inserted has placeholders and bind values,
1366 use a reference to an arrayref (yes this is a double reference --
1367 not so common, but perfectly legal Perl). For example, to find a date
1368 in Postgres you can use something like this:
1371 date_column => \[q/= date '2008-09-30' - ?::integer/, 10/]
1376 $stmt = "WHERE ( date_column = date '2008-09-30' - ?::integer )"
1379 Note that you must pass the bind values in the same format as they are returned
1380 by L</where>. That means that if you set L</bindtype> to C<columns>, you must
1381 provide the bind values in the C<< [ column_meta => value ] >> format, where
1382 C<column_meta> is an opaque scalar value; most commonly the column name, but
1383 you can use any scalar value (including references and blessed references),
1384 L<SQL::Abstract> will simply pass it through intact. So if C<bindtype> is set
1385 to C<columns> the above example will look like:
1388 date_column => \[q/= date '2008-09-30' - ?::integer/, [ dummy => 10 ]/]
1391 Literal SQL is especially useful for nesting parenthesized clauses in the
1392 main SQL query. Here is a first example :
1394 my ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
1398 bar => \["IN ($sub_stmt)" => @sub_bind],
1403 $stmt = "WHERE (foo = ? AND bar IN (SELECT c1 FROM t1
1404 WHERE c2 < ? AND c3 LIKE ?))";
1405 @bind = (1234, 100, "foo%");
1407 Other subquery operators, like for example C<"E<gt> ALL"> or C<"NOT IN">,
1408 are expressed in the same way. Of course the C<$sub_stmt> and
1409 its associated bind values can be generated through a former call
1412 my ($sub_stmt, @sub_bind)
1413 = $sql->select("t1", "c1", {c2 => {"<" => 100},
1414 c3 => {-like => "foo%"}});
1417 bar => \["> ALL ($sub_stmt)" => @sub_bind],
1420 In the examples above, the subquery was used as an operator on a column;
1421 but the same principle also applies for a clause within the main C<%where>
1422 hash, like an EXISTS subquery :
1424 my ($sub_stmt, @sub_bind)
1425 = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
1426 my %where = ( -and => [
1428 \["EXISTS ($sub_stmt)" => @sub_bind],
1433 $stmt = "WHERE (foo = ? AND EXISTS (SELECT * FROM t1
1434 WHERE c1 = ? AND c2 > t0.c0))";
1438 Observe that the condition on C<c2> in the subquery refers to
1439 column C<t0.c0> of the main query : this is I<not> a bind
1440 value, so we have to express it through a scalar ref.
1441 Writing C<< c2 => {">" => "t0.c0"} >> would have generated
1442 C<< c2 > ? >> with bind value C<"t0.c0"> ... not exactly
1443 what we wanted here.
1445 Finally, here is an example where a subquery is used
1446 for expressing unary negation:
1448 my ($sub_stmt, @sub_bind)
1449 = $sql->where({age => [{"<" => 10}, {">" => 20}]});
1450 $sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
1452 lname => {like => '%son%'},
1453 \["NOT ($sub_stmt)" => @sub_bind],
1458 $stmt = "lname LIKE ? AND NOT ( age < ? OR age > ? )"
1459 @bind = ('%son%', 10, 20)
1461 =head3 Deprecated usage of Literal SQL
1463 Below are some examples of archaic use of literal SQL. It is shown only as
1464 reference for those who deal with legacy code. Each example has a much
1465 better, cleaner and safer alternative that users should opt for in new code.
1471 my %where = ( requestor => \'IS NOT NULL' )
1473 $stmt = "WHERE requestor IS NOT NULL"
1475 This used to be the way of generating NULL comparisons, before the handling
1476 of C<undef> got formalized. For new code please use the superior syntax as
1477 described in L</Tests for NULL values>.
1481 my %where = ( requestor => \'= submitter' )
1483 $stmt = "WHERE requestor = submitter"
1485 This used to be the only way to compare columns. Use the superior L</-ident>
1486 method for all new code. For example an identifier declared in such a way
1487 will be properly quoted if L</quote_char> is properly set, while the legacy
1488 form will remain as supplied.
1492 my %where = ( is_ready => \"", completed => { '>', '2012-12-21' } )
1494 $stmt = "WHERE completed > ? AND is_ready"
1495 @bind = ('2012-12-21')
1497 Using an empty string literal used to be the only way to express a boolean.
1498 For all new code please use the much more readable
1499 L<-bool|/Unary operators: bool> operator.
1505 These pages could go on for a while, since the nesting of the data
1506 structures this module can handle are pretty much unlimited (the
1507 module implements the C<WHERE> expansion as a recursive function
1508 internally). Your best bet is to "play around" with the module a
1509 little to see how the data structures behave, and choose the best
1510 format for your data based on that.
1512 And of course, all the values above will probably be replaced with
1513 variables gotten from forms or the command line. After all, if you
1514 knew everything ahead of time, you wouldn't have to worry about
1515 dynamically-generating SQL and could just hardwire it into your
1518 =head1 ORDER BY CLAUSES
1520 Some functions take an order by clause. This can either be a scalar (just a
1521 column name,) a hash of C<< { -desc => 'col' } >> or C<< { -asc => 'col' } >>,
1522 or an array of either of the two previous forms. Examples:
1524 Given | Will Generate
1525 ----------------------------------------------------------
1527 \'colA DESC' | ORDER BY colA DESC
1529 'colA' | ORDER BY colA
1531 [qw/colA colB/] | ORDER BY colA, colB
1533 {-asc => 'colA'} | ORDER BY colA ASC
1535 {-desc => 'colB'} | ORDER BY colB DESC
1537 ['colA', {-asc => 'colB'}] | ORDER BY colA, colB ASC
1539 { -asc => [qw/colA colB/] } | ORDER BY colA ASC, colB ASC
1542 { -asc => 'colA' }, | ORDER BY colA ASC, colB DESC,
1543 { -desc => [qw/colB/], | colC ASC, colD ASC
1544 { -asc => [qw/colC colD/],|
1546 ===========================================================
1550 =head1 SPECIAL OPERATORS
1552 my $sqlmaker = SQL::Abstract->new(special_ops => [
1556 my ($self, $field, $op, $arg) = @_;
1562 handler => 'method_name',
1566 A "special operator" is a SQL syntactic clause that can be
1567 applied to a field, instead of a usual binary operator.
1570 WHERE field IN (?, ?, ?)
1571 WHERE field BETWEEN ? AND ?
1572 WHERE MATCH(field) AGAINST (?, ?)
1574 Special operators IN and BETWEEN are fairly standard and therefore
1575 are builtin within C<SQL::Abstract> (as the overridable methods
1576 C<_where_field_IN> and C<_where_field_BETWEEN>). For other operators,
1577 like the MATCH .. AGAINST example above which is specific to MySQL,
1578 you can write your own operator handlers - supply a C<special_ops>
1579 argument to the C<new> method. That argument takes an arrayref of
1580 operator definitions; each operator definition is a hashref with two
1587 the regular expression to match the operator
1591 Either a coderef or a plain scalar method name. In both cases
1592 the expected return is C<< ($sql, @bind) >>.
1594 When supplied with a method name, it is simply called on the
1595 L<SQL::Abstract/> object as:
1597 $self->$method_name ($field, $op, $arg)
1601 $op is the part that matched the handler regex
1602 $field is the LHS of the operator
1605 When supplied with a coderef, it is called as:
1607 $coderef->($self, $field, $op, $arg)
1612 For example, here is an implementation
1613 of the MATCH .. AGAINST syntax for MySQL
1615 my $sqlmaker = SQL::Abstract->new(special_ops => [
1617 # special op for MySql MATCH (field) AGAINST(word1, word2, ...)
1618 {regex => qr/^match$/i,
1620 my ($self, $field, $op, $arg) = @_;
1621 $arg = [$arg] if not ref $arg;
1622 my $label = $self->_quote($field);
1623 my ($placeholder) = $self->_convert('?');
1624 my $placeholders = join ", ", (($placeholder) x @$arg);
1625 my $sql = $self->_sqlcase('match') . " ($label) "
1626 . $self->_sqlcase('against') . " ($placeholders) ";
1627 my @bind = $self->_bindtype($field, @$arg);
1628 return ($sql, @bind);
1635 =head1 UNARY OPERATORS
1637 my $sqlmaker = SQL::Abstract->new(unary_ops => [
1641 my ($self, $op, $arg) = @_;
1647 handler => 'method_name',
1651 A "unary operator" is a SQL syntactic clause that can be
1652 applied to a field - the operator goes before the field
1654 You can write your own operator handlers - supply a C<unary_ops>
1655 argument to the C<new> method. That argument takes an arrayref of
1656 operator definitions; each operator definition is a hashref with two
1663 the regular expression to match the operator
1667 Either a coderef or a plain scalar method name. In both cases
1668 the expected return is C<< $sql >>.
1670 When supplied with a method name, it is simply called on the
1671 L<SQL::Abstract/> object as:
1673 $self->$method_name ($op, $arg)
1677 $op is the part that matched the handler regex
1678 $arg is the RHS or argument of the operator
1680 When supplied with a coderef, it is called as:
1682 $coderef->($self, $op, $arg)
1690 Thanks to some benchmarking by Mark Stosberg, it turns out that
1691 this module is many orders of magnitude faster than using C<DBIx::Abstract>.
1692 I must admit this wasn't an intentional design issue, but it's a
1693 byproduct of the fact that you get to control your C<DBI> handles
1696 To maximize performance, use a code snippet like the following:
1698 # prepare a statement handle using the first row
1699 # and then reuse it for the rest of the rows
1701 for my $href (@array_of_hashrefs) {
1702 $stmt ||= $sql->insert('table', $href);
1703 $sth ||= $dbh->prepare($stmt);
1704 $sth->execute($sql->values($href));
1707 The reason this works is because the keys in your C<$href> are sorted
1708 internally by B<SQL::Abstract>. Thus, as long as your data retains
1709 the same structure, you only have to generate the SQL the first time
1710 around. On subsequent queries, simply use the C<values> function provided
1711 by this module to return your values in the correct order.
1713 However this depends on the values having the same type - if, for
1714 example, the values of a where clause may either have values
1715 (resulting in sql of the form C<column = ?> with a single bind
1716 value), or alternatively the values might be C<undef> (resulting in
1717 sql of the form C<column IS NULL> with no bind value) then the
1718 caching technique suggested will not work.
1722 If you use my C<CGI::FormBuilder> module at all, you'll hopefully
1723 really like this part (I do, at least). Building up a complex query
1724 can be as simple as the following:
1728 use CGI::FormBuilder;
1731 my $form = CGI::FormBuilder->new(...);
1732 my $sql = SQL::Abstract->new;
1734 if ($form->submitted) {
1735 my $field = $form->field;
1736 my $id = delete $field->{id};
1737 my($stmt, @bind) = $sql->update('table', $field, {id => $id});
1740 Of course, you would still have to connect using C<DBI> to run the
1741 query, but the point is that if you make your form look like your
1742 table, the actual query script can be extremely simplistic.
1744 If you're B<REALLY> lazy (I am), check out C<HTML::QuickTable> for
1745 a fast interface to returning and formatting data. I frequently
1746 use these three modules together to write complex database query
1747 apps in under 50 lines.
1753 =item * gitweb: L<http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/SQL-Abstract.git>
1755 =item * git: L<git://git.shadowcat.co.uk/dbsrgits/SQL-Abstract.git>
1761 Version 1.50 was a major internal refactoring of C<SQL::Abstract>.
1762 Great care has been taken to preserve the I<published> behavior
1763 documented in previous versions in the 1.* family; however,
1764 some features that were previously undocumented, or behaved
1765 differently from the documentation, had to be changed in order
1766 to clarify the semantics. Hence, client code that was relying
1767 on some dark areas of C<SQL::Abstract> v1.*
1768 B<might behave differently> in v1.50.
1770 The main changes are :
1776 support for literal SQL through the C<< \ [$sql, bind] >> syntax.
1780 support for the { operator => \"..." } construct (to embed literal SQL)
1784 support for the { operator => \["...", @bind] } construct (to embed literal SQL with bind values)
1788 optional support for L<array datatypes|/"Inserting and Updating Arrays">
1792 defensive programming : check arguments
1796 fixed bug with global logic, which was previously implemented
1797 through global variables yielding side-effects. Prior versions would
1798 interpret C<< [ {cond1, cond2}, [cond3, cond4] ] >>
1799 as C<< "(cond1 AND cond2) OR (cond3 AND cond4)" >>.
1800 Now this is interpreted
1801 as C<< "(cond1 AND cond2) OR (cond3 OR cond4)" >>.
1806 fixed semantics of _bindtype on array args
1810 dropped the C<_anoncopy> of the %where tree. No longer necessary,
1811 we just avoid shifting arrays within that tree.
1815 dropped the C<_modlogic> function
1819 =head1 ACKNOWLEDGEMENTS
1821 There are a number of individuals that have really helped out with
1822 this module. Unfortunately, most of them submitted bugs via CPAN
1823 so I have no idea who they are! But the people I do know are:
1825 Ash Berlin (order_by hash term support)
1826 Matt Trout (DBIx::Class support)
1827 Mark Stosberg (benchmarking)
1828 Chas Owens (initial "IN" operator support)
1829 Philip Collins (per-field SQL functions)
1830 Eric Kolve (hashref "AND" support)
1831 Mike Fragassi (enhancements to "BETWEEN" and "LIKE")
1832 Dan Kubb (support for "quote_char" and "name_sep")
1833 Guillermo Roditi (patch to cleanup "IN" and "BETWEEN", fix and tests for _order_by)
1834 Laurent Dami (internal refactoring, extensible list of special operators, literal SQL)
1835 Norbert Buchmuller (support for literal SQL in hashpair, misc. fixes & tests)
1836 Peter Rabbitson (rewrite of SQLA::Test, misc. fixes & tests)
1837 Oliver Charles (support for "RETURNING" after "INSERT")
1843 L<DBIx::Class>, L<DBIx::Abstract>, L<CGI::FormBuilder>, L<HTML::QuickTable>.
1847 Copyright (c) 2001-2007 Nathan Wiger <nwiger@cpan.org>. All Rights Reserved.
1849 This module is actively maintained by Matt Trout <mst@shadowcatsystems.co.uk>
1851 For support, your best bet is to try the C<DBIx::Class> users mailing list.
1852 While not an official support venue, C<DBIx::Class> makes heavy use of
1853 C<SQL::Abstract>, and as such list members there are very familiar with
1854 how to create queries.
1858 This module is free software; you may copy this under the same
1859 terms as perl itself (either the GNU General Public License or
1860 the Artistic License)