[Bps-public-commit] dbix-searchbuilder branch, pg-age-func-is-wrong-choice, created. 1.64-1-gac70768

Ruslan Zakirov ruz at bestpractical.com
Tue Jul 2 04:49:48 EDT 2013


The branch, pg-age-func-is-wrong-choice has been created
        at  ac70768af21cebec371f4d0296ce07f210640caf (commit)

- Log -----------------------------------------------------------------
commit ac70768af21cebec371f4d0296ce07f210640caf
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jul 2 12:46:09 2013 +0400

    AGE(...) returns "rounded" interval when we need exact
    
    AGE function returns interval, but it's not "object", but
    stringified representation with months equal to 30 days, so
    during conversion to epoch information is lost.
    
    Use substraction of epoch values instead of the function.
    Cover with a test.

diff --git a/lib/DBIx/SearchBuilder/Handle/Pg.pm b/lib/DBIx/SearchBuilder/Handle/Pg.pm
index 7f0cfd3..14be2bf 100755
--- a/lib/DBIx/SearchBuilder/Handle/Pg.pm
+++ b/lib/DBIx/SearchBuilder/Handle/Pg.pm
@@ -329,7 +329,7 @@ sub _DateTimeIntervalFunction {
     my $self = shift;
     my %args = ( From => undef, To => undef, @_ );
 
-    return "EXTRACT(EPOCH FROM AGE($args{'To'}, $args{'From'}))";
+    return "(EXTRACT(EPOCH FROM $args{'To'}) - EXTRACT(EPOCH FROM $args{'From'}))";
 }
 
 sub HasSupportForNullsOrder {
diff --git a/t/02records_dt_interval.t b/t/02records_dt_interval.t
index ce0e6f3..ef1ead3 100644
--- a/t/02records_dt_interval.t
+++ b/t/02records_dt_interval.t
@@ -8,7 +8,7 @@ use Test::More;
 BEGIN { require "t/utils.pl" }
 our (@AvailableDrivers);
 
-use constant TESTS_PER_DRIVER => 15;
+use constant TESTS_PER_DRIVER => 17;
 
 my $total = scalar(@AvailableDrivers) * TESTS_PER_DRIVER;
 plan tests => $total;
@@ -158,6 +158,7 @@ sub init_data {
     [ '2011-05-20 19:53:23', '2011-05-20 19:53:23', 0],
     [ '2011-05-20 19:53:23', '2011-05-21 20:54:24', 1*24*60*60+1*60*60+1*60+1],
     [ '2011-05-20 19:53:23', '2011-05-19 18:52:22', -(1*24*60*60+1*60*60+1*60+1)],
+    [ '2011-05-20 19:53:23', '2012-09-20 19:53:23', 42249600],
     );
 }
 

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



More information about the Bps-public-commit mailing list