[Bps-public-commit] dbix-searchbuilder branch, experimental, created. 1.59-54-g77debaa

Ruslan Zakirov ruz at bestpractical.com
Wed Jun 1 11:36:22 EDT 2011


The branch, experimental has been created
        at  77debaa909259cc5bad8947f379d788af71c9eb4 (commit)

- Log -----------------------------------------------------------------
commit 25fc357c4ecea12e46adfafd566d8c8329e28aff
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 28 15:54:20 2011 +0400

    ignore leading zeros in tests

diff --git a/t/02records_datetime.t b/t/02records_datetime.t
index cc49c87..63d34c0 100644
--- a/t/02records_datetime.t
+++ b/t/02records_datetime.t
@@ -111,7 +111,7 @@ SKIP: {
         { Type => 'month' },
         {
             '' => undef,
-            '2011-05-20 19:53:23' => '05',
+            '2011-05-20 19:53:23' => 5,
         },
     );
 
@@ -164,6 +164,8 @@ sub run_test {
     }
     foreach my $key ( keys %got ) {
         delete $got{ $key } unless exists $expected->{ $key };
+
+        $got{ $key } =~ s/^0+(?!$)// if defined $got{ $key };
     }
     local $Test::Builder::Level = $Test::Builder::Level + 1;
     is_deeply( \%got, $expected, "correct ". $props->{'Type'} ." function" )

commit 4291d1ebc8b10ca43804e0560ec4d89e3c0dbca2
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat May 28 15:54:53 2011 +0400

    use DB specific date time functions instead of SUBSTR

diff --git a/lib/DBIx/SearchBuilder/Handle/Oracle.pm b/lib/DBIx/SearchBuilder/Handle/Oracle.pm
index 4a44b71..0f01d8a 100755
--- a/lib/DBIx/SearchBuilder/Handle/Oracle.pm
+++ b/lib/DBIx/SearchBuilder/Handle/Oracle.pm
@@ -326,6 +326,24 @@ sub SimpleDateTimeFunctions {
 
     return $self->{'_simple_date_time_functions'} ||= {
         %res,
+        datetime   => "?",
+        time       => "TO_CHAR(?, 'HH24:MI:SS')",
+
+        hourly     => "TO_CHAR(?, 'YYYY-MM-DD HH24')",
+        hour       => "TO_CHAR(?, 'HH24')",
+
+        date       => "TO_CHAR(?, 'YYYY-MM-DD')",
+        daily      => "TO_CHAR(?, 'YYYY-MM-DD')",
+
+        day        => "TO_CHAR(?, 'DD')",
+        dayofmonth => "TO_CHAR(?, 'DD')",
+
+        monthly    => "TO_CHAR(?, 'YYYY-MM')",
+        month      => "TO_CHAR(?, 'MM')",
+
+        annually   => "TO_CHAR(?, 'YYYY')",
+        year       => "TO_CHAR(?, 'YYYY')",
+
         dayofweek  => "TO_CHAR(?, 'D') - 1", # 1-7, 1 - Sunday
         dayofyear  => "TO_CHAR(?, 'DDD')", # 1-366
         # no idea about props
diff --git a/lib/DBIx/SearchBuilder/Handle/Pg.pm b/lib/DBIx/SearchBuilder/Handle/Pg.pm
index ce37b42..05bf8a4 100755
--- a/lib/DBIx/SearchBuilder/Handle/Pg.pm
+++ b/lib/DBIx/SearchBuilder/Handle/Pg.pm
@@ -260,8 +260,27 @@ sub SimpleDateTimeFunctions {
     my %res = %{ $self->SUPER::SimpleDateTimeFunctions(@_) };
     s/SUBSTR\s*\(\s*\?/SUBSTR( CAST(? AS text)/ig for values %res;
 
+    # everything else we should implement through date_trunc that
+    # does SUBSTR(?, 1, X) on a date, but leaves trailing values
+    # when we don't need them
+
     return $self->{'_simple_date_time_functions'} ||= {
         %res,
+        datetime   => '?',
+        time       => 'CAST(? AS time)',
+
+        hour       => 'EXTRACT(HOUR FROM ?)',
+
+        date       => 'CAST(? AS date)',
+        daily      => 'CAST(? AS date)',
+
+        day        => 'EXTRACT(DAY FROM ?)',
+
+        month      => 'EXTRACT(MONTH FROM ?)',
+
+        annually   => 'EXTRACT(YEAR FROM ?)',
+        year       => 'EXTRACT(YEAR FROM ?)',
+
         dayofweek  => "EXTRACT(DOW  FROM ?)", # 0-6, 0 - Sunday
         dayofyear  => "EXTRACT(DOY  FROM ?)", # 1-366
         # 1-53, 1st week January 4, week starts on Monay
diff --git a/lib/DBIx/SearchBuilder/Handle/SQLite.pm b/lib/DBIx/SearchBuilder/Handle/SQLite.pm
index 1f1c083..a8b9e29 100644
--- a/lib/DBIx/SearchBuilder/Handle/SQLite.pm
+++ b/lib/DBIx/SearchBuilder/Handle/SQLite.pm
@@ -153,6 +153,24 @@ sub SimpleDateTimeFunctions {
     my $self = shift;
     return $self->{'_simple_date_time_functions'} ||= {
         %{ $self->SUPER::SimpleDateTimeFunctions(@_) },
+        datetime   => 'datetime(?)',
+        time       => 'time(?)',
+
+        hourly     => "strftime('%Y-%m-%d %H', ?)",
+        hour       => "strftime('%H', ?)",
+
+        date       => 'date(?)',
+        daily      => 'date(?)',
+
+        day        => "strftime('%d', ?)",
+        dayofmonth => "strftime('%d', ?)",
+
+        monthly    => "strftime('%Y-%m', ?)",
+        month      => "strftime('%m', ?)",
+
+        annually   => "strftime('%Y', ?)",
+        year       => "strftime('%Y', ?)",
+
         dayofweek  => "strftime('%w', ?)",
         dayofyear  => "strftime('%j', ?)",
         weekofyear => "strftime('%W', ?)",
diff --git a/lib/DBIx/SearchBuilder/Handle/mysql.pm b/lib/DBIx/SearchBuilder/Handle/mysql.pm
index 0ebcbec..65f93e7 100755
--- a/lib/DBIx/SearchBuilder/Handle/mysql.pm
+++ b/lib/DBIx/SearchBuilder/Handle/mysql.pm
@@ -141,6 +141,24 @@ sub SimpleDateTimeFunctions {
     my $self = shift;
     return $self->{'_simple_date_time_functions'} ||= {
         %{ $self->SUPER::SimpleDateTimeFunctions(@_) },
+        datetime   => '?',
+        time       => 'TIME(?)',
+
+        hourly     => "DATE_FORMAT(?, '%Y-%m-%d %H')",
+        hour       => 'HOUR(?)',
+
+        date       => 'DATE(?)',
+        daily      => 'DATE(?)',
+
+        day        => 'DAYOFMONTH(?)',
+        dayofmonth => 'DAYOFMONTH(?)',
+
+        monthly    => "DATE_FORMAT(?, '%Y-%m')",
+        month      => 'MONTH(?)',
+
+        annually   => 'YEAR(?)',
+        year       => 'YEAR(?)',
+
         dayofweek  => "DAYOFWEEK(?) - 1", # 1-7, 1 - Sunday
         dayofyear  => "DAYOFYEAR(?)", # 1-366
         weekofyear => "WEEK(?)", # skip mode argument, so it can be controlled in mysql config

commit 1079063c88385ff8642606c4f861310b74a179dc
Merge: 9a26dd4 9d4a091
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun May 29 02:30:18 2011 +0400

    Merge branch 'functions-in-limit' into tmp
    
    Conflicts:
    	lib/DBIx/SearchBuilder.pm


commit 77debaa909259cc5bad8947f379d788af71c9eb4
Merge: 1079063 4291d1e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun May 29 02:30:27 2011 +0400

    Merge branch 'date-time-helpers' into tmp


-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list