Development

#2234 (0000-00-00 gives me grief)

You must first sign up to be able to contribute.

Ticket #2234 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

0000-00-00 gives me grief

Reported by: alex@webjitsu.co.uk Assigned to: fabien
Priority: minor Milestone: 1.0.18
Component: other Version: 1.0.17
Keywords: Cc:
Qualification: Unreviewed

Description

I was getting an error from getDate method, that it couldn't convert. So I made this change in ResultSetCommon?.php. I am sure this is not the first table with null dates. So my hack probably isn't needed. What am I doing wrong?

/**

  • @see ResultSet::getDate() */

public function getDate($column, $format = '%x') {

$idx = (is_int($column) ? $column - 1 : $column); if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); } if ($this->fields[$idx] === null) { return null; } $ts = strtotime($this->fields[$idx]);

if ($ts === -1 $ts === false) { // in PHP 5.1 return value changes to FALSE

return null; //Alex Jackson change.... so that 0000-00-00 //the following is the original //throw new SQLException("Unable to convert value at column " . $column . " to timestamp: " . $this->fields[$idx]);

} if ($format === null) {

return $ts;

} if (strpos($format, '%') !== false) {

return strftime($format, $ts);

} else {

return date($format, $ts);

}

}

Change History

10/12/07 16:57:28 changed by noel

  • qualification set to Unreviewed.
  • milestone set to 1.0.9.

11/14/07 08:02:48 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

in r6003 and r6004

07/07/08 16:24:36 changed by utdrmac

  • status changed from closed to reopened.
  • version changed from 1.0.0 to 1.0.17.
  • resolution deleted.

07/07/08 16:27:29 changed by utdrmac

This never ported to mysqli/MySQLiResultSet.php. Couldn't figure out why when using the latest 1.0 branch of symfony I was still getting these types of errors about 0000-00-00. Turns out someone patched MySQLResultSet but never did MySQLiResultSet.

diff -ur MySQLiResultSet.php.orig MySQLiResultSet.php
--- MySQLiResultSet.php.orig	2008-07-07 09:20:01.000000000 -0500
+++ MySQLiResultSet.php	2008-07-07 09:21:47.000000000 -0500
@@ -130,21 +130,11 @@
      */
     public function getTimestamp($column, $format='Y-m-d H:i:s')
     {
-        if (is_int($column)) {
-            // because Java convention is to start at 1
-            $column--;
-        }
-
-        if (!array_key_exists($column, $this->fields)) {
-            throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column));
-        }
-
-	if ($this->fields[$column] === null) {
-		return null;
-	}
+        if (is_int($column)) { $column--; } // because Java convention is to start at 1
+        if (!array_key_exists($column, $this->fields)) { throw new SQLException("Invalid resultset column: " . (is_int($column) ? $column + 1 : $column)); }
+        if ($this->fields[$column] === null || $this->fields[$column] == '0000-00-00 00:00:00') { return null; }
 
         $ts = strtotime($this->fields[$column]);
-
         if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE
             // otherwise it's an ugly MySQL timestamp!
             // YYYYMMDDHHMMSS
@@ -159,11 +149,9 @@
             // if it's still -1, then there's nothing to be done; use a different method.
             throw new SQLException("Unable to convert value at column " . (is_int($column) ? $column + 1 : $column) . " to timestamp: " . $this->fields[$column]);
         }
-
         if ($format === null) {
             return $ts;
         }
-
         if (strpos($format, '%') !== false) {
             return strftime($format, $ts);
         } else {

07/07/08 19:04:53 changed by fabien

  • milestone changed from 1.0.9 to 1.0.18.

08/19/08 16:20:41 changed by fabien

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [10948]) [1.0, 1.1, 1.2] fixed 0000-00-00 dates in mysqli creole driver (closes #2234)

09/02/08 10:36:57 changed by lazymanc

  • status changed from closed to reopened.
  • resolution deleted.

[10948] looks like a bad merge maybe, public function getDate() starts half way through getTimestamp() (line 151).

09/18/08 12:01:04 changed by nicolas

  • status changed from reopened to closed.
  • resolution set to fixed.

It's been fixed in r11017

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.