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 => 'rw', lazy => 1, builder => '_build_converter_class',
97 trigger => sub { shift->clear_converter },
100 sub _build_converter_class {
101 use_module('SQL::Abstract::Converter')
104 has renderer_class => (
105 is => 'rw', lazy => 1, builder => '_build_renderer_class',
106 trigger => sub { shift->clear_renderer },
109 sub _build_renderer_class {
110 use_module('Data::Query::Renderer::SQL::Naive')
113 sub _converter_args {
115 Scalar::Util::weaken($self);
117 lower_case => $self->case,
118 default_logic => $self->logic,
119 bind_meta => not($self->bindtype eq 'normal'),
120 identifier_sep => $self->name_sep,
121 (map +($_ => $self->$_), qw(
122 cmp sqltrue sqlfalse injection_guard convert array_datatypes
126 my $sub = $_->{handler};
129 handler => sub { $self->$sub(@_) }
131 } @{$self->special_ops}
133 renderer_will_quote => (
134 defined($self->quote_char) and $self->always_quote
139 sub _build_converter {
141 $self->converter_class->new($self->_converter_args);
147 for ($self->quote_char) {
148 $chars = defined() ? (ref() ? $_ : [$_]) : ['',''];
151 quote_chars => $chars, always_quote => $self->always_quote,
152 identifier_sep => $self->name_sep,
153 collapse_aliases => $self->collapse_aliases,
154 ($self->case ? (lc_keywords => 1) : ()), # always 'lower' if it exists
158 sub _build_renderer {
160 $self->renderer_class->new($self->_renderer_args);
164 my ($self, $dq) = @_;
168 my ($sql, @bind) = @{$self->renderer->render($dq)};
170 ($self->{bindtype} eq 'normal'
171 ? ($sql, map $_->{value}, @bind)
172 : ($sql, map [ $_->{value_meta}, $_->{value} ], @bind)
178 my ($self, $type, @args) = @_;
179 $self->_render_dq($self->converter->${\"_${type}_to_dq"}(@args));
182 sub insert { shift->_render_sqla(insert => @_) }
184 sub update { shift->_render_sqla(update => @_) }
186 sub select { shift->_render_sqla(select => @_) }
188 sub delete { shift->_render_sqla(delete => @_) }
191 my ($self, $where, $order) = @_;
197 ($sql, @bind) = $self->_recurse_where($where) if defined($where);
198 $sql = $sql ? $self->_sqlcase(' where ') . "( $sql )" : '';
202 $sql .= $self->_order_by($order);
205 return wantarray ? ($sql, @bind) : $sql;
208 sub _recurse_where { shift->_render_sqla(where => @_) }
211 my ($self, $arg) = @_;
212 if (my $dq = $self->converter->_order_by_to_dq($arg)) {
213 # SQLA generates ' ORDER BY foo'. The hilarity.
215 ? do { my @r = $self->_render_dq($dq); $r[0] = ' '.$r[0]; @r }
216 : ' '.$self->_render_dq($dq);
222 # highly optimized, as it's called way too often
224 # my ($self, $label) = @_;
226 return '' unless defined $_[1];
227 return ${$_[1]} if ref($_[1]) eq 'SCALAR';
229 unless ($_[0]->{quote_char}) {
230 $_[0]->_assert_pass_injection_guard($_[1]);
234 my $qref = ref $_[0]->{quote_char};
237 ($l, $r) = ( $_[0]->{quote_char}, $_[0]->{quote_char} );
239 elsif ($qref eq 'ARRAY') {
240 ($l, $r) = @{$_[0]->{quote_char}};
243 puke "Unsupported quote_char format: $_[0]->{quote_char}";
246 # parts containing * are naturally unquoted
247 return join( $_[0]->{name_sep}||'', map
248 { $_ eq '*' ? $_ : $l . $_ . $r }
249 ( $_[0]->{name_sep} ? split (/\Q$_[0]->{name_sep}\E/, $_[1] ) : $_[1] )
253 sub _assert_pass_injection_guard {
254 if ($_[1] =~ $_[0]->{injection_guard}) {
255 my $class = ref $_[0];
256 die "Possible SQL injection attempt '$_[1]'. If this is indeed a part of the
258 . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own
260 . "{injection_guard} attribute to ${class}->new()"
264 # Conversion, if applicable
266 #my ($self, $arg) = @_;
268 # LDNOTE : modified the previous implementation below because
269 # it was not consistent : the first "return" is always an array,
270 # the second "return" is context-dependent. Anyway, _convert
271 # seems always used with just a single argument, so make it a
273 # return @_ unless $self->{convert};
274 # my $conv = $self->_sqlcase($self->{convert});
275 # my @ret = map { $conv.'('.$_.')' } @_;
276 # return wantarray ? @ret : $ret[0];
277 if ($_[0]->{convert}) {
278 return $_[0]->_sqlcase($_[0]->{convert}) .'(' . $_[1] . ')';
285 #my ($self, $col, @vals) = @_;
287 #LDNOTE : changed original implementation below because it did not make
288 # sense when bindtype eq 'columns' and @vals > 1.
289 # return $self->{bindtype} eq 'columns' ? [ $col, @vals ] : @vals;
291 # called often - tighten code
292 return $_[0]->{bindtype} eq 'columns'
293 ? map {[$_[1], $_]} @_[2 .. $#_]
298 # Dies if any element of @bind is not in [colname => value] format
299 # if bindtype is 'columns'.
300 sub _assert_bindval_matches_bindtype {
301 # my ($self, @bind) = @_;
303 if ($self->{bindtype} eq 'columns') {
305 if (!defined $_ || ref($_) ne 'ARRAY' || @$_ != 2) {
306 puke "bindtype 'columns' selected, you need to pass: [column_name => bind_value]"
312 # Fix SQL case, if so requested
314 # LDNOTE: if $self->{case} is true, then it contains 'lower', so we
315 # don't touch the argument ... crooked logic, but let's not change it!
316 return $_[0]->{case} ? $_[1] : uc($_[1]);
321 my $data = shift || return;
322 puke "Argument to ", __PACKAGE__, "->values must be a \\%hash"
323 unless ref $data eq 'HASH';
326 foreach my $k ( sort keys %$data ) {
328 local our $Cur_Col_Meta = $k;
329 my ($sql, @bind) = $self->_render_sqla(
332 push @all_bind, @bind;
341 my(@sql, @sqlq, @sqlv);
345 if ($ref eq 'HASH') {
346 for my $k (sort keys %$_) {
349 my $label = $self->_quote($k);
351 # literal SQL with bind
352 my ($sql, @bind) = @$v;
353 $self->_assert_bindval_matches_bindtype(@bind);
354 push @sqlq, "$label = $sql";
356 } elsif ($r eq 'SCALAR') {
357 # literal SQL without bind
358 push @sqlq, "$label = $$v";
360 push @sqlq, "$label = ?";
361 push @sqlv, $self->_bindtype($k, $v);
364 push @sql, $self->_sqlcase('set'), join ', ', @sqlq;
365 } elsif ($ref eq 'ARRAY') {
366 # unlike insert(), assume these are ONLY the column names, i.e. for SQL
369 if ($r eq 'ARRAY') { # literal SQL with bind
370 my ($sql, @bind) = @$v;
371 $self->_assert_bindval_matches_bindtype(@bind);
374 } elsif ($r eq 'SCALAR') { # literal SQL without bind
375 # embedded literal SQL
382 push @sql, '(' . join(', ', @sqlq) . ')';
383 } elsif ($ref eq 'SCALAR') {
387 # strings get case twiddled
388 push @sql, $self->_sqlcase($_);
392 my $sql = join ' ', @sql;
394 # this is pretty tricky
395 # if ask for an array, return ($stmt, @bind)
396 # otherwise, s/?/shift @sqlv/ to put it inline
398 return ($sql, @sqlv);
400 1 while $sql =~ s/\?/my $d = shift(@sqlv);
401 ref $d ? $d->[1] : $d/e;
413 SQL::Abstract - Generate SQL from Perl data structures
419 my $sql = SQL::Abstract->new;
421 my($stmt, @bind) = $sql->select($table, \@fields, \%where, \@order);
423 my($stmt, @bind) = $sql->insert($table, \%fieldvals || \@values);
425 my($stmt, @bind) = $sql->update($table, \%fieldvals, \%where);
427 my($stmt, @bind) = $sql->delete($table, \%where);
429 # Then, use these in your DBI statements
430 my $sth = $dbh->prepare($stmt);
431 $sth->execute(@bind);
433 # Just generate the WHERE clause
434 my($stmt, @bind) = $sql->where(\%where, \@order);
436 # Return values in the same order, for hashed queries
437 # See PERFORMANCE section for more details
438 my @bind = $sql->values(\%fieldvals);
442 This module was inspired by the excellent L<DBIx::Abstract>.
443 However, in using that module I found that what I really wanted
444 to do was generate SQL, but still retain complete control over my
445 statement handles and use the DBI interface. So, I set out to
446 create an abstract SQL generation module.
448 While based on the concepts used by L<DBIx::Abstract>, there are
449 several important differences, especially when it comes to WHERE
450 clauses. I have modified the concepts used to make the SQL easier
451 to generate from Perl data structures and, IMO, more intuitive.
452 The underlying idea is for this module to do what you mean, based
453 on the data structures you provide it. The big advantage is that
454 you don't have to modify your code every time your data changes,
455 as this module figures it out.
457 To begin with, an SQL INSERT is as easy as just specifying a hash
458 of C<key=value> pairs:
461 name => 'Jimbo Bobson',
462 phone => '123-456-7890',
463 address => '42 Sister Lane',
465 state => 'Louisiana',
468 The SQL can then be generated with this:
470 my($stmt, @bind) = $sql->insert('people', \%data);
472 Which would give you something like this:
474 $stmt = "INSERT INTO people
475 (address, city, name, phone, state)
476 VALUES (?, ?, ?, ?, ?)";
477 @bind = ('42 Sister Lane', 'St. Louis', 'Jimbo Bobson',
478 '123-456-7890', 'Louisiana');
480 These are then used directly in your DBI code:
482 my $sth = $dbh->prepare($stmt);
483 $sth->execute(@bind);
485 =head2 Inserting and Updating Arrays
487 If your database has array types (like for example Postgres),
488 activate the special option C<< array_datatypes => 1 >>
489 when creating the C<SQL::Abstract> object.
490 Then you may use an arrayref to insert and update database array types:
492 my $sql = SQL::Abstract->new(array_datatypes => 1);
494 planets => [qw/Mercury Venus Earth Mars/]
497 my($stmt, @bind) = $sql->insert('solar_system', \%data);
501 $stmt = "INSERT INTO solar_system (planets) VALUES (?)"
503 @bind = (['Mercury', 'Venus', 'Earth', 'Mars']);
506 =head2 Inserting and Updating SQL
508 In order to apply SQL functions to elements of your C<%data> you may
509 specify a reference to an arrayref for the given hash value. For example,
510 if you need to execute the Oracle C<to_date> function on a value, you can
511 say something like this:
515 date_entered => \["to_date(?,'MM/DD/YYYY')", "03/02/2003"],
518 The first value in the array is the actual SQL. Any other values are
519 optional and would be included in the bind values array. This gives
522 my($stmt, @bind) = $sql->insert('people', \%data);
524 $stmt = "INSERT INTO people (name, date_entered)
525 VALUES (?, to_date(?,'MM/DD/YYYY'))";
526 @bind = ('Bill', '03/02/2003');
528 An UPDATE is just as easy, all you change is the name of the function:
530 my($stmt, @bind) = $sql->update('people', \%data);
532 Notice that your C<%data> isn't touched; the module will generate
533 the appropriately quirky SQL for you automatically. Usually you'll
534 want to specify a WHERE clause for your UPDATE, though, which is
535 where handling C<%where> hashes comes in handy...
537 =head2 Complex where statements
539 This module can generate pretty complicated WHERE statements
540 easily. For example, simple C<key=value> pairs are taken to mean
541 equality, and if you want to see if a field is within a set
542 of values, you can use an arrayref. Let's say we wanted to
543 SELECT some data based on this criteria:
547 worker => ['nwiger', 'rcwe', 'sfz'],
548 status => { '!=', 'completed' }
551 my($stmt, @bind) = $sql->select('tickets', '*', \%where);
553 The above would give you something like this:
555 $stmt = "SELECT * FROM tickets WHERE
556 ( requestor = ? ) AND ( status != ? )
557 AND ( worker = ? OR worker = ? OR worker = ? )";
558 @bind = ('inna', 'completed', 'nwiger', 'rcwe', 'sfz');
560 Which you could then use in DBI code like so:
562 my $sth = $dbh->prepare($stmt);
563 $sth->execute(@bind);
569 The functions are simple. There's one for each major SQL operation,
570 and a constructor you use first. The arguments are specified in a
571 similar order to each function (table, then fields, then a where
572 clause) to try and simplify things.
577 =head2 new(option => 'value')
579 The C<new()> function takes a list of options and values, and returns
580 a new B<SQL::Abstract> object which can then be used to generate SQL
581 through the methods below. The options accepted are:
587 If set to 'lower', then SQL will be generated in all lowercase. By
588 default SQL is generated in "textbook" case meaning something like:
590 SELECT a_field FROM a_table WHERE some_field LIKE '%someval%'
592 Any setting other than 'lower' is ignored.
596 This determines what the default comparison operator is. By default
597 it is C<=>, meaning that a hash like this:
599 %where = (name => 'nwiger', email => 'nate@wiger.org');
601 Will generate SQL like this:
603 WHERE name = 'nwiger' AND email = 'nate@wiger.org'
605 However, you may want loose comparisons by default, so if you set
606 C<cmp> to C<like> you would get SQL such as:
608 WHERE name like 'nwiger' AND email like 'nate@wiger.org'
610 You can also override the comparsion on an individual basis - see
611 the huge section on L</"WHERE CLAUSES"> at the bottom.
613 =item sqltrue, sqlfalse
615 Expressions for inserting boolean values within SQL statements.
616 By default these are C<1=1> and C<1=0>. They are used
617 by the special operators C<-in> and C<-not_in> for generating
618 correct SQL even when the argument is an empty array (see below).
622 This determines the default logical operator for multiple WHERE
623 statements in arrays or hashes. If absent, the default logic is "or"
624 for arrays, and "and" for hashes. This means that a WHERE
628 event_date => {'>=', '2/13/99'},
629 event_date => {'<=', '4/24/03'},
632 will generate SQL like this:
634 WHERE event_date >= '2/13/99' OR event_date <= '4/24/03'
636 This is probably not what you want given this query, though (look
637 at the dates). To change the "OR" to an "AND", simply specify:
639 my $sql = SQL::Abstract->new(logic => 'and');
641 Which will change the above C<WHERE> to:
643 WHERE event_date >= '2/13/99' AND event_date <= '4/24/03'
645 The logic can also be changed locally by inserting
646 a modifier in front of an arrayref :
648 @where = (-and => [event_date => {'>=', '2/13/99'},
649 event_date => {'<=', '4/24/03'} ]);
651 See the L</"WHERE CLAUSES"> section for explanations.
655 This will automatically convert comparisons using the specified SQL
656 function for both column and value. This is mostly used with an argument
657 of C<upper> or C<lower>, so that the SQL will have the effect of
658 case-insensitive "searches". For example, this:
660 $sql = SQL::Abstract->new(convert => 'upper');
661 %where = (keywords => 'MaKe iT CAse inSeNSItive');
663 Will turn out the following SQL:
665 WHERE upper(keywords) like upper('MaKe iT CAse inSeNSItive')
667 The conversion can be C<upper()>, C<lower()>, or any other SQL function
668 that can be applied symmetrically to fields (actually B<SQL::Abstract> does
669 not validate this option; it will just pass through what you specify verbatim).
673 This is a kludge because many databases suck. For example, you can't
674 just bind values using DBI's C<execute()> for Oracle C<CLOB> or C<BLOB> fields.
675 Instead, you have to use C<bind_param()>:
677 $sth->bind_param(1, 'reg data');
678 $sth->bind_param(2, $lots, {ora_type => ORA_CLOB});
680 The problem is, B<SQL::Abstract> will normally just return a C<@bind> array,
681 which loses track of which field each slot refers to. Fear not.
683 If you specify C<bindtype> in new, you can determine how C<@bind> is returned.
684 Currently, you can specify either C<normal> (default) or C<columns>. If you
685 specify C<columns>, you will get an array that looks like this:
687 my $sql = SQL::Abstract->new(bindtype => 'columns');
688 my($stmt, @bind) = $sql->insert(...);
691 [ 'column1', 'value1' ],
692 [ 'column2', 'value2' ],
693 [ 'column3', 'value3' ],
696 You can then iterate through this manually, using DBI's C<bind_param()>.
698 $sth->prepare($stmt);
701 my($col, $data) = @$_;
702 if ($col eq 'details' || $col eq 'comments') {
703 $sth->bind_param($i, $data, {ora_type => ORA_CLOB});
704 } elsif ($col eq 'image') {
705 $sth->bind_param($i, $data, {ora_type => ORA_BLOB});
707 $sth->bind_param($i, $data);
711 $sth->execute; # execute without @bind now
713 Now, why would you still use B<SQL::Abstract> if you have to do this crap?
714 Basically, the advantage is still that you don't have to care which fields
715 are or are not included. You could wrap that above C<for> loop in a simple
716 sub called C<bind_fields()> or something and reuse it repeatedly. You still
717 get a layer of abstraction over manual SQL specification.
719 Note that if you set L</bindtype> to C<columns>, the C<\[$sql, @bind]>
720 construct (see L</Literal SQL with placeholders and bind values (subqueries)>)
721 will expect the bind values in this format.
725 This is the character that a table or column name will be quoted
726 with. By default this is an empty string, but you could set it to
727 the character C<`>, to generate SQL like this:
729 SELECT `a_field` FROM `a_table` WHERE `some_field` LIKE '%someval%'
731 Alternatively, you can supply an array ref of two items, the first being the left
732 hand quote character, and the second the right hand quote character. For
733 example, you could supply C<['[',']']> for SQL Server 2000 compliant quotes
734 that generates SQL like this:
736 SELECT [a_field] FROM [a_table] WHERE [some_field] LIKE '%someval%'
738 Quoting is useful if you have tables or columns names that are reserved
739 words in your database's SQL dialect.
743 This is the character that separates a table and column name. It is
744 necessary to specify this when the C<quote_char> option is selected,
745 so that tables and column names can be individually quoted like this:
747 SELECT `table`.`one_field` FROM `table` WHERE `table`.`other_field` = 1
749 =item injection_guard
751 A regular expression C<qr/.../> that is applied to any C<-function> and unquoted
752 column name specified in a query structure. This is a safety mechanism to avoid
753 injection attacks when mishandling user input e.g.:
755 my %condition_as_column_value_pairs = get_values_from_user();
756 $sqla->select( ... , \%condition_as_column_value_pairs );
758 If the expression matches an exception is thrown. Note that literal SQL
759 supplied via C<\'...'> or C<\['...']> is B<not> checked in any way.
761 Defaults to checking for C<;> and the C<GO> keyword (TransactSQL)
763 =item array_datatypes
765 When this option is true, arrayrefs in INSERT or UPDATE are
766 interpreted as array datatypes and are passed directly
768 When this option is false, arrayrefs are interpreted
769 as literal SQL, just like refs to arrayrefs
770 (but this behavior is for backwards compatibility; when writing
771 new queries, use the "reference to arrayref" syntax
777 Takes a reference to a list of "special operators"
778 to extend the syntax understood by L<SQL::Abstract>.
779 See section L</"SPECIAL OPERATORS"> for details.
783 Takes a reference to a list of "unary operators"
784 to extend the syntax understood by L<SQL::Abstract>.
785 See section L</"UNARY OPERATORS"> for details.
791 =head2 insert($table, \@values || \%fieldvals, \%options)
793 This is the simplest function. You simply give it a table name
794 and either an arrayref of values or hashref of field/value pairs.
795 It returns an SQL INSERT statement and a list of bind values.
796 See the sections on L</"Inserting and Updating Arrays"> and
797 L</"Inserting and Updating SQL"> for information on how to insert
798 with those data types.
800 The optional C<\%options> hash reference may contain additional
801 options to generate the insert SQL. Currently supported options
808 Takes either a scalar of raw SQL fields, or an array reference of
809 field names, and adds on an SQL C<RETURNING> statement at the end.
810 This allows you to return data generated by the insert statement
811 (such as row IDs) without performing another C<SELECT> statement.
812 Note, however, this is not part of the SQL standard and may not
813 be supported by all database engines.
817 =head2 update($table, \%fieldvals, \%where)
819 This takes a table, hashref of field/value pairs, and an optional
820 hashref L<WHERE clause|/WHERE CLAUSES>. It returns an SQL UPDATE function and a list
822 See the sections on L</"Inserting and Updating Arrays"> and
823 L</"Inserting and Updating SQL"> for information on how to insert
824 with those data types.
826 =head2 select($source, $fields, $where, $order)
828 This returns a SQL SELECT statement and associated list of bind values, as
829 specified by the arguments :
835 Specification of the 'FROM' part of the statement.
836 The argument can be either a plain scalar (interpreted as a table
837 name, will be quoted), or an arrayref (interpreted as a list
838 of table names, joined by commas, quoted), or a scalarref
839 (literal table name, not quoted), or a ref to an arrayref
840 (list of literal table names, joined by commas, not quoted).
844 Specification of the list of fields to retrieve from
846 The argument can be either an arrayref (interpreted as a list
847 of field names, will be joined by commas and quoted), or a
848 plain scalar (literal SQL, not quoted).
849 Please observe that this API is not as flexible as for
850 the first argument C<$table>, for backwards compatibility reasons.
854 Optional argument to specify the WHERE part of the query.
855 The argument is most often a hashref, but can also be
856 an arrayref or plain scalar --
857 see section L<WHERE clause|/"WHERE CLAUSES"> for details.
861 Optional argument to specify the ORDER BY part of the query.
862 The argument can be a scalar, a hashref or an arrayref
863 -- see section L<ORDER BY clause|/"ORDER BY CLAUSES">
869 =head2 delete($table, \%where)
871 This takes a table name and optional hashref L<WHERE clause|/WHERE CLAUSES>.
872 It returns an SQL DELETE statement and list of bind values.
874 =head2 where(\%where, \@order)
876 This is used to generate just the WHERE clause. For example,
877 if you have an arbitrary data structure and know what the
878 rest of your SQL is going to look like, but want an easy way
879 to produce a WHERE clause, use this. It returns an SQL WHERE
880 clause and list of bind values.
883 =head2 values(\%data)
885 This just returns the values from the hash C<%data>, in the same
886 order that would be returned from any of the other above queries.
887 Using this allows you to markedly speed up your queries if you
888 are affecting lots of rows. See below under the L</"PERFORMANCE"> section.
890 =head2 generate($any, 'number', $of, \@data, $struct, \%types)
892 Warning: This is an experimental method and subject to change.
894 This returns arbitrarily generated SQL. It's a really basic shortcut.
895 It will return two different things, depending on return context:
897 my($stmt, @bind) = $sql->generate('create table', \$table, \@fields);
898 my $stmt_and_val = $sql->generate('create table', \$table, \@fields);
900 These would return the following:
903 $stmt = "CREATE TABLE test (?, ?)";
904 @bind = (field1, field2);
906 # Second calling form
907 $stmt_and_val = "CREATE TABLE test (field1, field2)";
909 Depending on what you're trying to do, it's up to you to choose the correct
910 format. In this example, the second form is what you would want.
914 $sql->generate('alter session', { nls_date_format => 'MM/YY' });
918 ALTER SESSION SET nls_date_format = 'MM/YY'
920 You get the idea. Strings get their case twiddled, but everything
921 else remains verbatim.
927 This module uses a variation on the idea from L<DBIx::Abstract>. It
928 is B<NOT>, repeat I<not> 100% compatible. B<The main logic of this
929 module is that things in arrays are OR'ed, and things in hashes
932 The easiest way to explain is to show lots of examples. After
933 each C<%where> hash shown, it is assumed you used:
935 my($stmt, @bind) = $sql->where(\%where);
937 However, note that the C<%where> hash can be used directly in any
938 of the other functions as well, as described above.
940 =head2 Key-value pairs
942 So, let's get started. To begin, a simple hash:
946 status => 'completed'
949 Is converted to SQL C<key = val> statements:
951 $stmt = "WHERE user = ? AND status = ?";
952 @bind = ('nwiger', 'completed');
954 One common thing I end up doing is having a list of values that
955 a field can be in. To do this, simply specify a list inside of
960 status => ['assigned', 'in-progress', 'pending'];
963 This simple code will create the following:
965 $stmt = "WHERE user = ? AND ( status = ? OR status = ? OR status = ? )";
966 @bind = ('nwiger', 'assigned', 'in-progress', 'pending');
968 A field associated to an empty arrayref will be considered a
969 logical false and will generate 0=1.
971 =head2 Tests for NULL values
973 If the value part is C<undef> then this is converted to SQL <IS NULL>
982 $stmt = "WHERE user = ? AND status IS NULL";
985 To test if a column IS NOT NULL:
989 status => { '!=', undef },
992 =head2 Specific comparison operators
994 If you want to specify a different type of operator for your comparison,
995 you can use a hashref for a given column:
999 status => { '!=', 'completed' }
1002 Which would generate:
1004 $stmt = "WHERE user = ? AND status != ?";
1005 @bind = ('nwiger', 'completed');
1007 To test against multiple values, just enclose the values in an arrayref:
1009 status => { '=', ['assigned', 'in-progress', 'pending'] };
1011 Which would give you:
1013 "WHERE status = ? OR status = ? OR status = ?"
1016 The hashref can also contain multiple pairs, in which case it is expanded
1017 into an C<AND> of its elements:
1021 status => { '!=', 'completed', -not_like => 'pending%' }
1024 # Or more dynamically, like from a form
1025 $where{user} = 'nwiger';
1026 $where{status}{'!='} = 'completed';
1027 $where{status}{'-not_like'} = 'pending%';
1029 # Both generate this
1030 $stmt = "WHERE user = ? AND status != ? AND status NOT LIKE ?";
1031 @bind = ('nwiger', 'completed', 'pending%');
1034 To get an OR instead, you can combine it with the arrayref idea:
1038 priority => [ { '=', 2 }, { '>', 5 } ]
1041 Which would generate:
1043 $stmt = "WHERE ( priority = ? OR priority > ? ) AND user = ?";
1044 @bind = ('2', '5', 'nwiger');
1046 If you want to include literal SQL (with or without bind values), just use a
1047 scalar reference or array reference as the value:
1050 date_entered => { '>' => \["to_date(?, 'MM/DD/YYYY')", "11/26/2008"] },
1051 date_expires => { '<' => \"now()" }
1054 Which would generate:
1056 $stmt = "WHERE date_entered > "to_date(?, 'MM/DD/YYYY') AND date_expires < now()";
1057 @bind = ('11/26/2008');
1060 =head2 Logic and nesting operators
1062 In the example above,
1063 there is a subtle trap if you want to say something like
1064 this (notice the C<AND>):
1066 WHERE priority != ? AND priority != ?
1068 Because, in Perl you I<can't> do this:
1070 priority => { '!=', 2, '!=', 1 }
1072 As the second C<!=> key will obliterate the first. The solution
1073 is to use the special C<-modifier> form inside an arrayref:
1075 priority => [ -and => {'!=', 2},
1079 Normally, these would be joined by C<OR>, but the modifier tells it
1080 to use C<AND> instead. (Hint: You can use this in conjunction with the
1081 C<logic> option to C<new()> in order to change the way your queries
1082 work by default.) B<Important:> Note that the C<-modifier> goes
1083 B<INSIDE> the arrayref, as an extra first element. This will
1084 B<NOT> do what you think it might:
1086 priority => -and => [{'!=', 2}, {'!=', 1}] # WRONG!
1088 Here is a quick list of equivalencies, since there is some overlap:
1091 status => {'!=', 'completed', 'not like', 'pending%' }
1092 status => [ -and => {'!=', 'completed'}, {'not like', 'pending%'}]
1095 status => {'=', ['assigned', 'in-progress']}
1096 status => [ -or => {'=', 'assigned'}, {'=', 'in-progress'}]
1097 status => [ {'=', 'assigned'}, {'=', 'in-progress'} ]
1101 =head2 Special operators : IN, BETWEEN, etc.
1103 You can also use the hashref format to compare a list of fields using the
1104 C<IN> comparison operator, by specifying the list as an arrayref:
1107 status => 'completed',
1108 reportid => { -in => [567, 2335, 2] }
1111 Which would generate:
1113 $stmt = "WHERE status = ? AND reportid IN (?,?,?)";
1114 @bind = ('completed', '567', '2335', '2');
1116 The reverse operator C<-not_in> generates SQL C<NOT IN> and is used in
1119 If the argument to C<-in> is an empty array, 'sqlfalse' is generated
1120 (by default : C<1=0>). Similarly, C<< -not_in => [] >> generates
1121 'sqltrue' (by default : C<1=1>).
1123 In addition to the array you can supply a chunk of literal sql or
1124 literal sql with bind:
1127 customer => { -in => \[
1128 'SELECT cust_id FROM cust WHERE balance > ?',
1131 status => { -in => \'SELECT status_codes FROM states' },
1137 customer IN ( SELECT cust_id FROM cust WHERE balance > ? )
1138 AND status IN ( SELECT status_codes FROM states )
1144 Another pair of operators is C<-between> and C<-not_between>,
1145 used with an arrayref of two values:
1149 completion_date => {
1150 -not_between => ['2002-10-01', '2003-02-06']
1156 WHERE user = ? AND completion_date NOT BETWEEN ( ? AND ? )
1158 Just like with C<-in> all plausible combinations of literal SQL
1162 start0 => { -between => [ 1, 2 ] },
1163 start1 => { -between => \["? AND ?", 1, 2] },
1164 start2 => { -between => \"lower(x) AND upper(y)" },
1165 start3 => { -between => [
1167 \["upper(?)", 'stuff' ],
1174 ( start0 BETWEEN ? AND ? )
1175 AND ( start1 BETWEEN ? AND ? )
1176 AND ( start2 BETWEEN lower(x) AND upper(y) )
1177 AND ( start3 BETWEEN lower(x) AND upper(?) )
1179 @bind = (1, 2, 1, 2, 'stuff');
1182 These are the two builtin "special operators"; but the
1183 list can be expanded : see section L</"SPECIAL OPERATORS"> below.
1185 =head2 Unary operators: bool
1187 If you wish to test against boolean columns or functions within your
1188 database you can use the C<-bool> and C<-not_bool> operators. For
1189 example to test the column C<is_user> being true and the column
1190 C<is_enabled> being false you would use:-
1194 -not_bool => 'is_enabled',
1199 WHERE is_user AND NOT is_enabled
1201 If a more complex combination is required, testing more conditions,
1202 then you should use the and/or operators:-
1209 -not_bool => 'four',
1215 WHERE one AND two AND three AND NOT four
1218 =head2 Nested conditions, -and/-or prefixes
1220 So far, we've seen how multiple conditions are joined with a top-level
1221 C<AND>. We can change this by putting the different conditions we want in
1222 hashes and then putting those hashes in an array. For example:
1227 status => { -like => ['pending%', 'dispatched'] },
1231 status => 'unassigned',
1235 This data structure would create the following:
1237 $stmt = "WHERE ( user = ? AND ( status LIKE ? OR status LIKE ? ) )
1238 OR ( user = ? AND status = ? ) )";
1239 @bind = ('nwiger', 'pending', 'dispatched', 'robot', 'unassigned');
1242 Clauses in hashrefs or arrayrefs can be prefixed with an C<-and> or C<-or>
1243 to change the logic inside :
1249 -and => [ workhrs => {'>', 20}, geo => 'ASIA' ],
1250 -or => { workhrs => {'<', 50}, geo => 'EURO' },
1257 WHERE ( user = ? AND (
1258 ( workhrs > ? AND geo = ? )
1259 OR ( workhrs < ? OR geo = ? )
1262 =head3 Algebraic inconsistency, for historical reasons
1264 C<Important note>: when connecting several conditions, the C<-and->|C<-or>
1265 operator goes C<outside> of the nested structure; whereas when connecting
1266 several constraints on one column, the C<-and> operator goes
1267 C<inside> the arrayref. Here is an example combining both features :
1270 -and => [a => 1, b => 2],
1271 -or => [c => 3, d => 4],
1272 e => [-and => {-like => 'foo%'}, {-like => '%bar'} ]
1277 WHERE ( ( ( a = ? AND b = ? )
1278 OR ( c = ? OR d = ? )
1279 OR ( e LIKE ? AND e LIKE ? ) ) )
1281 This difference in syntax is unfortunate but must be preserved for
1282 historical reasons. So be careful : the two examples below would
1283 seem algebraically equivalent, but they are not
1285 {col => [-and => {-like => 'foo%'}, {-like => '%bar'}]}
1286 # yields : WHERE ( ( col LIKE ? AND col LIKE ? ) )
1288 [-and => {col => {-like => 'foo%'}, {col => {-like => '%bar'}}]]
1289 # yields : WHERE ( ( col LIKE ? OR col LIKE ? ) )
1292 =head2 Literal SQL and value type operators
1294 The basic premise of SQL::Abstract is that in WHERE specifications the "left
1295 side" is a column name and the "right side" is a value (normally rendered as
1296 a placeholder). This holds true for both hashrefs and arrayref pairs as you
1297 see in the L</WHERE CLAUSES> examples above. Sometimes it is necessary to
1298 alter this behavior. There are several ways of doing so.
1302 This is a virtual operator that signals the string to its right side is an
1303 identifier (a column name) and not a value. For example to compare two
1304 columns you would write:
1307 priority => { '<', 2 },
1308 requestor => { -ident => 'submitter' },
1313 $stmt = "WHERE priority < ? AND requestor = submitter";
1316 If you are maintaining legacy code you may see a different construct as
1317 described in L</Deprecated usage of Literal SQL>, please use C<-ident> in new
1322 This is a virtual operator that signals that the construct to its right side
1323 is a value to be passed to DBI. This is for example necessary when you want
1324 to write a where clause against an array (for RDBMS that support such
1325 datatypes). For example:
1328 array => { -value => [1, 2, 3] }
1333 $stmt = 'WHERE array = ?';
1334 @bind = ([1, 2, 3]);
1336 Note that if you were to simply say:
1342 the result would porbably be not what you wanted:
1344 $stmt = 'WHERE array = ? OR array = ? OR array = ?';
1349 Finally, sometimes only literal SQL will do. To include a random snippet
1350 of SQL verbatim, you specify it as a scalar reference. Consider this only
1351 as a last resort. Usually there is a better way. For example:
1354 priority => { '<', 2 },
1355 requestor => { -in => \'(SELECT name FROM hitmen)' },
1360 $stmt = "WHERE priority < ? AND requestor IN (SELECT name FROM hitmen)"
1363 Note that in this example, you only get one bind parameter back, since
1364 the verbatim SQL is passed as part of the statement.
1368 Never use untrusted input as a literal SQL argument - this is a massive
1369 security risk (there is no way to check literal snippets for SQL
1370 injections and other nastyness). If you need to deal with untrusted input
1371 use literal SQL with placeholders as described next.
1373 =head3 Literal SQL with placeholders and bind values (subqueries)
1375 If the literal SQL to be inserted has placeholders and bind values,
1376 use a reference to an arrayref (yes this is a double reference --
1377 not so common, but perfectly legal Perl). For example, to find a date
1378 in Postgres you can use something like this:
1381 date_column => \[q/= date '2008-09-30' - ?::integer/, 10/]
1386 $stmt = "WHERE ( date_column = date '2008-09-30' - ?::integer )"
1389 Note that you must pass the bind values in the same format as they are returned
1390 by L</where>. That means that if you set L</bindtype> to C<columns>, you must
1391 provide the bind values in the C<< [ column_meta => value ] >> format, where
1392 C<column_meta> is an opaque scalar value; most commonly the column name, but
1393 you can use any scalar value (including references and blessed references),
1394 L<SQL::Abstract> will simply pass it through intact. So if C<bindtype> is set
1395 to C<columns> the above example will look like:
1398 date_column => \[q/= date '2008-09-30' - ?::integer/, [ dummy => 10 ]/]
1401 Literal SQL is especially useful for nesting parenthesized clauses in the
1402 main SQL query. Here is a first example :
1404 my ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
1408 bar => \["IN ($sub_stmt)" => @sub_bind],
1413 $stmt = "WHERE (foo = ? AND bar IN (SELECT c1 FROM t1
1414 WHERE c2 < ? AND c3 LIKE ?))";
1415 @bind = (1234, 100, "foo%");
1417 Other subquery operators, like for example C<"E<gt> ALL"> or C<"NOT IN">,
1418 are expressed in the same way. Of course the C<$sub_stmt> and
1419 its associated bind values can be generated through a former call
1422 my ($sub_stmt, @sub_bind)
1423 = $sql->select("t1", "c1", {c2 => {"<" => 100},
1424 c3 => {-like => "foo%"}});
1427 bar => \["> ALL ($sub_stmt)" => @sub_bind],
1430 In the examples above, the subquery was used as an operator on a column;
1431 but the same principle also applies for a clause within the main C<%where>
1432 hash, like an EXISTS subquery :
1434 my ($sub_stmt, @sub_bind)
1435 = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
1436 my %where = ( -and => [
1438 \["EXISTS ($sub_stmt)" => @sub_bind],
1443 $stmt = "WHERE (foo = ? AND EXISTS (SELECT * FROM t1
1444 WHERE c1 = ? AND c2 > t0.c0))";
1448 Observe that the condition on C<c2> in the subquery refers to
1449 column C<t0.c0> of the main query : this is I<not> a bind
1450 value, so we have to express it through a scalar ref.
1451 Writing C<< c2 => {">" => "t0.c0"} >> would have generated
1452 C<< c2 > ? >> with bind value C<"t0.c0"> ... not exactly
1453 what we wanted here.
1455 Finally, here is an example where a subquery is used
1456 for expressing unary negation:
1458 my ($sub_stmt, @sub_bind)
1459 = $sql->where({age => [{"<" => 10}, {">" => 20}]});
1460 $sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
1462 lname => {like => '%son%'},
1463 \["NOT ($sub_stmt)" => @sub_bind],
1468 $stmt = "lname LIKE ? AND NOT ( age < ? OR age > ? )"
1469 @bind = ('%son%', 10, 20)
1471 =head3 Deprecated usage of Literal SQL
1473 Below are some examples of archaic use of literal SQL. It is shown only as
1474 reference for those who deal with legacy code. Each example has a much
1475 better, cleaner and safer alternative that users should opt for in new code.
1481 my %where = ( requestor => \'IS NOT NULL' )
1483 $stmt = "WHERE requestor IS NOT NULL"
1485 This used to be the way of generating NULL comparisons, before the handling
1486 of C<undef> got formalized. For new code please use the superior syntax as
1487 described in L</Tests for NULL values>.
1491 my %where = ( requestor => \'= submitter' )
1493 $stmt = "WHERE requestor = submitter"
1495 This used to be the only way to compare columns. Use the superior L</-ident>
1496 method for all new code. For example an identifier declared in such a way
1497 will be properly quoted if L</quote_char> is properly set, while the legacy
1498 form will remain as supplied.
1502 my %where = ( is_ready => \"", completed => { '>', '2012-12-21' } )
1504 $stmt = "WHERE completed > ? AND is_ready"
1505 @bind = ('2012-12-21')
1507 Using an empty string literal used to be the only way to express a boolean.
1508 For all new code please use the much more readable
1509 L<-bool|/Unary operators: bool> operator.
1515 These pages could go on for a while, since the nesting of the data
1516 structures this module can handle are pretty much unlimited (the
1517 module implements the C<WHERE> expansion as a recursive function
1518 internally). Your best bet is to "play around" with the module a
1519 little to see how the data structures behave, and choose the best
1520 format for your data based on that.
1522 And of course, all the values above will probably be replaced with
1523 variables gotten from forms or the command line. After all, if you
1524 knew everything ahead of time, you wouldn't have to worry about
1525 dynamically-generating SQL and could just hardwire it into your
1528 =head1 ORDER BY CLAUSES
1530 Some functions take an order by clause. This can either be a scalar (just a
1531 column name,) a hash of C<< { -desc => 'col' } >> or C<< { -asc => 'col' } >>,
1532 or an array of either of the two previous forms. Examples:
1534 Given | Will Generate
1535 ----------------------------------------------------------
1537 \'colA DESC' | ORDER BY colA DESC
1539 'colA' | ORDER BY colA
1541 [qw/colA colB/] | ORDER BY colA, colB
1543 {-asc => 'colA'} | ORDER BY colA ASC
1545 {-desc => 'colB'} | ORDER BY colB DESC
1547 ['colA', {-asc => 'colB'}] | ORDER BY colA, colB ASC
1549 { -asc => [qw/colA colB/] } | ORDER BY colA ASC, colB ASC
1552 { -asc => 'colA' }, | ORDER BY colA ASC, colB DESC,
1553 { -desc => [qw/colB/], | colC ASC, colD ASC
1554 { -asc => [qw/colC colD/],|
1556 ===========================================================
1560 =head1 SPECIAL OPERATORS
1562 my $sqlmaker = SQL::Abstract->new(special_ops => [
1566 my ($self, $field, $op, $arg) = @_;
1572 handler => 'method_name',
1576 A "special operator" is a SQL syntactic clause that can be
1577 applied to a field, instead of a usual binary operator.
1580 WHERE field IN (?, ?, ?)
1581 WHERE field BETWEEN ? AND ?
1582 WHERE MATCH(field) AGAINST (?, ?)
1584 Special operators IN and BETWEEN are fairly standard and therefore
1585 are builtin within C<SQL::Abstract> (as the overridable methods
1586 C<_where_field_IN> and C<_where_field_BETWEEN>). For other operators,
1587 like the MATCH .. AGAINST example above which is specific to MySQL,
1588 you can write your own operator handlers - supply a C<special_ops>
1589 argument to the C<new> method. That argument takes an arrayref of
1590 operator definitions; each operator definition is a hashref with two
1597 the regular expression to match the operator
1601 Either a coderef or a plain scalar method name. In both cases
1602 the expected return is C<< ($sql, @bind) >>.
1604 When supplied with a method name, it is simply called on the
1605 L<SQL::Abstract/> object as:
1607 $self->$method_name ($field, $op, $arg)
1611 $op is the part that matched the handler regex
1612 $field is the LHS of the operator
1615 When supplied with a coderef, it is called as:
1617 $coderef->($self, $field, $op, $arg)
1622 For example, here is an implementation
1623 of the MATCH .. AGAINST syntax for MySQL
1625 my $sqlmaker = SQL::Abstract->new(special_ops => [
1627 # special op for MySql MATCH (field) AGAINST(word1, word2, ...)
1628 {regex => qr/^match$/i,
1630 my ($self, $field, $op, $arg) = @_;
1631 $arg = [$arg] if not ref $arg;
1632 my $label = $self->_quote($field);
1633 my ($placeholder) = $self->_convert('?');
1634 my $placeholders = join ", ", (($placeholder) x @$arg);
1635 my $sql = $self->_sqlcase('match') . " ($label) "
1636 . $self->_sqlcase('against') . " ($placeholders) ";
1637 my @bind = $self->_bindtype($field, @$arg);
1638 return ($sql, @bind);
1645 =head1 UNARY OPERATORS
1647 my $sqlmaker = SQL::Abstract->new(unary_ops => [
1651 my ($self, $op, $arg) = @_;
1657 handler => 'method_name',
1661 A "unary operator" is a SQL syntactic clause that can be
1662 applied to a field - the operator goes before the field
1664 You can write your own operator handlers - supply a C<unary_ops>
1665 argument to the C<new> method. That argument takes an arrayref of
1666 operator definitions; each operator definition is a hashref with two
1673 the regular expression to match the operator
1677 Either a coderef or a plain scalar method name. In both cases
1678 the expected return is C<< $sql >>.
1680 When supplied with a method name, it is simply called on the
1681 L<SQL::Abstract/> object as:
1683 $self->$method_name ($op, $arg)
1687 $op is the part that matched the handler regex
1688 $arg is the RHS or argument of the operator
1690 When supplied with a coderef, it is called as:
1692 $coderef->($self, $op, $arg)
1700 Thanks to some benchmarking by Mark Stosberg, it turns out that
1701 this module is many orders of magnitude faster than using C<DBIx::Abstract>.
1702 I must admit this wasn't an intentional design issue, but it's a
1703 byproduct of the fact that you get to control your C<DBI> handles
1706 To maximize performance, use a code snippet like the following:
1708 # prepare a statement handle using the first row
1709 # and then reuse it for the rest of the rows
1711 for my $href (@array_of_hashrefs) {
1712 $stmt ||= $sql->insert('table', $href);
1713 $sth ||= $dbh->prepare($stmt);
1714 $sth->execute($sql->values($href));
1717 The reason this works is because the keys in your C<$href> are sorted
1718 internally by B<SQL::Abstract>. Thus, as long as your data retains
1719 the same structure, you only have to generate the SQL the first time
1720 around. On subsequent queries, simply use the C<values> function provided
1721 by this module to return your values in the correct order.
1723 However this depends on the values having the same type - if, for
1724 example, the values of a where clause may either have values
1725 (resulting in sql of the form C<column = ?> with a single bind
1726 value), or alternatively the values might be C<undef> (resulting in
1727 sql of the form C<column IS NULL> with no bind value) then the
1728 caching technique suggested will not work.
1732 If you use my C<CGI::FormBuilder> module at all, you'll hopefully
1733 really like this part (I do, at least). Building up a complex query
1734 can be as simple as the following:
1738 use CGI::FormBuilder;
1741 my $form = CGI::FormBuilder->new(...);
1742 my $sql = SQL::Abstract->new;
1744 if ($form->submitted) {
1745 my $field = $form->field;
1746 my $id = delete $field->{id};
1747 my($stmt, @bind) = $sql->update('table', $field, {id => $id});
1750 Of course, you would still have to connect using C<DBI> to run the
1751 query, but the point is that if you make your form look like your
1752 table, the actual query script can be extremely simplistic.
1754 If you're B<REALLY> lazy (I am), check out C<HTML::QuickTable> for
1755 a fast interface to returning and formatting data. I frequently
1756 use these three modules together to write complex database query
1757 apps in under 50 lines.
1763 =item * gitweb: L<http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/SQL-Abstract.git>
1765 =item * git: L<git://git.shadowcat.co.uk/dbsrgits/SQL-Abstract.git>
1771 Version 1.50 was a major internal refactoring of C<SQL::Abstract>.
1772 Great care has been taken to preserve the I<published> behavior
1773 documented in previous versions in the 1.* family; however,
1774 some features that were previously undocumented, or behaved
1775 differently from the documentation, had to be changed in order
1776 to clarify the semantics. Hence, client code that was relying
1777 on some dark areas of C<SQL::Abstract> v1.*
1778 B<might behave differently> in v1.50.
1780 The main changes are :
1786 support for literal SQL through the C<< \ [$sql, bind] >> syntax.
1790 support for the { operator => \"..." } construct (to embed literal SQL)
1794 support for the { operator => \["...", @bind] } construct (to embed literal SQL with bind values)
1798 optional support for L<array datatypes|/"Inserting and Updating Arrays">
1802 defensive programming : check arguments
1806 fixed bug with global logic, which was previously implemented
1807 through global variables yielding side-effects. Prior versions would
1808 interpret C<< [ {cond1, cond2}, [cond3, cond4] ] >>
1809 as C<< "(cond1 AND cond2) OR (cond3 AND cond4)" >>.
1810 Now this is interpreted
1811 as C<< "(cond1 AND cond2) OR (cond3 OR cond4)" >>.
1816 fixed semantics of _bindtype on array args
1820 dropped the C<_anoncopy> of the %where tree. No longer necessary,
1821 we just avoid shifting arrays within that tree.
1825 dropped the C<_modlogic> function
1829 =head1 ACKNOWLEDGEMENTS
1831 There are a number of individuals that have really helped out with
1832 this module. Unfortunately, most of them submitted bugs via CPAN
1833 so I have no idea who they are! But the people I do know are:
1835 Ash Berlin (order_by hash term support)
1836 Matt Trout (DBIx::Class support)
1837 Mark Stosberg (benchmarking)
1838 Chas Owens (initial "IN" operator support)
1839 Philip Collins (per-field SQL functions)
1840 Eric Kolve (hashref "AND" support)
1841 Mike Fragassi (enhancements to "BETWEEN" and "LIKE")
1842 Dan Kubb (support for "quote_char" and "name_sep")
1843 Guillermo Roditi (patch to cleanup "IN" and "BETWEEN", fix and tests for _order_by)
1844 Laurent Dami (internal refactoring, extensible list of special operators, literal SQL)
1845 Norbert Buchmuller (support for literal SQL in hashpair, misc. fixes & tests)
1846 Peter Rabbitson (rewrite of SQLA::Test, misc. fixes & tests)
1847 Oliver Charles (support for "RETURNING" after "INSERT")
1853 L<DBIx::Class>, L<DBIx::Abstract>, L<CGI::FormBuilder>, L<HTML::QuickTable>.
1857 Copyright (c) 2001-2007 Nathan Wiger <nwiger@cpan.org>. All Rights Reserved.
1859 This module is actively maintained by Matt Trout <mst@shadowcatsystems.co.uk>
1861 For support, your best bet is to try the C<DBIx::Class> users mailing list.
1862 While not an official support venue, C<DBIx::Class> makes heavy use of
1863 C<SQL::Abstract>, and as such list members there are very familiar with
1864 how to create queries.
1868 This module is free software; you may copy this under the same
1869 terms as perl itself (either the GNU General Public License or
1870 the Artistic License)