php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #54648
Patch PDO_DBLIB-force-format-of-datetime-fields revision 2011-11-15 13:23 UTC by steven dot lambeth at gmx dot de

Patch PDO_DBLIB-force-format-of-datetime-fields for PDO DBlib Bug #54648

Patch version 2011-11-15 13:23 UTC

Return to Bug #54648 | Download this patch
Patch Revisions:

Developer: steven.lambeth@gmx.de

Index: trunk/ext/pdo_dblib/tests/bug_54648.phpt
===================================================================
--- trunk/ext/pdo_dblib/tests/bug_54648.phpt	(Revision 0)
+++ trunk/ext/pdo_dblib/tests/bug_54648.phpt	(Revision 0)
@@ -0,0 +1,26 @@
+--TEST--
+PDO_DBLIB: Does not force correct dateformat
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_dblib')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/config.inc';
+$db->query('set dateformat ymd'); 
+$rs = $db->query("select cast('1950-01-18 23:00:00' as smalldatetime) as sdt, cast('2030-01-01 23:59:59' as datetime) as dt");
+var_dump($rs->fetchAll(PDO::FETCH_ASSOC));
+echo "Done.\n";
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  array(2) {
+    ["sdt"]=>
+    string(19) "1950-01-18 23:00:00"
+    ["dt"]=>
+    string(19) "2030-01-01 23:59:59"
+  }
+}
+Done.
Index: trunk/ext/pdo_dblib/dblib_stmt.c
===================================================================
--- trunk/ext/pdo_dblib/dblib_stmt.c	(Revision 319239)
+++ trunk/ext/pdo_dblib/dblib_stmt.c	(Arbeitskopie)
@@ -243,6 +243,27 @@
 			*ptr = tmp_ptr;
 			break;
 		}
+		case SQLDATETIM4:
+		case SQLDATETIME: {	
+			DBDATETIME dt;
+			DBDATEREC di;	
+			tmp_ptr = emalloc(20);	
+			
+			dbconvert(H->link, coltype, (BYTE*) *ptr, -1, SQLDATETIME, (LPBYTE) &dt, -1);
+			dbdatecrack(H->link, &di, &dt);		
+			
+			spprintf((char**) &tmp_ptr, 0, "%d-%02d-%02d %02d:%02d:%02d",
+#ifdef PHP_DBLIB_IS_MSSQL || MSDBLIB
+					di.year,     di.month,       di.day,        di.hour,     di.minute,     di.second
+#else
+					di.dateyear, di.datemonth+1, di.datedmonth, di.datehour, di.dateminute, di.datesecond
+#endif
+				);
+
+			*len = 19;
+			*ptr = (char*) tmp_ptr;
+			break;
+		}		
 		default:
 			if (dbwillconvert(coltype, SQLCHAR)) {
 				tmp_len = 32 + (2 * (*len));
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 23:01:31 2024 UTC