}
sub _unsupported_date_extraction {
- "date part extraction not supported for part $_[1] with database $_[2]"
+ "date part extraction not supported for part \"$_[1]\" with database \"$_[2]\""
}
sub _unsupported_date_diff {
- "date diff not supported for part $_[1] with database $_[2]"
+ "date diff not supported for part \"$_[1]\" with database \"$_[2]\""
}
sub _datetime_sql { die 'date part extraction not implemented for this database' }
use warnings;
use Test::More;
+use Test::Fatal;
use lib qw(t/lib);
use DBIC::SqlMakerTest;
WHERE artist.when_began = ?
",
[['artist.when_began', '2010-12-14 12:12:12']],
+ '-dt works'
);
is_same_sql_bind (
['artist.when_began', '2010-12-14 12:12:12'],
['artist.when_ended', '2010-12-16 12:12:12'],
],
+ '-dt works'
);
is_same_sql_bind (
{ -op => [ '=', 12, { -dt_month => { -ident => 'artist.when_began' } } ] },
{ -op => [ '=', 2010, { -dt_get => [year => \'artist.when_began'] } ] },
{ -op => [ '=', 14, { -dt_get => [day_of_month => \'artist.when_began'] } ] },
- { -op => [ '=', 10, { -dt_diff => [second => { -ident => 'artist.when_began' }, \'artist.when_ended'] } ] },
+ { -op => [ '=', 100, { -dt_diff => [second => { -ident => 'artist.when_began' }, \'artist.when_ended'] } ] },
+ { -op => [ '=', 10, { -dt_diff => [day => { -ident => 'artist.when_played_last' }, \'artist.when_ended'] } ] },
]
} ) ],
"SELECT *
( ? = STRFTIME('%m', artist.when_began) ) AND
( ? = STRFTIME('%Y', artist.when_began) ) AND
( ? = STRFTIME('%d', artist.when_began) ) AND
- ( ? = ( STRFTIME('%s', artist.when_began) - STRFTIME('%s', artist.when_ended)))
+ ( ? = ( STRFTIME('%s', artist.when_began) - STRFTIME('%s', artist.when_ended))) AND
+ ( ? = ( JULIANDAY(artist.when_played_last) - JULIANDAY(artist.when_ended)))
) )
",
[
['', 12],
['', 2010],
['', 14],
+ ['', 100],
['', 10],
],
+ '-dt_month, -dt_get, and -dt_diff work'
);
+like exception { $sql_maker->select('foo', '*', { -dt_diff => [year => \'artist.lololol', \'artist.fail'] }) }, qr/date diff not supported for part "year" with database "SQLite"/, 'SQLite does not support year diff';
+
done_testing;