From: Matt S Trout Date: Sat, 16 Oct 2010 01:54:30 +0000 (+0100) Subject: clean up sql.t somewhat X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3a1bb3a0d7d64b2d3703ab42b0052eaffe994b9c;p=dbsrgits%2FData-Query.git clean up sql.t somewhat --- diff --git a/t/sql.t b/t/sql.t index 57cb03b..adac5af 100644 --- a/t/sql.t +++ b/t/sql.t @@ -9,6 +9,8 @@ BEGIN { require 't/expr.include' } my $rend = Data::Query::Renderer::SQL::Naive->new({ quote_chars => [ "'" ] }); +sub binding { map perl_scalar_value($_), @_ } + sub expr_sql_is (&;@) { my $sub = shift; @_ @@ -29,64 +31,16 @@ expr_sql_is { $_->foo->group } "Complex identifier -> SQL"; expr_sql_is { $_->foo == 1 } - [ - "foo = ?", - { - subtype => { - Perl => "Scalar" - }, - type => "Value", - value => 1 - } - ], + [ "foo = ?", binding(1) ], "Simple expression -> SQL"; expr_sql_is { ($_->foo == 1) & ($_->bar eq "foo") } - [ - "( foo = ? AND bar = ? )", - { - subtype => { - Perl => "Scalar" - }, - type => "Value", - value => 1 - }, - { - subtype => { - Perl => "Scalar" - }, - type => "Value", - value => "foo" - } - ], + [ "( foo = ? AND bar = ? )", binding(1, "foo") ], "Compound expression -> SQL"; expr_sql_is { ($_->foo == 1) & ($_->bar eq "foo") & ($_->baz > 3) } - [ - "( foo = ? AND bar = ? AND baz > ? )", - { - subtype => { - Perl => "Scalar" - }, - type => "Value", - value => 1 - }, - { - subtype => { - Perl => "Scalar" - }, - type => "Value", - value => "foo" - }, - { - subtype => { - Perl => "Scalar" - }, - type => "Value", - value => 3 - } - ], + [ "( foo = ? AND bar = ? AND baz > ? )", binding(1, "foo", 3) ], "Flatten expression ok"; expr_sql_is { !$_->foo } @@ -100,5 +54,5 @@ expr_sql_is { SELECT { $_->foo } } expr_sql_is { SELECT { $_->foo, 1 } } # the extra space here is a little icky but Naive's _flatten_structure # will need rewriting to fix it - commit bits available if you do it first - [ "SELECT foo , ?", perl_scalar_value(1) ], + [ "SELECT foo , ?", binding(1) ], "Identifier and literal";