}
# test values() with literal sql
+#
+# NOTE:
+# The example is deliberately complicated by the addition of a literal ? in xfunc
+# This is an intentional test making sure literal ? remains untouched.
+# It is rather impractical in the field, as the user will have to insert
+# a bindvalue for the literal position(s) in the correct offset of \@bind
{
my $sql = SQL::Abstract->new;
- my $data = { event => 'rapture', time => \ 'now()', func => \ 'somefunc(?)', stuff => 'fluff', };
+ my $data = {
+ event => 'rapture',
+ stuff => 'fluff',
+ time => \ 'now()',
+ xfunc => \ 'xfunc(?)',
+ yfunc => ['yfunc(?)', 'ystuff' ],
+ zfunc => \['zfunc(?)', 'zstuff' ],
+ zzlast => 'zzstuff',
+ };
my ($stmt, @bind) = $sql->insert ('table', $data);
is_same_sql_bind (
$stmt,
\@bind,
- 'INSERT INTO table ( event, func, stuff, time) VALUES ( ?, somefunc (?), ?, now() )',
- [qw/rapture fluff/], # event < stuff
+ 'INSERT INTO table ( event, stuff, time, xfunc, yfunc, zfunc, zzlast) VALUES ( ?, ?, now(), xfunc (?), yfunc(?), zfunc(?), ? )',
+ [qw/rapture fluff ystuff zstuff zzstuff/], # event < stuff
);
is_same_bind (
[$sql->values ($data)],
- [\@bind],
+ [@bind],
'values() output matches that of initial bind'
- );
+ ) || diag "Corresponding SQL statement: $stmt";
}