]> granicus.if.org Git - php/commitdiff
Fixed #54648 PDO::MSSQL forces format of datetime fields
authorAnatol Belski <ab@php.net>
Mon, 29 Feb 2016 16:04:49 +0000 (17:04 +0100)
committerAnatol Belski <ab@php.net>
Mon, 29 Feb 2016 16:04:49 +0000 (17:04 +0100)
adopted patch by steven dot lambeth at gmx dot de

ext/pdo_dblib/dblib_stmt.c
ext/pdo_dblib/tests/bug_54648.phpt [new file with mode: 0644]

index e4a6d82200d02fc8bcb7a92e24aa496839fab631..86c6d8308bdf8aa2ccc962083879248d22687904 100644 (file)
@@ -265,6 +265,25 @@ static int pdo_dblib_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr,
                        *ptr = tmp_ptr;
                        break;
                }
+               case SQLDATETIM4:
+               case SQLDATETIME: {
+                       DBDATETIME dt;
+                       DBDATEREC di;
+
+                       dbconvert(H->link, coltype, (BYTE*) *ptr, -1, SQLDATETIME, (LPBYTE) &dt, -1);
+                       dbdatecrack(H->link, &di, &dt);
+
+                       *len = spprintf((char**) &tmp_ptr, 20, "%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
+                               );
+
+                       *ptr = (char*) tmp_ptr;
+                       break;
+               }
                default:
                        if (dbwillconvert(coltype, SQLCHAR)) {
                                tmp_len = 32 + (2 * (*len)); /* FIXME: We allocate more than we need here */
diff --git a/ext/pdo_dblib/tests/bug_54648.phpt b/ext/pdo_dblib/tests/bug_54648.phpt
new file mode 100644 (file)
index 0000000..aa9f292
--- /dev/null
@@ -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.