com php-src: Try fixing PDO MySQL pconnect test: ext/pdo/pdo_ dbh.c ext/pdo_mysql/tests/pdo_mysql___construct _uri.phpt
| From: | Nikita Popov | Date: | Sat, 04 Apr 2015 14:00:17 +0000 |
| Subject: | com php-src: Try fixing PDO MySQL pconnect test: ext/pdo/pdo_ dbh.c ext/pdo_mysql/tests/pdo_mysql___construct _uri.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86072@lists.php.net to get a copy of this message | ||
Commit: 30d59aed1c5a27435149c0609ad8a66802df117d
Author: Nikita Popov <nikic@php.net> Sat, 4 Apr 2015 15:58:00 +0200
Parents: f3e3d85bb2dec908f348e470f64bd99001345998
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=30d59aed1c5a27435149c0609ad8a66802df117d
Log:
Try fixing PDO MySQL pconnect test
Use less aggressive conversion to exceptions, in particular
do not convert warnings that happen during check_liveness. If the
server has gone away this will just reconnect and we still end up
with a valid connection, so it shouldn't throw.
Also drop some unnecessary checks for malloc returning NULL.
Changed paths:
M ext/pdo/pdo_dbh.c
M ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
Diff:
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 41d3974..47cba0e 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -216,6 +216,7 @@ static PHP_METHOD(PDO, dbh_constructor)
zend_restore_error_handling(&zeh);
return;
}
+ zend_restore_error_handling(&zeh);
/* parse the data source name */
colon = strchr(data_source, ':');
@@ -226,7 +227,6 @@ static PHP_METHOD(PDO, dbh_constructor)
snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source);
if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) {
- zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name");
return;
}
@@ -235,7 +235,6 @@ static PHP_METHOD(PDO, dbh_constructor)
colon = strchr(data_source, ':');
if (!colon) {
- zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via INI:
%s)", alt_dsn);
return;
}
@@ -245,13 +244,11 @@ static PHP_METHOD(PDO, dbh_constructor)
/* the specified URI holds connection details */
data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn));
if (!data_source) {
- zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI");
return;
}
colon = strchr(data_source, ':');
if (!colon) {
- zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via
URI)");
return;
}
@@ -262,7 +259,6 @@ static PHP_METHOD(PDO, dbh_constructor)
if (!driver) {
/* NB: don't want to include the data_source in the error message as
* it might contain a password */
- zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "could not find driver");
return;
}
@@ -317,15 +313,8 @@ static PHP_METHOD(PDO, dbh_constructor)
/* need a brand new pdbh */
pdbh = pecalloc(1, sizeof(*pdbh), 1);
- if (!pdbh) {
- php_error_docref(NULL, E_ERROR, "out of memory while allocating PDO handle");
- /* NOTREACHED */
- }
-
pdbh->is_persistent = 1;
- if (!(pdbh->persistent_id = pemalloc(plen + 1, 1))) {
- php_error_docref(NULL, E_ERROR, "out of memory while allocating PDO handle");
- }
+ pdbh->persistent_id = pemalloc(plen + 1, 1);
memcpy((char *)pdbh->persistent_id, hashkey, plen+1);
pdbh->persistent_id_len = plen;
pdbh->def_stmt_ce = dbh->def_stmt_ce;
@@ -363,6 +352,8 @@ static PHP_METHOD(PDO, dbh_constructor)
goto options;
}
+ zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh);
+
if (driver->db_handle_factory(dbh, options)) {
/* all set */
diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
index 87a6912..d5dd3e6 100644
--- a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
+++ b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
@@ -68,6 +68,9 @@ MySQLPDOTest::skip();
print "done!";
?>
--EXPECTF--
+Warning: PDO::__construct(file:/tmp/pdomuri.tst): failed to open stream: No such file or directory
in %s on line %d
[002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes,
'mysql%sdbname=%s'), invalid data source URI
+
+Warning: PDO::__construct(file:/tmp/pdomuri.tst): failed to open stream: No such file or directory
in %s on line %d
[003] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes,
'mysql%sdbname=letshopeinvalid%s'), chr(0) test, invalid data source URI
done!