Skip to content

Commit 53c036b

Browse files
committed
Fixed #54648 PDO::MSSQL forces format of datetime fields
adopted patch by steven dot lambeth at gmx dot de
1 parent 7816698 commit 53c036b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ext/pdo_dblib/dblib_stmt.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,25 @@ static int pdo_dblib_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr,
265265
*ptr = tmp_ptr;
266266
break;
267267
}
268+
case SQLDATETIM4:
269+
case SQLDATETIME: {
270+
DBDATETIME dt;
271+
DBDATEREC di;
272+
273+
dbconvert(H->link, coltype, (BYTE*) *ptr, -1, SQLDATETIME, (LPBYTE) &dt, -1);
274+
dbdatecrack(H->link, &di, &dt);
275+
276+
*len = spprintf((char**) &tmp_ptr, 20, "%d-%02d-%02d %02d:%02d:%02d",
277+
#ifdef PHP_DBLIB_IS_MSSQL || MSDBLIB
278+
di.year, di.month, di.day, di.hour, di.minute, di.second
279+
#else
280+
di.dateyear, di.datemonth+1, di.datedmonth, di.datehour, di.dateminute, di.datesecond
281+
#endif
282+
);
283+
284+
*ptr = (char*) tmp_ptr;
285+
break;
286+
}
268287
default:
269288
if (dbwillconvert(coltype, SQLCHAR)) {
270289
tmp_len = 32 + (2 * (*len)); /* FIXME: We allocate more than we need here */

ext/pdo_dblib/tests/bug_54648.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
PDO_DBLIB: Does not force correct dateformat
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_dblib')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
?>
8+
--FILE--
9+
<?php
10+
require dirname(__FILE__) . '/config.inc';
11+
$db->query('set dateformat ymd');
12+
$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");
13+
var_dump($rs->fetchAll(PDO::FETCH_ASSOC));
14+
echo "Done.\n";
15+
?>
16+
--EXPECT--
17+
array(1) {
18+
[0]=>
19+
array(2) {
20+
["sdt"]=>
21+
string(19) "1950-01-18 23:00:00"
22+
["dt"]=>
23+
string(19) "2030-01-01 23:59:59"
24+
}
25+
}
26+
Done.

0 commit comments

Comments
 (0)