add on_or_(before|after) ops
[dbsrgits/DBIx-Class.git] / t / sqlmaker / op_dt.t
index f980ae7..5b40621 100644 (file)
@@ -158,35 +158,13 @@ $s;
 
 my %rs = map { $_ => $schema{$_}->resultset('Event') } keys %schema;
 
-$rs{sqlite}->populate([
- [qw(starts_at created_on skip_inflation)],
- ['2010-12-12', '2010-12-14 12:12:12', '2019-12-12 12:12:12'],
- ['2010-12-12', '2011-12-14 12:12:12', '2011-12-12 12:12:12'],
-]);
-
-$rs{mssql}->populate([
- [qw(starts_at created_on skip_inflation)],
- ['2010-12-12', '2010-12-14 12:12:12.000', '2019-12-12 12:12:12.000'],
- ['2010-12-12', '2011-12-14 12:12:12.000', '2011-12-12 12:12:12.000'],
-]) if $schema{mssql}->storage->connected;
-
-$rs{mysql}->populate([
- [qw(starts_at created_on skip_inflation)],
- ['2010-12-12', '2010-12-14 12:12:12.000', '2019-12-12 12:12:12.000'],
- ['2010-12-12', '2011-12-14 12:12:12.000', '2011-12-12 12:12:12.000'],
-]) if $schema{mysql}->storage->connected;
-
-$rs{postgres}->populate([
- [qw(starts_at created_on skip_inflation)],
- ['2010-12-12', '2010-12-14 12:12:12', '2019-12-12 12:12:12'],
- ['2010-12-12', '2011-12-14 12:12:12', '2011-12-12 12:12:12'],
-]) if $schema{postgres}->storage->connected;
-
-$rs{oracle}->populate([
- [qw(starts_at created_on skip_inflation)],
- ['2010-12-12', '2010-12-14 12:12:12', '2019-12-12 12:12:12'],
- ['2010-12-12', '2011-12-14 12:12:12', '2011-12-12 12:12:12'],
-]) if $schema{oracle}->storage->connected;
+for (grep { $schema{$_}->storage->connected } keys %rs) {
+   $rs{$_}->populate([
+     [qw(starts_at created_on skip_inflation)],
+     ['2010-12-12', '2010-12-14 12:12:12', '2019-12-12 12:12:12'],
+     ['2010-12-12', '2011-12-14 12:12:12', '2011-12-12 12:12:12'],
+   ])
+}
 
 my $date = DateTime->new(
    year => 2010,
@@ -875,6 +853,155 @@ my @tests = (
       hri    => [{ date => '2011-12-15 12:12:15.000000000' }],
     },
   },
+
+  {
+    msg    => '-dt_before works',
+    search => { 'me.created_on' => { -dt_before => '2011-12-14 12:12:12' } },
+    select   => [ [ -ident => 'me.created_on' ] ],
+    as       => [ 'date' ],
+    sqlite => {
+      select   => "me.created_on",
+      where => "me.created_on < ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }],
+    },
+    postgres => {
+      select   => "me.created_on",
+      where => "me.created_on < ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }],
+    },
+    mysql => {
+      select   => "me.created_on",
+      where => "me.created_on < ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }],
+    },
+    mssql => {
+      select   => "me.created_on",
+      where => "me.created_on < ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }],
+    },
+    oracle => {
+      select   => "me.created_on",
+      where => "me.created_on < ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }],
+    },
+  },
+
+  {
+    msg    => '-dt_on_or_before works',
+    search => { 'me.created_on' => { -dt_on_or_before => '2011-12-14 12:12:12' } },
+    select   => [ [ -ident => 'me.created_on' ] ],
+    as       => [ 'date' ],
+    sqlite => {
+      select   => "me.created_on",
+      where => "me.created_on <= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+    postgres => {
+      select   => "me.created_on",
+      where => "me.created_on <= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+    mysql => {
+      select   => "me.created_on",
+      where => "me.created_on <= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+    mssql => {
+      select   => "me.created_on",
+      where => "me.created_on <= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+    oracle => {
+      select   => "me.created_on",
+      where => "me.created_on <= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2011-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+  },
+
+  {
+    msg    => '-dt_after works',
+    search => { 'me.created_on' => { -dt_after => '2010-12-14 12:12:12' } },
+    select   => [ [ -ident => 'me.created_on' ] ],
+    as       => [ 'date' ],
+    sqlite => {
+      select   => "me.created_on",
+      where => "me.created_on > ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2011-12-14 12:12:12' }],
+    },
+    postgres => {
+      select   => "me.created_on",
+      where => "me.created_on > ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2011-12-14 12:12:12' }],
+    },
+    mysql => {
+      select   => "me.created_on",
+      where => "me.created_on > ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2011-12-14 12:12:12' }],
+    },
+    mssql => {
+      select   => "me.created_on",
+      where => "me.created_on > ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2011-12-14 12:12:12' }],
+    },
+    oracle => {
+      select   => "me.created_on",
+      where => "me.created_on > ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2011-12-14 12:12:12' }],
+    },
+  },
+
+  {
+    msg    => '-dt_on_or_after works',
+    search => { 'me.created_on' => { -dt_on_or_after => '2010-12-14 12:12:12' } },
+    select   => [ [ -ident => 'me.created_on' ] ],
+    as       => [ 'date' ],
+    sqlite => {
+      select   => "me.created_on",
+      where => "me.created_on >= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+    postgres => {
+      select   => "me.created_on",
+      where => "me.created_on >= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+    mysql => {
+      select   => "me.created_on",
+      where => "me.created_on >= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+    mssql => {
+      select   => "me.created_on",
+      where => "me.created_on >= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+    oracle => {
+      select   => "me.created_on",
+      where => "me.created_on >= ?",
+      bind   => [[{dbic_colname => 'me.created_on', sqlt_datatype => 'timestamp' }, '2010-12-14 12:12:12']],
+      hri    => [{ date => '2010-12-14 12:12:12' }, { date => '2011-12-14 12:12:12' }],
+    },
+  },
+
 );
 
 for my $t (@tests) {