2 use Test::More qw(no_plan);
5 use Data::Query::Renderer::SQL::Naive;
6 use Data::Query::ExprHelpers qw(perl_scalar_value);
8 BEGIN { require 't/expr.include' }
10 my $rend = Data::Query::Renderer::SQL::Naive->new({ quote_chars => [ "'" ] });
12 sub expr_sql_is (&;@) {
15 ? is_deeply($rend->render(_mk_expr($sub)), @_)
16 : ::Dwarn($rend->render(_mk_expr($sub)));
19 expr_sql_is { $_->foo }
21 "Simple identifier -> SQL";
23 expr_sql_is { $_->group }
25 "Simple identifier needing quoting -> SQL";
27 expr_sql_is { $_->foo->group }
29 "Complex identifier -> SQL";
31 expr_sql_is { $_->foo == 1 }
42 "Simple expression -> SQL";
44 expr_sql_is { ($_->foo == 1) & ($_->bar eq "foo") }
46 "( foo = ? AND bar = ? )",
62 "Compound expression -> SQL";
65 expr_sql_is { ($_->foo == 1) & ($_->bar eq "foo") & ($_->baz > 3) }
67 "( foo = ? AND bar = ? AND baz > ? )",
90 "Flatten expression ok";
92 expr_sql_is { !$_->foo }
94 "Unary expression ok";
96 expr_sql_is { SELECT { $_->foo } }
100 expr_sql_is { SELECT { $_->foo, 1 } }
101 # the extra space here is a little icky but Naive's _flatten_structure
102 # will need rewriting to fix it - commit bits available if you do it first
103 [ "SELECT foo , ?", perl_scalar_value(1) ],
104 "Identifier and literal";