Revision history for SQL::Abstract
- Fix insufficient parenthesis unroll during operator comparison
+ - 'ORDER BY foo' and 'ORDER BY foo ASC' are now considered equal
+ by default (with a switch to reenable old behavior when necessary)
revision 1.73 2012-07-10
----------------------------
our $case_sensitive = 0;
our $parenthesis_significant = 0;
+our $order_by_asc_significant = 0;
+
our $sql_differ; # keeps track of differing portion between SQLs
our $tb = __PACKAGE__->builder;
$sqlat->_parenthesis_unroll($_) for $left, $right;
}
+ # unroll ASC order by's
+ unless ($order_by_asc_significant) {
+ $sqlat->_strip_asc_from_order_by($_) for $left, $right;
+ }
+
if ( $left->[0] ne $right->[0] ) {
$sql_differ = sprintf "OP [$left->[0]] != [$right->[0]] in\nleft: %s\nright: %s\n",
$sqlat->unparse($left),
parenthesis. Useful while testing C<IN (( x ))> vs C<IN ( x )>.
Defaults to false;
+=head2 $order_by_asc_significant
+
+If true SQL comparison will consider C<ORDER BY foo ASC> and
+C<ORDER BY foo> to be different. Default is false;
+
=head2 $sql_differ
When L</eq_sql> returns false, the global variable
} while ($changes);
}
+sub _strip_asc_from_order_by {
+ my ($self, $ast) = @_;
+
+ return $ast if (
+ ref $ast ne 'ARRAY'
+ or
+ $ast->[0] ne 'ORDER BY'
+ );
+
+
+ my $to_replace;
+
+ if (@{$ast->[1]} == 1 and $ast->[1][0][0] eq '-ASC') {
+ $to_replace = [ $ast->[1][0] ];
+ }
+ elsif (@{$ast->[1]} == 1 and $ast->[1][0][0] eq '-LIST') {
+ $to_replace = [ grep { $_->[0] eq '-ASC' } @{$ast->[1][0][1]} ];
+ }
+
+ @$_ = @{$_->[1][0]} for @$to_replace;
+
+ $ast;
+}
+
sub format { my $self = shift; $self->unparse($self->parse($_[0]), $_[1]) }
1;
]
},
+ # order by
+ {
+ equal => 1,
+ statements => [
+ q/SELECT * FROM foo ORDER BY bar/,
+ q/SELECT * FROM foo ORDER BY bar ASC/,
+ q/SELECT * FROM foo ORDER BY bar asc/,
+ ],
+ },
+ {
+ equal => 1,
+ statements => [
+ q/SELECT * FROM foo ORDER BY bar, baz ASC/,
+ q/SELECT * FROM foo ORDER BY bar ASC, baz/,
+ q/SELECT * FROM foo ORDER BY bar asc, baz ASC/,
+ q/SELECT * FROM foo ORDER BY bar, baz/,
+ ],
+ },
+ {
+ equal => 0,
+ opts => { order_by_asc_significant => 1 },
+ statements => [
+ q/SELECT * FROM foo ORDER BY bar/,
+ q/SELECT * FROM foo ORDER BY bar ASC/,
+ q/SELECT * FROM foo ORDER BY bar desc/,
+ ],
+ },
+
# list permutations
{
equal => 0,