1 package SQL::Abstract; # see doc at end of file
6 use Module::Runtime qw(use_module);
10 our $VERSION = '1.72';
12 $VERSION = eval $VERSION;
15 my($func) = (caller(1))[3];
16 Carp::carp "[$func] Warning: ", @_;
20 my($func) = (caller(1))[3];
21 Carp::croak "[$func] Fatal: ", @_;
24 has converter => (is => 'lazy', clearer => 'clear_converter');
27 is => 'ro', coerce => sub { $_[0] eq 'lower' ? 'lower' : undef }
31 is => 'ro', coerce => sub { uc($_[0]) }, default => sub { 'OR' }
35 is => 'ro', default => sub { 'normal' }
38 has cmp => (is => 'ro', default => sub { '=' });
40 has sqltrue => (is => 'ro', default => sub { '1=1' });
41 has sqlfalse => (is => 'ro', default => sub { '0=1' });
43 has special_ops => (is => 'ro', default => sub { [] });
44 has unary_ops => (is => 'ro', default => sub { [] });
47 # need to guard against ()'s in column names too, but this will break tons of
48 # hacks... ideas anyone?
50 has injection_guard => (
61 has renderer => (is => 'lazy', clearer => 'clear_renderer');
64 is => 'rw', default => sub { '.' },
66 $_[0]->clear_renderer;
67 $_[0]->clear_converter;
74 $_[0]->clear_renderer;
75 $_[0]->clear_converter;
79 has collapse_aliases => (
85 is => 'rw', default => sub { 1 },
87 $_[0]->clear_renderer;
88 $_[0]->clear_converter;
92 has convert => (is => 'ro');
94 has array_datatypes => (is => 'ro');
96 has converter_class => (
97 is => 'rw', lazy => 1, builder => '_build_converter_class',
98 trigger => sub { shift->clear_converter },
101 sub _build_converter_class {
102 use_module('SQL::Abstract::Converter')
105 has renderer_class => (
106 is => 'rw', lazy => 1, builder => '_build_renderer_class',
107 trigger => sub { shift->clear_renderer },
110 sub _build_renderer_class {
111 use_module('Data::Query::Renderer::SQL::Naive')
114 sub _converter_args {
116 Scalar::Util::weaken($self);
118 lower_case => $self->case,
119 default_logic => $self->logic,
120 bind_meta => not($self->bindtype eq 'normal'),
121 identifier_sep => $self->name_sep,
122 (map +($_ => $self->$_), qw(
123 cmp sqltrue sqlfalse injection_guard convert array_datatypes
127 my $sub = $_->{handler};
130 handler => sub { $self->$sub(@_) }
132 } @{$self->special_ops}
134 renderer_will_quote => (
135 defined($self->quote_char) and $self->always_quote
140 sub _build_converter {
142 $self->converter_class->new($self->_converter_args);
148 for ($self->quote_char) {
149 $chars = defined() ? (ref() ? $_ : [$_]) : ['',''];
152 quote_chars => $chars, always_quote => $self->always_quote,
153 identifier_sep => $self->name_sep,
154 collapse_aliases => $self->collapse_aliases,
155 ($self->case ? (lc_keywords => 1) : ()), # always 'lower' if it exists
159 sub _build_renderer {
161 $self->renderer_class->new($self->_renderer_args);
165 my ($self, $dq) = @_;
169 my ($sql, @bind) = @{$self->renderer->render($dq)};
171 ($self->{bindtype} eq 'normal'
172 ? ($sql, map $_->{value}, @bind)
173 : ($sql, map [ $_->{value_meta}, $_->{value} ], @bind)
179 my ($self, $type, @args) = @_;
180 $self->_render_dq($self->converter->${\"_${type}_to_dq"}(@args));
183 sub insert { shift->_render_sqla(insert => @_) }
185 sub update { shift->_render_sqla(update => @_) }
187 sub select { shift->_render_sqla(select => @_) }
189 sub delete { shift->_render_sqla(delete => @_) }
192 my ($self, $where, $order) = @_;
198 ($sql, @bind) = $self->_recurse_where($where) if defined($where);
199 $sql = $sql ? $self->_sqlcase(' where ') . "( $sql )" : '';
203 $sql .= $self->_order_by($order);
206 return wantarray ? ($sql, @bind) : $sql;
209 sub _recurse_where { shift->_render_sqla(where => @_) }
212 my ($self, $arg) = @_;
213 if (my $dq = $self->converter->_order_by_to_dq($arg)) {
214 # SQLA generates ' ORDER BY foo'. The hilarity.
216 ? do { my @r = $self->_render_dq($dq); $r[0] = ' '.$r[0]; @r }
217 : ' '.$self->_render_dq($dq);
223 # highly optimized, as it's called way too often
225 # my ($self, $label) = @_;
227 return '' unless defined $_[1];
228 return ${$_[1]} if ref($_[1]) eq 'SCALAR';
230 unless ($_[0]->{quote_char}) {
231 $_[0]->_assert_pass_injection_guard($_[1]);
235 my $qref = ref $_[0]->{quote_char};
238 ($l, $r) = ( $_[0]->{quote_char}, $_[0]->{quote_char} );
240 elsif ($qref eq 'ARRAY') {
241 ($l, $r) = @{$_[0]->{quote_char}};
244 puke "Unsupported quote_char format: $_[0]->{quote_char}";
247 # parts containing * are naturally unquoted
248 return join( $_[0]->{name_sep}||'', map
249 { $_ eq '*' ? $_ : $l . $_ . $r }
250 ( $_[0]->{name_sep} ? split (/\Q$_[0]->{name_sep}\E/, $_[1] ) : $_[1] )
254 sub _assert_pass_injection_guard {
255 if ($_[1] =~ $_[0]->{injection_guard}) {
256 my $class = ref $_[0];
257 die "Possible SQL injection attempt '$_[1]'. If this is indeed a part of the
259 . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own
261 . "{injection_guard} attribute to ${class}->new()"
265 # Conversion, if applicable
267 #my ($self, $arg) = @_;
269 # LDNOTE : modified the previous implementation below because
270 # it was not consistent : the first "return" is always an array,
271 # the second "return" is context-dependent. Anyway, _convert
272 # seems always used with just a single argument, so make it a
274 # return @_ unless $self->{convert};
275 # my $conv = $self->_sqlcase($self->{convert});
276 # my @ret = map { $conv.'('.$_.')' } @_;
277 # return wantarray ? @ret : $ret[0];
278 if ($_[0]->{convert}) {
279 return $_[0]->_sqlcase($_[0]->{convert}) .'(' . $_[1] . ')';
286 #my ($self, $col, @vals) = @_;
288 #LDNOTE : changed original implementation below because it did not make
289 # sense when bindtype eq 'columns' and @vals > 1.
290 # return $self->{bindtype} eq 'columns' ? [ $col, @vals ] : @vals;
292 # called often - tighten code
293 return $_[0]->{bindtype} eq 'columns'
294 ? map {[$_[1], $_]} @_[2 .. $#_]
299 # Dies if any element of @bind is not in [colname => value] format
300 # if bindtype is 'columns'.
301 sub _assert_bindval_matches_bindtype {
302 # my ($self, @bind) = @_;
304 if ($self->{bindtype} eq 'columns') {
306 if (!defined $_ || ref($_) ne 'ARRAY' || @$_ != 2) {
307 puke "bindtype 'columns' selected, you need to pass: [column_name => bind_value]"
313 # Fix SQL case, if so requested
315 # LDNOTE: if $self->{case} is true, then it contains 'lower', so we
316 # don't touch the argument ... crooked logic, but let's not change it!
317 return $_[0]->{case} ? $_[1] : uc($_[1]);
322 my $data = shift || return;
323 puke "Argument to ", __PACKAGE__, "->values must be a \\%hash"
324 unless ref $data eq 'HASH';
327 foreach my $k ( sort keys %$data ) {
329 local our $Cur_Col_Meta = $k;
330 my ($sql, @bind) = $self->_render_sqla(
333 push @all_bind, @bind;
342 my(@sql, @sqlq, @sqlv);
346 if ($ref eq 'HASH') {
347 for my $k (sort keys %$_) {
350 my $label = $self->_quote($k);
352 # literal SQL with bind
353 my ($sql, @bind) = @$v;
354 $self->_assert_bindval_matches_bindtype(@bind);
355 push @sqlq, "$label = $sql";
357 } elsif ($r eq 'SCALAR') {
358 # literal SQL without bind
359 push @sqlq, "$label = $$v";
361 push @sqlq, "$label = ?";
362 push @sqlv, $self->_bindtype($k, $v);
365 push @sql, $self->_sqlcase('set'), join ', ', @sqlq;
366 } elsif ($ref eq 'ARRAY') {
367 # unlike insert(), assume these are ONLY the column names, i.e. for SQL
370 if ($r eq 'ARRAY') { # literal SQL with bind
371 my ($sql, @bind) = @$v;
372 $self->_assert_bindval_matches_bindtype(@bind);
375 } elsif ($r eq 'SCALAR') { # literal SQL without bind
376 # embedded literal SQL
383 push @sql, '(' . join(', ', @sqlq) . ')';
384 } elsif ($ref eq 'SCALAR') {
388 # strings get case twiddled
389 push @sql, $self->_sqlcase($_);
393 my $sql = join ' ', @sql;
395 # this is pretty tricky
396 # if ask for an array, return ($stmt, @bind)
397 # otherwise, s/?/shift @sqlv/ to put it inline
399 return ($sql, @sqlv);
401 1 while $sql =~ s/\?/my $d = shift(@sqlv);
402 ref $d ? $d->[1] : $d/e;
414 SQL::Abstract - Generate SQL from Perl data structures
420 my $sql = SQL::Abstract->new;
422 my($stmt, @bind) = $sql->select($table, \@fields, \%where, \@order);
424 my($stmt, @bind) = $sql->insert($table, \%fieldvals || \@values);
426 my($stmt, @bind) = $sql->update($table, \%fieldvals, \%where);
428 my($stmt, @bind) = $sql->delete($table, \%where);
430 # Then, use these in your DBI statements
431 my $sth = $dbh->prepare($stmt);
432 $sth->execute(@bind);
434 # Just generate the WHERE clause
435 my($stmt, @bind) = $sql->where(\%where, \@order);
437 # Return values in the same order, for hashed queries
438 # See PERFORMANCE section for more details
439 my @bind = $sql->values(\%fieldvals);
443 This module was inspired by the excellent L<DBIx::Abstract>.
444 However, in using that module I found that what I really wanted
445 to do was generate SQL, but still retain complete control over my
446 statement handles and use the DBI interface. So, I set out to
447 create an abstract SQL generation module.
449 While based on the concepts used by L<DBIx::Abstract>, there are
450 several important differences, especially when it comes to WHERE
451 clauses. I have modified the concepts used to make the SQL easier
452 to generate from Perl data structures and, IMO, more intuitive.
453 The underlying idea is for this module to do what you mean, based
454 on the data structures you provide it. The big advantage is that
455 you don't have to modify your code every time your data changes,
456 as this module figures it out.
458 To begin with, an SQL INSERT is as easy as just specifying a hash
459 of C<key=value> pairs:
462 name => 'Jimbo Bobson',
463 phone => '123-456-7890',
464 address => '42 Sister Lane',
466 state => 'Louisiana',
469 The SQL can then be generated with this:
471 my($stmt, @bind) = $sql->insert('people', \%data);
473 Which would give you something like this:
475 $stmt = "INSERT INTO people
476 (address, city, name, phone, state)
477 VALUES (?, ?, ?, ?, ?)";
478 @bind = ('42 Sister Lane', 'St. Louis', 'Jimbo Bobson',
479 '123-456-7890', 'Louisiana');
481 These are then used directly in your DBI code:
483 my $sth = $dbh->prepare($stmt);
484 $sth->execute(@bind);
486 =head2 Inserting and Updating Arrays
488 If your database has array types (like for example Postgres),
489 activate the special option C<< array_datatypes => 1 >>
490 when creating the C<SQL::Abstract> object.
491 Then you may use an arrayref to insert and update database array types:
493 my $sql = SQL::Abstract->new(array_datatypes => 1);
495 planets => [qw/Mercury Venus Earth Mars/]
498 my($stmt, @bind) = $sql->insert('solar_system', \%data);
502 $stmt = "INSERT INTO solar_system (planets) VALUES (?)"
504 @bind = (['Mercury', 'Venus', 'Earth', 'Mars']);
507 =head2 Inserting and Updating SQL
509 In order to apply SQL functions to elements of your C<%data> you may
510 specify a reference to an arrayref for the given hash value. For example,
511 if you need to execute the Oracle C<to_date> function on a value, you can
512 say something like this:
516 date_entered => \["to_date(?,'MM/DD/YYYY')", "03/02/2003"],
519 The first value in the array is the actual SQL. Any other values are
520 optional and would be included in the bind values array. This gives
523 my($stmt, @bind) = $sql->insert('people', \%data);
525 $stmt = "INSERT INTO people (name, date_entered)
526 VALUES (?, to_date(?,'MM/DD/YYYY'))";
527 @bind = ('Bill', '03/02/2003');
529 An UPDATE is just as easy, all you change is the name of the function:
531 my($stmt, @bind) = $sql->update('people', \%data);
533 Notice that your C<%data> isn't touched; the module will generate
534 the appropriately quirky SQL for you automatically. Usually you'll
535 want to specify a WHERE clause for your UPDATE, though, which is
536 where handling C<%where> hashes comes in handy...
538 =head2 Complex where statements
540 This module can generate pretty complicated WHERE statements
541 easily. For example, simple C<key=value> pairs are taken to mean
542 equality, and if you want to see if a field is within a set
543 of values, you can use an arrayref. Let's say we wanted to
544 SELECT some data based on this criteria:
548 worker => ['nwiger', 'rcwe', 'sfz'],
549 status => { '!=', 'completed' }
552 my($stmt, @bind) = $sql->select('tickets', '*', \%where);
554 The above would give you something like this:
556 $stmt = "SELECT * FROM tickets WHERE
557 ( requestor = ? ) AND ( status != ? )
558 AND ( worker = ? OR worker = ? OR worker = ? )";
559 @bind = ('inna', 'completed', 'nwiger', 'rcwe', 'sfz');
561 Which you could then use in DBI code like so:
563 my $sth = $dbh->prepare($stmt);
564 $sth->execute(@bind);
570 The functions are simple. There's one for each major SQL operation,
571 and a constructor you use first. The arguments are specified in a
572 similar order to each function (table, then fields, then a where
573 clause) to try and simplify things.
578 =head2 new(option => 'value')
580 The C<new()> function takes a list of options and values, and returns
581 a new B<SQL::Abstract> object which can then be used to generate SQL
582 through the methods below. The options accepted are:
588 If set to 'lower', then SQL will be generated in all lowercase. By
589 default SQL is generated in "textbook" case meaning something like:
591 SELECT a_field FROM a_table WHERE some_field LIKE '%someval%'
593 Any setting other than 'lower' is ignored.
597 This determines what the default comparison operator is. By default
598 it is C<=>, meaning that a hash like this:
600 %where = (name => 'nwiger', email => 'nate@wiger.org');
602 Will generate SQL like this:
604 WHERE name = 'nwiger' AND email = 'nate@wiger.org'
606 However, you may want loose comparisons by default, so if you set
607 C<cmp> to C<like> you would get SQL such as:
609 WHERE name like 'nwiger' AND email like 'nate@wiger.org'
611 You can also override the comparsion on an individual basis - see
612 the huge section on L</"WHERE CLAUSES"> at the bottom.
614 =item sqltrue, sqlfalse
616 Expressions for inserting boolean values within SQL statements.
617 By default these are C<1=1> and C<1=0>. They are used
618 by the special operators C<-in> and C<-not_in> for generating
619 correct SQL even when the argument is an empty array (see below).
623 This determines the default logical operator for multiple WHERE
624 statements in arrays or hashes. If absent, the default logic is "or"
625 for arrays, and "and" for hashes. This means that a WHERE
629 event_date => {'>=', '2/13/99'},
630 event_date => {'<=', '4/24/03'},
633 will generate SQL like this:
635 WHERE event_date >= '2/13/99' OR event_date <= '4/24/03'
637 This is probably not what you want given this query, though (look
638 at the dates). To change the "OR" to an "AND", simply specify:
640 my $sql = SQL::Abstract->new(logic => 'and');
642 Which will change the above C<WHERE> to:
644 WHERE event_date >= '2/13/99' AND event_date <= '4/24/03'
646 The logic can also be changed locally by inserting
647 a modifier in front of an arrayref :
649 @where = (-and => [event_date => {'>=', '2/13/99'},
650 event_date => {'<=', '4/24/03'} ]);
652 See the L</"WHERE CLAUSES"> section for explanations.
656 This will automatically convert comparisons using the specified SQL
657 function for both column and value. This is mostly used with an argument
658 of C<upper> or C<lower>, so that the SQL will have the effect of
659 case-insensitive "searches". For example, this:
661 $sql = SQL::Abstract->new(convert => 'upper');
662 %where = (keywords => 'MaKe iT CAse inSeNSItive');
664 Will turn out the following SQL:
666 WHERE upper(keywords) like upper('MaKe iT CAse inSeNSItive')
668 The conversion can be C<upper()>, C<lower()>, or any other SQL function
669 that can be applied symmetrically to fields (actually B<SQL::Abstract> does
670 not validate this option; it will just pass through what you specify verbatim).
674 This is a kludge because many databases suck. For example, you can't
675 just bind values using DBI's C<execute()> for Oracle C<CLOB> or C<BLOB> fields.
676 Instead, you have to use C<bind_param()>:
678 $sth->bind_param(1, 'reg data');
679 $sth->bind_param(2, $lots, {ora_type => ORA_CLOB});
681 The problem is, B<SQL::Abstract> will normally just return a C<@bind> array,
682 which loses track of which field each slot refers to. Fear not.
684 If you specify C<bindtype> in new, you can determine how C<@bind> is returned.
685 Currently, you can specify either C<normal> (default) or C<columns>. If you
686 specify C<columns>, you will get an array that looks like this:
688 my $sql = SQL::Abstract->new(bindtype => 'columns');
689 my($stmt, @bind) = $sql->insert(...);
692 [ 'column1', 'value1' ],
693 [ 'column2', 'value2' ],
694 [ 'column3', 'value3' ],
697 You can then iterate through this manually, using DBI's C<bind_param()>.
699 $sth->prepare($stmt);
702 my($col, $data) = @$_;
703 if ($col eq 'details' || $col eq 'comments') {
704 $sth->bind_param($i, $data, {ora_type => ORA_CLOB});
705 } elsif ($col eq 'image') {
706 $sth->bind_param($i, $data, {ora_type => ORA_BLOB});
708 $sth->bind_param($i, $data);
712 $sth->execute; # execute without @bind now
714 Now, why would you still use B<SQL::Abstract> if you have to do this crap?
715 Basically, the advantage is still that you don't have to care which fields
716 are or are not included. You could wrap that above C<for> loop in a simple
717 sub called C<bind_fields()> or something and reuse it repeatedly. You still
718 get a layer of abstraction over manual SQL specification.
720 Note that if you set L</bindtype> to C<columns>, the C<\[$sql, @bind]>
721 construct (see L</Literal SQL with placeholders and bind values (subqueries)>)
722 will expect the bind values in this format.
726 This is the character that a table or column name will be quoted
727 with. By default this is an empty string, but you could set it to
728 the character C<`>, to generate SQL like this:
730 SELECT `a_field` FROM `a_table` WHERE `some_field` LIKE '%someval%'
732 Alternatively, you can supply an array ref of two items, the first being the left
733 hand quote character, and the second the right hand quote character. For
734 example, you could supply C<['[',']']> for SQL Server 2000 compliant quotes
735 that generates SQL like this:
737 SELECT [a_field] FROM [a_table] WHERE [some_field] LIKE '%someval%'
739 Quoting is useful if you have tables or columns names that are reserved
740 words in your database's SQL dialect.
744 This is the character that separates a table and column name. It is
745 necessary to specify this when the C<quote_char> option is selected,
746 so that tables and column names can be individually quoted like this:
748 SELECT `table`.`one_field` FROM `table` WHERE `table`.`other_field` = 1
750 =item injection_guard
752 A regular expression C<qr/.../> that is applied to any C<-function> and unquoted
753 column name specified in a query structure. This is a safety mechanism to avoid
754 injection attacks when mishandling user input e.g.:
756 my %condition_as_column_value_pairs = get_values_from_user();
757 $sqla->select( ... , \%condition_as_column_value_pairs );
759 If the expression matches an exception is thrown. Note that literal SQL
760 supplied via C<\'...'> or C<\['...']> is B<not> checked in any way.
762 Defaults to checking for C<;> and the C<GO> keyword (TransactSQL)
764 =item array_datatypes
766 When this option is true, arrayrefs in INSERT or UPDATE are
767 interpreted as array datatypes and are passed directly
769 When this option is false, arrayrefs are interpreted
770 as literal SQL, just like refs to arrayrefs
771 (but this behavior is for backwards compatibility; when writing
772 new queries, use the "reference to arrayref" syntax
778 Takes a reference to a list of "special operators"
779 to extend the syntax understood by L<SQL::Abstract>.
780 See section L</"SPECIAL OPERATORS"> for details.
784 Takes a reference to a list of "unary operators"
785 to extend the syntax understood by L<SQL::Abstract>.
786 See section L</"UNARY OPERATORS"> for details.
792 =head2 insert($table, \@values || \%fieldvals, \%options)
794 This is the simplest function. You simply give it a table name
795 and either an arrayref of values or hashref of field/value pairs.
796 It returns an SQL INSERT statement and a list of bind values.
797 See the sections on L</"Inserting and Updating Arrays"> and
798 L</"Inserting and Updating SQL"> for information on how to insert
799 with those data types.
801 The optional C<\%options> hash reference may contain additional
802 options to generate the insert SQL. Currently supported options
809 Takes either a scalar of raw SQL fields, or an array reference of
810 field names, and adds on an SQL C<RETURNING> statement at the end.
811 This allows you to return data generated by the insert statement
812 (such as row IDs) without performing another C<SELECT> statement.
813 Note, however, this is not part of the SQL standard and may not
814 be supported by all database engines.
818 =head2 update($table, \%fieldvals, \%where)
820 This takes a table, hashref of field/value pairs, and an optional
821 hashref L<WHERE clause|/WHERE CLAUSES>. It returns an SQL UPDATE function and a list
823 See the sections on L</"Inserting and Updating Arrays"> and
824 L</"Inserting and Updating SQL"> for information on how to insert
825 with those data types.
827 =head2 select($source, $fields, $where, $order)
829 This returns a SQL SELECT statement and associated list of bind values, as
830 specified by the arguments :
836 Specification of the 'FROM' part of the statement.
837 The argument can be either a plain scalar (interpreted as a table
838 name, will be quoted), or an arrayref (interpreted as a list
839 of table names, joined by commas, quoted), or a scalarref
840 (literal table name, not quoted), or a ref to an arrayref
841 (list of literal table names, joined by commas, not quoted).
845 Specification of the list of fields to retrieve from
847 The argument can be either an arrayref (interpreted as a list
848 of field names, will be joined by commas and quoted), or a
849 plain scalar (literal SQL, not quoted).
850 Please observe that this API is not as flexible as for
851 the first argument C<$table>, for backwards compatibility reasons.
855 Optional argument to specify the WHERE part of the query.
856 The argument is most often a hashref, but can also be
857 an arrayref or plain scalar --
858 see section L<WHERE clause|/"WHERE CLAUSES"> for details.
862 Optional argument to specify the ORDER BY part of the query.
863 The argument can be a scalar, a hashref or an arrayref
864 -- see section L<ORDER BY clause|/"ORDER BY CLAUSES">
870 =head2 delete($table, \%where)
872 This takes a table name and optional hashref L<WHERE clause|/WHERE CLAUSES>.
873 It returns an SQL DELETE statement and list of bind values.
875 =head2 where(\%where, \@order)
877 This is used to generate just the WHERE clause. For example,
878 if you have an arbitrary data structure and know what the
879 rest of your SQL is going to look like, but want an easy way
880 to produce a WHERE clause, use this. It returns an SQL WHERE
881 clause and list of bind values.
884 =head2 values(\%data)
886 This just returns the values from the hash C<%data>, in the same
887 order that would be returned from any of the other above queries.
888 Using this allows you to markedly speed up your queries if you
889 are affecting lots of rows. See below under the L</"PERFORMANCE"> section.
891 =head2 generate($any, 'number', $of, \@data, $struct, \%types)
893 Warning: This is an experimental method and subject to change.
895 This returns arbitrarily generated SQL. It's a really basic shortcut.
896 It will return two different things, depending on return context:
898 my($stmt, @bind) = $sql->generate('create table', \$table, \@fields);
899 my $stmt_and_val = $sql->generate('create table', \$table, \@fields);
901 These would return the following:
904 $stmt = "CREATE TABLE test (?, ?)";
905 @bind = (field1, field2);
907 # Second calling form
908 $stmt_and_val = "CREATE TABLE test (field1, field2)";
910 Depending on what you're trying to do, it's up to you to choose the correct
911 format. In this example, the second form is what you would want.
915 $sql->generate('alter session', { nls_date_format => 'MM/YY' });
919 ALTER SESSION SET nls_date_format = 'MM/YY'
921 You get the idea. Strings get their case twiddled, but everything
922 else remains verbatim.
928 This module uses a variation on the idea from L<DBIx::Abstract>. It
929 is B<NOT>, repeat I<not> 100% compatible. B<The main logic of this
930 module is that things in arrays are OR'ed, and things in hashes
933 The easiest way to explain is to show lots of examples. After
934 each C<%where> hash shown, it is assumed you used:
936 my($stmt, @bind) = $sql->where(\%where);
938 However, note that the C<%where> hash can be used directly in any
939 of the other functions as well, as described above.
941 =head2 Key-value pairs
943 So, let's get started. To begin, a simple hash:
947 status => 'completed'
950 Is converted to SQL C<key = val> statements:
952 $stmt = "WHERE user = ? AND status = ?";
953 @bind = ('nwiger', 'completed');
955 One common thing I end up doing is having a list of values that
956 a field can be in. To do this, simply specify a list inside of
961 status => ['assigned', 'in-progress', 'pending'];
964 This simple code will create the following:
966 $stmt = "WHERE user = ? AND ( status = ? OR status = ? OR status = ? )";
967 @bind = ('nwiger', 'assigned', 'in-progress', 'pending');
969 A field associated to an empty arrayref will be considered a
970 logical false and will generate 0=1.
972 =head2 Tests for NULL values
974 If the value part is C<undef> then this is converted to SQL <IS NULL>
983 $stmt = "WHERE user = ? AND status IS NULL";
986 To test if a column IS NOT NULL:
990 status => { '!=', undef },
993 =head2 Specific comparison operators
995 If you want to specify a different type of operator for your comparison,
996 you can use a hashref for a given column:
1000 status => { '!=', 'completed' }
1003 Which would generate:
1005 $stmt = "WHERE user = ? AND status != ?";
1006 @bind = ('nwiger', 'completed');
1008 To test against multiple values, just enclose the values in an arrayref:
1010 status => { '=', ['assigned', 'in-progress', 'pending'] };
1012 Which would give you:
1014 "WHERE status = ? OR status = ? OR status = ?"
1017 The hashref can also contain multiple pairs, in which case it is expanded
1018 into an C<AND> of its elements:
1022 status => { '!=', 'completed', -not_like => 'pending%' }
1025 # Or more dynamically, like from a form
1026 $where{user} = 'nwiger';
1027 $where{status}{'!='} = 'completed';
1028 $where{status}{'-not_like'} = 'pending%';
1030 # Both generate this
1031 $stmt = "WHERE user = ? AND status != ? AND status NOT LIKE ?";
1032 @bind = ('nwiger', 'completed', 'pending%');
1035 To get an OR instead, you can combine it with the arrayref idea:
1039 priority => [ { '=', 2 }, { '>', 5 } ]
1042 Which would generate:
1044 $stmt = "WHERE ( priority = ? OR priority > ? ) AND user = ?";
1045 @bind = ('2', '5', 'nwiger');
1047 If you want to include literal SQL (with or without bind values), just use a
1048 scalar reference or array reference as the value:
1051 date_entered => { '>' => \["to_date(?, 'MM/DD/YYYY')", "11/26/2008"] },
1052 date_expires => { '<' => \"now()" }
1055 Which would generate:
1057 $stmt = "WHERE date_entered > "to_date(?, 'MM/DD/YYYY') AND date_expires < now()";
1058 @bind = ('11/26/2008');
1061 =head2 Logic and nesting operators
1063 In the example above,
1064 there is a subtle trap if you want to say something like
1065 this (notice the C<AND>):
1067 WHERE priority != ? AND priority != ?
1069 Because, in Perl you I<can't> do this:
1071 priority => { '!=', 2, '!=', 1 }
1073 As the second C<!=> key will obliterate the first. The solution
1074 is to use the special C<-modifier> form inside an arrayref:
1076 priority => [ -and => {'!=', 2},
1080 Normally, these would be joined by C<OR>, but the modifier tells it
1081 to use C<AND> instead. (Hint: You can use this in conjunction with the
1082 C<logic> option to C<new()> in order to change the way your queries
1083 work by default.) B<Important:> Note that the C<-modifier> goes
1084 B<INSIDE> the arrayref, as an extra first element. This will
1085 B<NOT> do what you think it might:
1087 priority => -and => [{'!=', 2}, {'!=', 1}] # WRONG!
1089 Here is a quick list of equivalencies, since there is some overlap:
1092 status => {'!=', 'completed', 'not like', 'pending%' }
1093 status => [ -and => {'!=', 'completed'}, {'not like', 'pending%'}]
1096 status => {'=', ['assigned', 'in-progress']}
1097 status => [ -or => {'=', 'assigned'}, {'=', 'in-progress'}]
1098 status => [ {'=', 'assigned'}, {'=', 'in-progress'} ]
1102 =head2 Special operators : IN, BETWEEN, etc.
1104 You can also use the hashref format to compare a list of fields using the
1105 C<IN> comparison operator, by specifying the list as an arrayref:
1108 status => 'completed',
1109 reportid => { -in => [567, 2335, 2] }
1112 Which would generate:
1114 $stmt = "WHERE status = ? AND reportid IN (?,?,?)";
1115 @bind = ('completed', '567', '2335', '2');
1117 The reverse operator C<-not_in> generates SQL C<NOT IN> and is used in
1120 If the argument to C<-in> is an empty array, 'sqlfalse' is generated
1121 (by default : C<1=0>). Similarly, C<< -not_in => [] >> generates
1122 'sqltrue' (by default : C<1=1>).
1124 In addition to the array you can supply a chunk of literal sql or
1125 literal sql with bind:
1128 customer => { -in => \[
1129 'SELECT cust_id FROM cust WHERE balance > ?',
1132 status => { -in => \'SELECT status_codes FROM states' },
1138 customer IN ( SELECT cust_id FROM cust WHERE balance > ? )
1139 AND status IN ( SELECT status_codes FROM states )
1145 Another pair of operators is C<-between> and C<-not_between>,
1146 used with an arrayref of two values:
1150 completion_date => {
1151 -not_between => ['2002-10-01', '2003-02-06']
1157 WHERE user = ? AND completion_date NOT BETWEEN ( ? AND ? )
1159 Just like with C<-in> all plausible combinations of literal SQL
1163 start0 => { -between => [ 1, 2 ] },
1164 start1 => { -between => \["? AND ?", 1, 2] },
1165 start2 => { -between => \"lower(x) AND upper(y)" },
1166 start3 => { -between => [
1168 \["upper(?)", 'stuff' ],
1175 ( start0 BETWEEN ? AND ? )
1176 AND ( start1 BETWEEN ? AND ? )
1177 AND ( start2 BETWEEN lower(x) AND upper(y) )
1178 AND ( start3 BETWEEN lower(x) AND upper(?) )
1180 @bind = (1, 2, 1, 2, 'stuff');
1183 These are the two builtin "special operators"; but the
1184 list can be expanded : see section L</"SPECIAL OPERATORS"> below.
1186 =head2 Unary operators: bool
1188 If you wish to test against boolean columns or functions within your
1189 database you can use the C<-bool> and C<-not_bool> operators. For
1190 example to test the column C<is_user> being true and the column
1191 C<is_enabled> being false you would use:-
1195 -not_bool => 'is_enabled',
1200 WHERE is_user AND NOT is_enabled
1202 If a more complex combination is required, testing more conditions,
1203 then you should use the and/or operators:-
1210 -not_bool => 'four',
1216 WHERE one AND two AND three AND NOT four
1219 =head2 Nested conditions, -and/-or prefixes
1221 So far, we've seen how multiple conditions are joined with a top-level
1222 C<AND>. We can change this by putting the different conditions we want in
1223 hashes and then putting those hashes in an array. For example:
1228 status => { -like => ['pending%', 'dispatched'] },
1232 status => 'unassigned',
1236 This data structure would create the following:
1238 $stmt = "WHERE ( user = ? AND ( status LIKE ? OR status LIKE ? ) )
1239 OR ( user = ? AND status = ? ) )";
1240 @bind = ('nwiger', 'pending', 'dispatched', 'robot', 'unassigned');
1243 Clauses in hashrefs or arrayrefs can be prefixed with an C<-and> or C<-or>
1244 to change the logic inside :
1250 -and => [ workhrs => {'>', 20}, geo => 'ASIA' ],
1251 -or => { workhrs => {'<', 50}, geo => 'EURO' },
1258 WHERE ( user = ? AND (
1259 ( workhrs > ? AND geo = ? )
1260 OR ( workhrs < ? OR geo = ? )
1263 =head3 Algebraic inconsistency, for historical reasons
1265 C<Important note>: when connecting several conditions, the C<-and->|C<-or>
1266 operator goes C<outside> of the nested structure; whereas when connecting
1267 several constraints on one column, the C<-and> operator goes
1268 C<inside> the arrayref. Here is an example combining both features :
1271 -and => [a => 1, b => 2],
1272 -or => [c => 3, d => 4],
1273 e => [-and => {-like => 'foo%'}, {-like => '%bar'} ]
1278 WHERE ( ( ( a = ? AND b = ? )
1279 OR ( c = ? OR d = ? )
1280 OR ( e LIKE ? AND e LIKE ? ) ) )
1282 This difference in syntax is unfortunate but must be preserved for
1283 historical reasons. So be careful : the two examples below would
1284 seem algebraically equivalent, but they are not
1286 {col => [-and => {-like => 'foo%'}, {-like => '%bar'}]}
1287 # yields : WHERE ( ( col LIKE ? AND col LIKE ? ) )
1289 [-and => {col => {-like => 'foo%'}, {col => {-like => '%bar'}}]]
1290 # yields : WHERE ( ( col LIKE ? OR col LIKE ? ) )
1293 =head2 Literal SQL and value type operators
1295 The basic premise of SQL::Abstract is that in WHERE specifications the "left
1296 side" is a column name and the "right side" is a value (normally rendered as
1297 a placeholder). This holds true for both hashrefs and arrayref pairs as you
1298 see in the L</WHERE CLAUSES> examples above. Sometimes it is necessary to
1299 alter this behavior. There are several ways of doing so.
1303 This is a virtual operator that signals the string to its right side is an
1304 identifier (a column name) and not a value. For example to compare two
1305 columns you would write:
1308 priority => { '<', 2 },
1309 requestor => { -ident => 'submitter' },
1314 $stmt = "WHERE priority < ? AND requestor = submitter";
1317 If you are maintaining legacy code you may see a different construct as
1318 described in L</Deprecated usage of Literal SQL>, please use C<-ident> in new
1323 This is a virtual operator that signals that the construct to its right side
1324 is a value to be passed to DBI. This is for example necessary when you want
1325 to write a where clause against an array (for RDBMS that support such
1326 datatypes). For example:
1329 array => { -value => [1, 2, 3] }
1334 $stmt = 'WHERE array = ?';
1335 @bind = ([1, 2, 3]);
1337 Note that if you were to simply say:
1343 the result would porbably be not what you wanted:
1345 $stmt = 'WHERE array = ? OR array = ? OR array = ?';
1350 Finally, sometimes only literal SQL will do. To include a random snippet
1351 of SQL verbatim, you specify it as a scalar reference. Consider this only
1352 as a last resort. Usually there is a better way. For example:
1355 priority => { '<', 2 },
1356 requestor => { -in => \'(SELECT name FROM hitmen)' },
1361 $stmt = "WHERE priority < ? AND requestor IN (SELECT name FROM hitmen)"
1364 Note that in this example, you only get one bind parameter back, since
1365 the verbatim SQL is passed as part of the statement.
1369 Never use untrusted input as a literal SQL argument - this is a massive
1370 security risk (there is no way to check literal snippets for SQL
1371 injections and other nastyness). If you need to deal with untrusted input
1372 use literal SQL with placeholders as described next.
1374 =head3 Literal SQL with placeholders and bind values (subqueries)
1376 If the literal SQL to be inserted has placeholders and bind values,
1377 use a reference to an arrayref (yes this is a double reference --
1378 not so common, but perfectly legal Perl). For example, to find a date
1379 in Postgres you can use something like this:
1382 date_column => \[q/= date '2008-09-30' - ?::integer/, 10/]
1387 $stmt = "WHERE ( date_column = date '2008-09-30' - ?::integer )"
1390 Note that you must pass the bind values in the same format as they are returned
1391 by L</where>. That means that if you set L</bindtype> to C<columns>, you must
1392 provide the bind values in the C<< [ column_meta => value ] >> format, where
1393 C<column_meta> is an opaque scalar value; most commonly the column name, but
1394 you can use any scalar value (including references and blessed references),
1395 L<SQL::Abstract> will simply pass it through intact. So if C<bindtype> is set
1396 to C<columns> the above example will look like:
1399 date_column => \[q/= date '2008-09-30' - ?::integer/, [ dummy => 10 ]/]
1402 Literal SQL is especially useful for nesting parenthesized clauses in the
1403 main SQL query. Here is a first example :
1405 my ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
1409 bar => \["IN ($sub_stmt)" => @sub_bind],
1414 $stmt = "WHERE (foo = ? AND bar IN (SELECT c1 FROM t1
1415 WHERE c2 < ? AND c3 LIKE ?))";
1416 @bind = (1234, 100, "foo%");
1418 Other subquery operators, like for example C<"E<gt> ALL"> or C<"NOT IN">,
1419 are expressed in the same way. Of course the C<$sub_stmt> and
1420 its associated bind values can be generated through a former call
1423 my ($sub_stmt, @sub_bind)
1424 = $sql->select("t1", "c1", {c2 => {"<" => 100},
1425 c3 => {-like => "foo%"}});
1428 bar => \["> ALL ($sub_stmt)" => @sub_bind],
1431 In the examples above, the subquery was used as an operator on a column;
1432 but the same principle also applies for a clause within the main C<%where>
1433 hash, like an EXISTS subquery :
1435 my ($sub_stmt, @sub_bind)
1436 = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
1437 my %where = ( -and => [
1439 \["EXISTS ($sub_stmt)" => @sub_bind],
1444 $stmt = "WHERE (foo = ? AND EXISTS (SELECT * FROM t1
1445 WHERE c1 = ? AND c2 > t0.c0))";
1449 Observe that the condition on C<c2> in the subquery refers to
1450 column C<t0.c0> of the main query : this is I<not> a bind
1451 value, so we have to express it through a scalar ref.
1452 Writing C<< c2 => {">" => "t0.c0"} >> would have generated
1453 C<< c2 > ? >> with bind value C<"t0.c0"> ... not exactly
1454 what we wanted here.
1456 Finally, here is an example where a subquery is used
1457 for expressing unary negation:
1459 my ($sub_stmt, @sub_bind)
1460 = $sql->where({age => [{"<" => 10}, {">" => 20}]});
1461 $sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
1463 lname => {like => '%son%'},
1464 \["NOT ($sub_stmt)" => @sub_bind],
1469 $stmt = "lname LIKE ? AND NOT ( age < ? OR age > ? )"
1470 @bind = ('%son%', 10, 20)
1472 =head3 Deprecated usage of Literal SQL
1474 Below are some examples of archaic use of literal SQL. It is shown only as
1475 reference for those who deal with legacy code. Each example has a much
1476 better, cleaner and safer alternative that users should opt for in new code.
1482 my %where = ( requestor => \'IS NOT NULL' )
1484 $stmt = "WHERE requestor IS NOT NULL"
1486 This used to be the way of generating NULL comparisons, before the handling
1487 of C<undef> got formalized. For new code please use the superior syntax as
1488 described in L</Tests for NULL values>.
1492 my %where = ( requestor => \'= submitter' )
1494 $stmt = "WHERE requestor = submitter"
1496 This used to be the only way to compare columns. Use the superior L</-ident>
1497 method for all new code. For example an identifier declared in such a way
1498 will be properly quoted if L</quote_char> is properly set, while the legacy
1499 form will remain as supplied.
1503 my %where = ( is_ready => \"", completed => { '>', '2012-12-21' } )
1505 $stmt = "WHERE completed > ? AND is_ready"
1506 @bind = ('2012-12-21')
1508 Using an empty string literal used to be the only way to express a boolean.
1509 For all new code please use the much more readable
1510 L<-bool|/Unary operators: bool> operator.
1516 These pages could go on for a while, since the nesting of the data
1517 structures this module can handle are pretty much unlimited (the
1518 module implements the C<WHERE> expansion as a recursive function
1519 internally). Your best bet is to "play around" with the module a
1520 little to see how the data structures behave, and choose the best
1521 format for your data based on that.
1523 And of course, all the values above will probably be replaced with
1524 variables gotten from forms or the command line. After all, if you
1525 knew everything ahead of time, you wouldn't have to worry about
1526 dynamically-generating SQL and could just hardwire it into your
1529 =head1 ORDER BY CLAUSES
1531 Some functions take an order by clause. This can either be a scalar (just a
1532 column name,) a hash of C<< { -desc => 'col' } >> or C<< { -asc => 'col' } >>,
1533 or an array of either of the two previous forms. Examples:
1535 Given | Will Generate
1536 ----------------------------------------------------------
1538 \'colA DESC' | ORDER BY colA DESC
1540 'colA' | ORDER BY colA
1542 [qw/colA colB/] | ORDER BY colA, colB
1544 {-asc => 'colA'} | ORDER BY colA ASC
1546 {-desc => 'colB'} | ORDER BY colB DESC
1548 ['colA', {-asc => 'colB'}] | ORDER BY colA, colB ASC
1550 { -asc => [qw/colA colB/] } | ORDER BY colA ASC, colB ASC
1553 { -asc => 'colA' }, | ORDER BY colA ASC, colB DESC,
1554 { -desc => [qw/colB/], | colC ASC, colD ASC
1555 { -asc => [qw/colC colD/],|
1557 ===========================================================
1561 =head1 SPECIAL OPERATORS
1563 my $sqlmaker = SQL::Abstract->new(special_ops => [
1567 my ($self, $field, $op, $arg) = @_;
1573 handler => 'method_name',
1577 A "special operator" is a SQL syntactic clause that can be
1578 applied to a field, instead of a usual binary operator.
1581 WHERE field IN (?, ?, ?)
1582 WHERE field BETWEEN ? AND ?
1583 WHERE MATCH(field) AGAINST (?, ?)
1585 Special operators IN and BETWEEN are fairly standard and therefore
1586 are builtin within C<SQL::Abstract> (as the overridable methods
1587 C<_where_field_IN> and C<_where_field_BETWEEN>). For other operators,
1588 like the MATCH .. AGAINST example above which is specific to MySQL,
1589 you can write your own operator handlers - supply a C<special_ops>
1590 argument to the C<new> method. That argument takes an arrayref of
1591 operator definitions; each operator definition is a hashref with two
1598 the regular expression to match the operator
1602 Either a coderef or a plain scalar method name. In both cases
1603 the expected return is C<< ($sql, @bind) >>.
1605 When supplied with a method name, it is simply called on the
1606 L<SQL::Abstract/> object as:
1608 $self->$method_name ($field, $op, $arg)
1612 $op is the part that matched the handler regex
1613 $field is the LHS of the operator
1616 When supplied with a coderef, it is called as:
1618 $coderef->($self, $field, $op, $arg)
1623 For example, here is an implementation
1624 of the MATCH .. AGAINST syntax for MySQL
1626 my $sqlmaker = SQL::Abstract->new(special_ops => [
1628 # special op for MySql MATCH (field) AGAINST(word1, word2, ...)
1629 {regex => qr/^match$/i,
1631 my ($self, $field, $op, $arg) = @_;
1632 $arg = [$arg] if not ref $arg;
1633 my $label = $self->_quote($field);
1634 my ($placeholder) = $self->_convert('?');
1635 my $placeholders = join ", ", (($placeholder) x @$arg);
1636 my $sql = $self->_sqlcase('match') . " ($label) "
1637 . $self->_sqlcase('against') . " ($placeholders) ";
1638 my @bind = $self->_bindtype($field, @$arg);
1639 return ($sql, @bind);
1646 =head1 UNARY OPERATORS
1648 my $sqlmaker = SQL::Abstract->new(unary_ops => [
1652 my ($self, $op, $arg) = @_;
1658 handler => 'method_name',
1662 A "unary operator" is a SQL syntactic clause that can be
1663 applied to a field - the operator goes before the field
1665 You can write your own operator handlers - supply a C<unary_ops>
1666 argument to the C<new> method. That argument takes an arrayref of
1667 operator definitions; each operator definition is a hashref with two
1674 the regular expression to match the operator
1678 Either a coderef or a plain scalar method name. In both cases
1679 the expected return is C<< $sql >>.
1681 When supplied with a method name, it is simply called on the
1682 L<SQL::Abstract/> object as:
1684 $self->$method_name ($op, $arg)
1688 $op is the part that matched the handler regex
1689 $arg is the RHS or argument of the operator
1691 When supplied with a coderef, it is called as:
1693 $coderef->($self, $op, $arg)
1701 Thanks to some benchmarking by Mark Stosberg, it turns out that
1702 this module is many orders of magnitude faster than using C<DBIx::Abstract>.
1703 I must admit this wasn't an intentional design issue, but it's a
1704 byproduct of the fact that you get to control your C<DBI> handles
1707 To maximize performance, use a code snippet like the following:
1709 # prepare a statement handle using the first row
1710 # and then reuse it for the rest of the rows
1712 for my $href (@array_of_hashrefs) {
1713 $stmt ||= $sql->insert('table', $href);
1714 $sth ||= $dbh->prepare($stmt);
1715 $sth->execute($sql->values($href));
1718 The reason this works is because the keys in your C<$href> are sorted
1719 internally by B<SQL::Abstract>. Thus, as long as your data retains
1720 the same structure, you only have to generate the SQL the first time
1721 around. On subsequent queries, simply use the C<values> function provided
1722 by this module to return your values in the correct order.
1724 However this depends on the values having the same type - if, for
1725 example, the values of a where clause may either have values
1726 (resulting in sql of the form C<column = ?> with a single bind
1727 value), or alternatively the values might be C<undef> (resulting in
1728 sql of the form C<column IS NULL> with no bind value) then the
1729 caching technique suggested will not work.
1733 If you use my C<CGI::FormBuilder> module at all, you'll hopefully
1734 really like this part (I do, at least). Building up a complex query
1735 can be as simple as the following:
1739 use CGI::FormBuilder;
1742 my $form = CGI::FormBuilder->new(...);
1743 my $sql = SQL::Abstract->new;
1745 if ($form->submitted) {
1746 my $field = $form->field;
1747 my $id = delete $field->{id};
1748 my($stmt, @bind) = $sql->update('table', $field, {id => $id});
1751 Of course, you would still have to connect using C<DBI> to run the
1752 query, but the point is that if you make your form look like your
1753 table, the actual query script can be extremely simplistic.
1755 If you're B<REALLY> lazy (I am), check out C<HTML::QuickTable> for
1756 a fast interface to returning and formatting data. I frequently
1757 use these three modules together to write complex database query
1758 apps in under 50 lines.
1764 =item * gitweb: L<http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/SQL-Abstract.git>
1766 =item * git: L<git://git.shadowcat.co.uk/dbsrgits/SQL-Abstract.git>
1772 Version 1.50 was a major internal refactoring of C<SQL::Abstract>.
1773 Great care has been taken to preserve the I<published> behavior
1774 documented in previous versions in the 1.* family; however,
1775 some features that were previously undocumented, or behaved
1776 differently from the documentation, had to be changed in order
1777 to clarify the semantics. Hence, client code that was relying
1778 on some dark areas of C<SQL::Abstract> v1.*
1779 B<might behave differently> in v1.50.
1781 The main changes are :
1787 support for literal SQL through the C<< \ [$sql, bind] >> syntax.
1791 support for the { operator => \"..." } construct (to embed literal SQL)
1795 support for the { operator => \["...", @bind] } construct (to embed literal SQL with bind values)
1799 optional support for L<array datatypes|/"Inserting and Updating Arrays">
1803 defensive programming : check arguments
1807 fixed bug with global logic, which was previously implemented
1808 through global variables yielding side-effects. Prior versions would
1809 interpret C<< [ {cond1, cond2}, [cond3, cond4] ] >>
1810 as C<< "(cond1 AND cond2) OR (cond3 AND cond4)" >>.
1811 Now this is interpreted
1812 as C<< "(cond1 AND cond2) OR (cond3 OR cond4)" >>.
1817 fixed semantics of _bindtype on array args
1821 dropped the C<_anoncopy> of the %where tree. No longer necessary,
1822 we just avoid shifting arrays within that tree.
1826 dropped the C<_modlogic> function
1830 =head1 ACKNOWLEDGEMENTS
1832 There are a number of individuals that have really helped out with
1833 this module. Unfortunately, most of them submitted bugs via CPAN
1834 so I have no idea who they are! But the people I do know are:
1836 Ash Berlin (order_by hash term support)
1837 Matt Trout (DBIx::Class support)
1838 Mark Stosberg (benchmarking)
1839 Chas Owens (initial "IN" operator support)
1840 Philip Collins (per-field SQL functions)
1841 Eric Kolve (hashref "AND" support)
1842 Mike Fragassi (enhancements to "BETWEEN" and "LIKE")
1843 Dan Kubb (support for "quote_char" and "name_sep")
1844 Guillermo Roditi (patch to cleanup "IN" and "BETWEEN", fix and tests for _order_by)
1845 Laurent Dami (internal refactoring, extensible list of special operators, literal SQL)
1846 Norbert Buchmuller (support for literal SQL in hashpair, misc. fixes & tests)
1847 Peter Rabbitson (rewrite of SQLA::Test, misc. fixes & tests)
1848 Oliver Charles (support for "RETURNING" after "INSERT")
1854 L<DBIx::Class>, L<DBIx::Abstract>, L<CGI::FormBuilder>, L<HTML::QuickTable>.
1858 Copyright (c) 2001-2007 Nathan Wiger <nwiger@cpan.org>. All Rights Reserved.
1860 This module is actively maintained by Matt Trout <mst@shadowcatsystems.co.uk>
1862 For support, your best bet is to try the C<DBIx::Class> users mailing list.
1863 While not an official support venue, C<DBIx::Class> makes heavy use of
1864 C<SQL::Abstract>, and as such list members there are very familiar with
1865 how to create queries.
1869 This module is free software; you may copy this under the same
1870 terms as perl itself (either the GNU General Public License or
1871 the Artistic License)