From: Ash Berlin Date: Sun, 29 Mar 2009 22:40:51 +0000 (+0100) Subject: Port more of the back-compat tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aa0f2366f9d425eed0c5126c4e947c448bca7ecb;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Port more of the back-compat tests --- diff --git a/lib/SQL/Abstract/Compat.pm b/lib/SQL/Abstract/Compat.pm index 2fd21c6..e2d02b0 100644 --- a/lib/SQL/Abstract/Compat.pm +++ b/lib/SQL/Abstract/Compat.pm @@ -15,7 +15,8 @@ class SQL::Abstract::Compat { has logic => ( is => 'rw', isa => LogicEnum, - default => 'AND' + default => 'AND', + coerce => 1 ); has visitor => ( @@ -33,7 +34,6 @@ class SQL::Abstract::Compat { { my $ast = $self->_new_compat_ast->select($from,$fields,$where,$order); - pp($ast); return ($self->visitor->dispatch($ast), $self->visitor->binds); } diff --git a/lib/SQL/Abstract/Types/Compat.pm b/lib/SQL/Abstract/Types/Compat.pm index 36dd455..fff3859 100644 --- a/lib/SQL/Abstract/Types/Compat.pm +++ b/lib/SQL/Abstract/Types/Compat.pm @@ -10,5 +10,7 @@ class SQL::Abstract::Types::Compat { enum LogicEnum, qw(OR AND); + coerce LogicEnum, from Str, via { uc $_ }; + subtype WhereType, as Str|ArrayRef|HashRef|ScalarRef; } diff --git a/t/compat/00new.t b/t/compat/00new.t index 4d28b95..732c0d9 100644 --- a/t/compat/00new.t +++ b/t/compat/00new.t @@ -7,11 +7,100 @@ use SQL::Abstract::Test import => ['is_same_sql_bind']; #LDNOTE: renamed all "bind" into "where" because that's what they are my @handle_tests = ( - #2 - { - args => {}, - stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' - } + #1 + { + args => {logic => 'OR'}, +# stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' +# LDNOTE: modified the line above (changing the test suite!!!) because +# the test was not consistent with the doc: hashrefs should not be +# influenced by the current logic, they always mean 'AND'. So +# { a => 4, b => 0} should ALWAYS mean ( a = ? AND b = ? ). +# +# acked by RIBASUSHI + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' + }, + + #2 + { + args => {}, + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' + }, + #3 + { + args => {case => "upper"}, + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' + }, + #4 + { + args => {case => "upper", cmp => "="}, + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' + }, + #5 + { + args => {cmp => "=", logic => 'or'}, +# LDNOTE idem +# stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' +# acked by RIBASUSHI + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' + }, +); +my @foo = ( + #6 + { + args => {cmp => "like"}, + stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )' + }, + #7 + { + args => {logic => "or", cmp => "like"}, +# LDNOTE idem +# stmt => 'SELECT * FROM test WHERE ( a LIKE ? OR b LIKE ? )' +# acked by RIBASUSHI + stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )' + }, + #8 + { + args => {case => "lower"}, + stmt => 'select * from test where ( a = ? and b = ? )' + }, + #9 + { + args => {case => "lower", cmp => "="}, + stmt => 'select * from test where ( a = ? and b = ? )' + }, + #10 + { + args => {case => "lower", cmp => "like"}, + stmt => 'select * from test where ( a like ? and b like ? )' + }, + #11 + { + args => {case => "lower", convert => "lower", cmp => "like"}, + stmt => 'select * from test where ( lower(a) like lower(?) and lower(b) like lower(?) )' + }, + #12 + { + args => {convert => "Round"}, + stmt => 'SELECT * FROM test WHERE ( ROUND(a) = ROUND(?) AND ROUND(b) = ROUND(?) )', + }, + #13 + { + args => {convert => "lower"}, + stmt => 'SELECT * FROM test WHERE ( ( LOWER(ticket) = LOWER(?) ) OR ( LOWER(hostname) = LOWER(?) ) OR ( LOWER(taco) = LOWER(?) ) OR ( LOWER(salami) = LOWER(?) ) )', + where => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ], + }, + #14 + { + args => {convert => "upper"}, + stmt => 'SELECT * FROM test WHERE ( ( UPPER(hostname) IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) AND ( ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) ) ) OR ( UPPER(tack) BETWEEN UPPER(?) AND UPPER(?) ) OR ( ( ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) ) AND ( ( UPPER(e) != UPPER(?) ) OR ( UPPER(e) != UPPER(?) ) ) AND UPPER(q) NOT IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) ) )', + where => [ { ticket => [11, 12, 13], + hostname => { in => ['ntf', 'avd', 'bvd', '123'] } }, + { tack => { between => [qw/tick tock/] } }, + { a => [qw/b c d/], + e => { '!=', [qw(f g)] }, + q => { 'not in', [14..20] } } ], + }, + ); plan tests => (1 + scalar(@handle_tests));