diff options
author | Anatol Belski <ab@php.net> | 2016-02-29 17:07:05 +0100 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2016-02-29 17:07:05 +0100 |
commit | 56ab4a6096552e684045bcc0bc87da84073331cc (patch) | |
tree | e6808cfe31f5f0833ebb61c11ec1121fe657becc /ext/pdo_dblib | |
parent | 44c3f1492f698f9ebc3e279d5e4471c7f576973f (diff) | |
parent | 53c036b30bdabedf841fb8716a7cd722bbab09a3 (diff) | |
download | php-git-56ab4a6096552e684045bcc0bc87da84073331cc.tar.gz |
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
Fixed #54648 PDO::MSSQL forces format of datetime fields
Diffstat (limited to 'ext/pdo_dblib')
-rw-r--r-- | ext/pdo_dblib/dblib_stmt.c | 19 | ||||
-rw-r--r-- | ext/pdo_dblib/tests/bug_54648.phpt | 26 |
2 files changed, 45 insertions, 0 deletions
diff --git a/ext/pdo_dblib/dblib_stmt.c b/ext/pdo_dblib/dblib_stmt.c index d8cd219b4a..0eff4945dd 100644 --- a/ext/pdo_dblib/dblib_stmt.c +++ b/ext/pdo_dblib/dblib_stmt.c @@ -268,6 +268,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 index 0000000000..aa9f292669 --- /dev/null +++ b/ext/pdo_dblib/tests/bug_54648.phpt @@ -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. |