+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+
use strict;
use warnings;
use Test::More;
-use lib qw(t/lib);
-use DBIC::SqlMakerTest;
-use_ok('DBICTest');
+use DBICTest ':DiffSQL';
my $schema = DBICTest->init_schema;
my $rs;
-TODO: {
- local $TODO = 'bind args order needs fixing (semifor)';
-
+{
# First, the simple cases...
$rs = $schema->resultset('Artist')->search(
{ artistid => 1 },
->search({}, $where_bind);
is ( $rs->count, 1, 'where/bind last' );
+
+ # and the complex case
+ $rs = $schema->resultset('CustomSql')->search({}, { bind => [ 1999 ] })
+ ->search({ 'artistid' => 1 }, {
+ where => \'title like ?',
+ bind => [ 'Spoon%' ] });
+ is ( $rs->count, 1, '...cookbook + chained search with extra bind' );
}
{
$new_source->source_name('Complex');
$new_source->name(\<<'');
- ( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year
+ ( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year
FROM artist a
JOIN cd ON cd.artist = a.artistid
WHERE cd.year = ?)
->search({ 'artistid' => 1 });
is ( $rs->count, 1, '...cookbook (bind first) + chained search' );
- $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })->search({}, { where => \"title LIKE ?", bind => [ 'Spoon%' ] });
+ $rs = $schema->resultset('Complex')->search({}, { bind => [ [{ sqlt_datatype => 'datetime'} => 1999 ] ] })->search({}, { where => \"title LIKE ?", bind => [ 'Spoon%' ] });
is_same_sql_bind(
$rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM (SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year FROM artist a JOIN cd ON cd.artist = a.artistid WHERE cd.year = ?) me WHERE title LIKE ?)",
[
- [ '!!dummy' => '1999' ],
- [ '!!dummy' => 'Spoon%' ]
+ [ { sqlt_datatype => 'datetime' } => '1999' ],
+ [ {} => 'Spoon%' ]
],
'got correct SQL'
);
$rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM (SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year FROM artist a JOIN cd ON cd.artist = a.artistid WHERE cd.year = ?) me WHERE title LIKE ?)",
[
- [ '!!dummy' => '1999' ],
- [ '!!dummy' => 'Spoon%' ]
+ [ {} => '1999' ],
+ [ {} => 'Spoon%' ]
],
'got correct SQL (cookbook arbitrary SQL, in separate file)'
);
}
-TODO: {
- local $TODO = 'bind args order needs fixing (semifor)';
- $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })
- ->search({ 'artistid' => 1 }, {
- where => \'title like ?',
- bind => [ 'Spoon%' ] });
- is ( $rs->count, 1, '...cookbook + chained search with extra bind' );
-}
-
done_testing;