]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 316971: [PostgreSQL] ./collectstats.pl --regenerate fails - Patch by Frédéric...
authorlpsolit%gmail.com <>
Fri, 23 Dec 2005 10:08:46 +0000 (10:08 +0000)
committerlpsolit%gmail.com <>
Fri, 23 Dec 2005 10:08:46 +0000 (10:08 +0000)
Bugzilla/DB.pm
Bugzilla/DB/Mysql.pm
Bugzilla/DB/Pg.pm
collectstats.pl

index ec189b7eed381f795cf9b56a921c048dd6622058..13d754e6bdf498bc9ff2ccfc63d17befabef82fe 100644 (file)
@@ -1118,6 +1118,13 @@ formatted SQL command have prefix C<sql_>. All other methods have prefix C<bz_>.
  Returns:     formatted SQL for limiting number of rows returned from query
               with optional offset (e.g. LIMIT 1, 1) (scalar)
 
+=item C<sql_from_days>
+
+ Description: Outputs SQL syntax for converting Julian days to date.
+              Abstract method, should be overriden by database specific code.
+ Params:      $days = days to convert to date
+ Returns:     formatted SQL for returning Julian days in dates. (scalar)
+
 =item C<sql_to_days>
 
  Description: Outputs SQL syntax for converting date to Julian days.
index ecdf63517823281f9aea4bcbf562f94661d2e56c..c753e8883a878c08f8eccc0a41ff372ba8dd9f35 100644 (file)
@@ -117,6 +117,12 @@ sub sql_istring {
     return $string;
 }
 
+sub sql_from_days {
+    my ($self, $days) = @_;
+
+    return "FROM_DAYS($days)";
+}
+
 sub sql_to_days {
     my ($self, $date) = @_;
 
index 8fc522490a862af21a32069c971e7370c62c1a79..e0a8e7ff5fcc2c51c50b3ab02601e858bb9ab080 100644 (file)
@@ -106,6 +106,12 @@ sub sql_limit {
     }
 }
 
+sub sql_from_days {
+    my ($self, $days) = @_;
+
+    return "TO_TIMESTAMP(${days}::int, 'J')::date";
+}
+
 sub sql_to_days {
     my ($self, $date) = @_;
 
index e087c28d046adc35c3e7bbda713c5b02b64f1117..2d7d3d25846b9c7345e8316b6878a228349a11f6 100755 (executable)
@@ -286,7 +286,7 @@ sub regenerate_stats {
                         $dbh->sql_to_days('current_date') . " AS end, " .
                         $dbh->sql_to_days("'1970-01-01'") . 
             " FROM bugs $from_product WHERE " .
-            $dbh->sql_to_days('creation_ts') . " != 'NULL'" .
+            $dbh->sql_to_days('creation_ts') . " IS NOT NULL " .
             $and_product .
             " ORDER BY start " . $dbh->sql_limit(1));
     
@@ -316,8 +316,8 @@ FIN
             # Get a list of bugs that were created the previous day, and
             # add those bugs to the list of bugs for this product.
             SendSQL("SELECT bug_id FROM bugs $from_product " .
-                    "WHERE bugs.creation_ts < from_days(" . ($day - 1) . ") " . 
-                    "AND bugs.creation_ts >= from_days(" . ($day - 2) . ") " .
+                    " WHERE bugs.creation_ts < " . $dbh->sql_from_days($day - 1) .
+                    " AND bugs.creation_ts >= " . $dbh->sql_from_days($day - 2) .
                     $and_product .
                     " ORDER BY bug_id");
             
@@ -354,8 +354,8 @@ FIN
                         "    ON bugs_activity.fieldid = fielddefs.fieldid " .
                         " WHERE fielddefs.name = 'bug_status' " .
                         "   AND bugs_activity.bug_id = $bug " .
-                        "   AND bugs_activity.bug_when >= from_days($day) " .
-                      "ORDER BY bugs_activity.bug_when " .
+                        "   AND bugs_activity.bug_when >= " . $dbh->sql_from_days($day) .
+                     ORDER BY bugs_activity.bug_when " .
                         $dbh->sql_limit(1));
                 
                 my $status;
@@ -377,8 +377,8 @@ FIN
                         "    ON bugs_activity.fieldid = fielddefs.fieldid " .
                         " WHERE fielddefs.name = 'resolution' " .
                         "   AND bugs_activity.bug_id = $bug " .
-                        "   AND bugs_activity.bug_when >= from_days($day) " .
-                      "ORDER BY bugs_activity.bug_when " . 
+                        "   AND bugs_activity.bug_when >= " . $dbh->sql_from_days($day) .
+                     ORDER BY bugs_activity.bug_when " . 
                         $dbh->sql_limit(1));
                         
                 if (@row = FetchSQLData()) {