summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Baratz <adambaratz@php.net>2016-09-13 17:02:53 -0400
committerAdam Baratz <adambaratz@php.net>2016-09-13 17:02:53 -0400
commitf6b6e97b29b7155efabbd935fc5f1cbdf548d601 (patch)
tree61513a6abe431c2c242365cef27d451ee443564b
parent45850213bd1c924e83e4b291bc475788762e103b (diff)
parentbcee34c649c7a26bebf282ca94e08ef06b882017 (diff)
downloadphp-git-f6b6e97b29b7155efabbd935fc5f1cbdf548d601.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Add special case for earlier versions of TDS Adjust error formatting so ext/pdo/tests/bug_43130.phpt passes with pdo_dblib Free error and message strings when cleaning up PDO instances that use pdo_dblib Add common suite
-rw-r--r--ext/pdo/tests/pdo_018.phpt17
-rw-r--r--ext/pdo_dblib/dblib_driver.c6
-rw-r--r--ext/pdo_dblib/dblib_stmt.c16
-rw-r--r--ext/pdo_dblib/pdo_dblib.c20
-rw-r--r--ext/pdo_dblib/php_pdo_dblib_int.h2
-rw-r--r--ext/pdo_dblib/tests/common.phpt17
6 files changed, 59 insertions, 19 deletions
diff --git a/ext/pdo/tests/pdo_018.phpt b/ext/pdo/tests/pdo_018.phpt
index d931a2c1c0..80e3453287 100644
--- a/ext/pdo/tests/pdo_018.phpt
+++ b/ext/pdo/tests/pdo_018.phpt
@@ -129,9 +129,20 @@ unset($stmt);
echo "===DATA===\n";
$res = $db->query('SELECT test.val FROM test')->fetchAll(PDO::FETCH_COLUMN);
-// For Oracle map NULL to empty string so the test doesn't diff
-if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci' && $res[0] === null) {
- $res[0] = "";
+switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
+ case 'dblib':
+ // map whitespace (from early TDS versions) to empty string so the test doesn't diff
+ if ($res[0] === ' ') {
+ $res[0] = '';
+ }
+ break;
+
+ case 'oci':
+ // map NULL to empty string so the test doesn't diff
+ if ($res[0] === null) {
+ $res[0] = '';
+ }
+ break;
}
var_dump($res);
diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c
index 13ddd8a472..3e0529fa1d 100644
--- a/ext/pdo_dblib/dblib_driver.c
+++ b/ext/pdo_dblib/dblib_driver.c
@@ -57,6 +57,11 @@ static int dblib_fetch_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
msg = einfo->dberrstr;
}
+ /* don't return anything if there's nothing to return */
+ if (msg == NULL && einfo->dberr == 0 && einfo->oserr == 0 && einfo->severity == 0) {
+ return 0;
+ }
+
spprintf(&message, 0, "%s [%d] (severity %d) [%s]",
msg, einfo->dberr, einfo->severity, stmt ? stmt->active_query_string : "");
@@ -88,6 +93,7 @@ static int dblib_handle_closer(pdo_dbh_t *dbh)
}
pefree(H, dbh->is_persistent);
dbh->driver_data = NULL;
+ pdo_dblib_err_dtor(&H->err);
}
return 0;
}
diff --git a/ext/pdo_dblib/dblib_stmt.c b/ext/pdo_dblib/dblib_stmt.c
index 311d856d55..1c0577e611 100644
--- a/ext/pdo_dblib/dblib_stmt.c
+++ b/ext/pdo_dblib/dblib_stmt.c
@@ -95,22 +95,6 @@ static char *pdo_dblib_get_field_name(int type)
}
/* }}} */
-static void pdo_dblib_err_dtor(pdo_dblib_err *err)
-{
- if (err->dberrstr) {
- efree(err->dberrstr);
- err->dberrstr = NULL;
- }
- if (err->lastmsg) {
- efree(err->lastmsg);
- err->lastmsg = NULL;
- }
- if (err->oserrstr) {
- efree(err->oserrstr);
- err->oserrstr = NULL;
- }
-}
-
static int pdo_dblib_stmt_cursor_closer(pdo_stmt_t *stmt)
{
pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data;
diff --git a/ext/pdo_dblib/pdo_dblib.c b/ext/pdo_dblib/pdo_dblib.c
index f1016de125..d19429ec34 100644
--- a/ext/pdo_dblib/pdo_dblib.c
+++ b/ext/pdo_dblib/pdo_dblib.c
@@ -146,6 +146,26 @@ int pdo_dblib_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
return 0;
}
+void pdo_dblib_err_dtor(pdo_dblib_err *err)
+{
+ if (!err) {
+ return;
+ }
+
+ if (err->dberrstr) {
+ efree(err->dberrstr);
+ err->dberrstr = NULL;
+ }
+ if (err->lastmsg) {
+ efree(err->lastmsg);
+ err->lastmsg = NULL;
+ }
+ if (err->oserrstr) {
+ efree(err->oserrstr);
+ err->oserrstr = NULL;
+ }
+}
+
static PHP_GINIT_FUNCTION(dblib)
{
memset(dblib_globals, 0, sizeof(*dblib_globals));
diff --git a/ext/pdo_dblib/php_pdo_dblib_int.h b/ext/pdo_dblib/php_pdo_dblib_int.h
index 87a0038ef4..01c538eed7 100644
--- a/ext/pdo_dblib/php_pdo_dblib_int.h
+++ b/ext/pdo_dblib/php_pdo_dblib_int.h
@@ -108,6 +108,8 @@ typedef struct {
char *lastmsg;
} pdo_dblib_err;
+void pdo_dblib_err_dtor(pdo_dblib_err *err);
+
typedef struct {
LOGINREC *login;
DBPROCESS *link;
diff --git a/ext/pdo_dblib/tests/common.phpt b/ext/pdo_dblib/tests/common.phpt
new file mode 100644
index 0000000000..27f503c781
--- /dev/null
+++ b/ext/pdo_dblib/tests/common.phpt
@@ -0,0 +1,17 @@
+--TEST--
+DBLIB
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo_dblib')) die('skip not loaded');
+?>
+--REDIRECTTEST--
+# magic auto-configuration
+
+return [
+ 'ENV' => [
+ 'PDOTEST_DSN' => getenv('PDO_DBLIB_TEST_DSN') ?: 'dblib:host=localhost;dbname=test',
+ 'PDOTEST_USER' => getenv('PDO_DBLIB_TEST_USER') ?: 'php',
+ 'PDOTEST_PASS' => getenv('PDO_DBLIB_TEST_PASS') ?: 'password',
+ ],
+ 'TESTS' => __DIR__ . '/ext/pdo/tests',
+];