Skip to content

Commit ac519ea

Browse files
committed
Merge branch 'master' of https://git.php.net/repository/php-src
* 'master' of https://git.php.net/repository/php-src: Remove obsolete flag Update DTrace probes Add test for oci_set_* error changes Make oci_set_*($connection,...) errors retrievable via oci_error($connection). Improve some error handling to produce error text on some rare edge cases. Disambiguate the Oracle library function call return status values from ORA error numbers. Review and unify error data types.
2 parents 6ece550 + 43289d6 commit ac519ea

File tree

11 files changed

+615
-419
lines changed

11 files changed

+615
-419
lines changed

ext/oci8/oci8.c

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,6 @@ PHP_MINIT_FUNCTION(oci)
13061306

13071307
PHP_RINIT_FUNCTION(oci)
13081308
{
1309-
OCI_G(debug_mode) = 0; /* start "fresh" */
13101309
OCI_G(num_links) = OCI_G(num_persistent);
13111310
OCI_G(errcode) = 0;
13121311
OCI_G(edition) = NULL;
@@ -1643,12 +1642,12 @@ void php_oci_connection_descriptors_free(php_oci_connection *connection TSRMLS_D
16431642
* Fetch & print out error message if we get an error
16441643
* Returns an Oracle error number
16451644
*/
1646-
sb4 php_oci_error(OCIError *err_p, sword status TSRMLS_DC)
1645+
sb4 php_oci_error(OCIError *err_p, sword errstatus TSRMLS_DC)
16471646
{
16481647
text *errbuf = (text *)NULL;
1649-
sb4 errcode = 0;
1648+
sb4 errcode = 0; /* Oracle error number */
16501649

1651-
switch (status) {
1650+
switch (errstatus) {
16521651
case OCI_SUCCESS:
16531652
break;
16541653
case OCI_SUCCESS_WITH_INFO:
@@ -1691,13 +1690,13 @@ sb4 php_oci_error(OCIError *err_p, sword status TSRMLS_DC)
16911690
php_error_docref(NULL TSRMLS_CC, E_WARNING, "OCI_CONTINUE");
16921691
break;
16931692
default:
1694-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown OCI error code: %d", status);
1693+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown OCI error code: %d", errstatus);
16951694
break;
16961695
}
16971696

16981697
#ifdef HAVE_OCI8_DTRACE
16991698
if (DTRACE_OCI8_ERROR_ENABLED()) {
1700-
DTRACE_OCI8_ERROR(status, errcode);
1699+
DTRACE_OCI8_ERROR((int)errstatus, (long)errcode);
17011700
}
17021701
#endif /* HAVE_OCI8_DTRACE */
17031702

@@ -2210,20 +2209,24 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
22102209
*/
22112210
static int php_oci_connection_ping(php_oci_connection *connection TSRMLS_DC)
22122211
{
2212+
sword errstatus;
2213+
2214+
OCI_G(errcode) = 0; /* assume ping is successful */
2215+
22132216
/* Use OCIPing instead of OCIServerVersion. If OCIPing returns ORA-1010 (invalid OCI operation)
22142217
* such as from Pre-10.1 servers, the error is still from the server and we would have
22152218
* successfully performed a roundtrip and validated the connection. Use OCIServerVersion for
22162219
* Pre-10.2 clients
22172220
*/
22182221
#if ((OCI_MAJOR_VERSION > 10) || ((OCI_MAJOR_VERSION == 10) && (OCI_MINOR_VERSION >= 2))) /* OCIPing available 10.2 onwards */
2219-
PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIPing, (connection->svc, OCI_G(err), OCI_DEFAULT));
2222+
PHP_OCI_CALL_RETURN(errstatus, OCIPing, (connection->svc, OCI_G(err), OCI_DEFAULT));
22202223
#else
22212224
char version[256];
22222225
/* use good old OCIServerVersion() */
2223-
PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIServerVersion, (connection->svc, OCI_G(err), (text *)version, sizeof(version), OCI_HTYPE_SVCCTX));
2226+
PHP_OCI_CALL_RETURN(errstatus, OCIServerVersion, (connection->svc, OCI_G(err), (text *)version, sizeof(version), OCI_HTYPE_SVCCTX));
22242227
#endif
22252228

2226-
if (OCI_G(errcode) == OCI_SUCCESS) {
2229+
if (errstatus == OCI_SUCCESS) {
22272230
return 1;
22282231
} else {
22292232
sb4 error_code = 0;
@@ -2234,10 +2237,9 @@ static int php_oci_connection_ping(php_oci_connection *connection TSRMLS_DC)
22342237
if (error_code == 1010) {
22352238
return 1;
22362239
}
2240+
OCI_G(errcode) = error_code;
22372241
}
22382242

2239-
/* ignore errors here, just return failure
2240-
* php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); */
22412243
return 0;
22422244
}
22432245
/* }}} */
@@ -2248,17 +2250,17 @@ static int php_oci_connection_ping(php_oci_connection *connection TSRMLS_DC)
22482250
*/
22492251
static int php_oci_connection_status(php_oci_connection *connection TSRMLS_DC)
22502252
{
2251-
ub4 ss = 0;
2253+
ub4 ss = OCI_SERVER_NOT_CONNECTED;
2254+
sword errstatus;
22522255

22532256
/* get OCI_ATTR_SERVER_STATUS */
2254-
PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrGet, ((dvoid *)connection->server, OCI_HTYPE_SERVER, (dvoid *)&ss, (ub4 *)0, OCI_ATTR_SERVER_STATUS, OCI_G(err)));
2257+
PHP_OCI_CALL_RETURN(errstatus, OCIAttrGet, ((dvoid *)connection->server, OCI_HTYPE_SERVER, (dvoid *)&ss, (ub4 *)0, OCI_ATTR_SERVER_STATUS, OCI_G(err)));
22552258

2256-
if (OCI_G(errcode) == OCI_SUCCESS && ss == OCI_SERVER_NORMAL) {
2259+
if (errstatus == OCI_SUCCESS && ss == OCI_SERVER_NORMAL) {
22572260
return 1;
22582261
}
22592262

2260-
/* ignore errors here, just return failure
2261-
* php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC); */
2263+
/* ignore errors here, just return failure */
22622264
return 0;
22632265
}
22642266
/* }}} */
@@ -2269,14 +2271,17 @@ static int php_oci_connection_status(php_oci_connection *connection TSRMLS_DC)
22692271
*/
22702272
int php_oci_connection_rollback(php_oci_connection *connection TSRMLS_DC)
22712273
{
2272-
PHP_OCI_CALL_RETURN(connection->errcode, OCITransRollback, (connection->svc, connection->err, (ub4) 0));
2274+
sword errstatus;
2275+
2276+
PHP_OCI_CALL_RETURN(errstatus, OCITransRollback, (connection->svc, connection->err, (ub4) 0));
22732277
connection->rb_on_disconnect = 0;
22742278

2275-
if (connection->errcode != OCI_SUCCESS) {
2276-
connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
2279+
if (errstatus != OCI_SUCCESS) {
2280+
connection->errcode = php_oci_error(connection->err, errstatus TSRMLS_CC);
22772281
PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
22782282
return 1;
22792283
}
2284+
connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
22802285
return 0;
22812286
}
22822287
/* }}} */
@@ -2287,14 +2292,17 @@ int php_oci_connection_rollback(php_oci_connection *connection TSRMLS_DC)
22872292
*/
22882293
int php_oci_connection_commit(php_oci_connection *connection TSRMLS_DC)
22892294
{
2290-
PHP_OCI_CALL_RETURN(connection->errcode, OCITransCommit, (connection->svc, connection->err, (ub4) 0));
2295+
sword errstatus;
2296+
2297+
PHP_OCI_CALL_RETURN(errstatus, OCITransCommit, (connection->svc, connection->err, (ub4) 0));
22912298
connection->rb_on_disconnect = 0;
22922299

2293-
if (connection->errcode != OCI_SUCCESS) {
2294-
connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
2300+
if (errstatus != OCI_SUCCESS) {
2301+
connection->errcode = php_oci_error(connection->err, errstatus TSRMLS_CC);
22952302
PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
22962303
return 1;
22972304
}
2305+
connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
22982306
return 0;
22992307
}
23002308
/* }}} */
@@ -2308,6 +2316,12 @@ static int php_oci_connection_close(php_oci_connection *connection TSRMLS_DC)
23082316
int result = 0;
23092317
zend_bool in_call_save = OCI_G(in_call);
23102318

2319+
#ifdef HAVE_OCI8_DTRACE
2320+
if (DTRACE_OCI8_CONNECTION_CLOSE_ENABLED()) {
2321+
DTRACE_OCI8_CONNECTION_CLOSE(connection);
2322+
}
2323+
#endif /* HAVE_OCI8_DTRACE */
2324+
23112325
if (!connection->is_stub) {
23122326
/* Release resources associated with connection */
23132327
php_oci_connection_release(connection TSRMLS_CC);
@@ -2462,13 +2476,16 @@ int php_oci_connection_release(php_oci_connection *connection TSRMLS_DC)
24622476
*/
24632477
int php_oci_password_change(php_oci_connection *connection, char *user, int user_len, char *pass_old, int pass_old_len, char *pass_new, int pass_new_len TSRMLS_DC)
24642478
{
2465-
PHP_OCI_CALL_RETURN(connection->errcode, OCIPasswordChange, (connection->svc, connection->err, (text *)user, user_len, (text *)pass_old, pass_old_len, (text *)pass_new, pass_new_len, OCI_DEFAULT));
2479+
sword errstatus;
24662480

2467-
if (connection->errcode != OCI_SUCCESS) {
2468-
connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
2481+
PHP_OCI_CALL_RETURN(errstatus, OCIPasswordChange, (connection->svc, connection->err, (text *)user, user_len, (text *)pass_old, pass_old_len, (text *)pass_new, pass_new_len, OCI_DEFAULT));
2482+
2483+
if (errstatus != OCI_SUCCESS) {
2484+
connection->errcode = php_oci_error(connection->err, errstatus TSRMLS_CC);
24692485
PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
24702486
return 1;
24712487
}
2488+
connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
24722489
connection->passwd_changed = 1;
24732490
return 0;
24742491
}
@@ -2503,12 +2520,13 @@ void php_oci_client_get_version(char **version TSRMLS_DC)
25032520
*/
25042521
int php_oci_server_get_version(php_oci_connection *connection, char **version TSRMLS_DC)
25052522
{
2523+
sword errstatus;
25062524
char version_buff[256];
25072525

2508-
PHP_OCI_CALL_RETURN(connection->errcode, OCIServerVersion, (connection->svc, connection->err, (text *)version_buff, sizeof(version_buff), OCI_HTYPE_SVCCTX));
2526+
PHP_OCI_CALL_RETURN(errstatus, OCIServerVersion, (connection->svc, connection->err, (text *)version_buff, sizeof(version_buff), OCI_HTYPE_SVCCTX));
25092527

2510-
if (connection->errcode != OCI_SUCCESS) {
2511-
connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
2528+
if (errstatus != OCI_SUCCESS) {
2529+
connection->errcode = php_oci_error(connection->err, errstatus TSRMLS_CC);
25122530
PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
25132531
return 1;
25142532
}
@@ -2806,6 +2824,7 @@ static php_oci_spool *php_oci_create_spool(char *username, int username_len, cha
28062824
zend_bool iserror = 0;
28072825
ub4 poolmode = OCI_DEFAULT; /* Mode to be passed to OCISessionPoolCreate */
28082826
OCIAuthInfo *spoolAuth = NULL;
2827+
sword errstatus;
28092828

28102829
/* Allocate sessionpool out of persistent memory */
28112830
session_pool = (php_oci_spool *) calloc(1, sizeof(php_oci_spool));
@@ -2830,10 +2849,10 @@ static php_oci_spool *php_oci_create_spool(char *username, int username_len, cha
28302849
}
28312850

28322851
/* Allocate the pool handle */
2833-
PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIHandleAlloc, (session_pool->env, (dvoid **) &session_pool->poolh, OCI_HTYPE_SPOOL, (size_t) 0, (dvoid **) 0));
2852+
PHP_OCI_CALL_RETURN(errstatus, OCIHandleAlloc, (session_pool->env, (dvoid **) &session_pool->poolh, OCI_HTYPE_SPOOL, (size_t) 0, (dvoid **) 0));
28342853

2835-
if (OCI_G(errcode) != OCI_SUCCESS) {
2836-
php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
2854+
if (errstatus != OCI_SUCCESS) {
2855+
OCI_G(errcode) = php_oci_error(OCI_G(err), errstatus TSRMLS_CC);
28372856
iserror = 1;
28382857
goto exit_create_spool;
28392858
}
@@ -2842,10 +2861,10 @@ static php_oci_spool *php_oci_create_spool(char *username, int username_len, cha
28422861
* generic bug which can free up the OCI_G(err) variable before destroying connections. We
28432862
* cannot use this for other roundtrip calls as there is no way the user can access this error
28442863
*/
2845-
PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIHandleAlloc, ((dvoid *) session_pool->env, (dvoid **)&(session_pool->err), (ub4) OCI_HTYPE_ERROR,(size_t) 0, (dvoid **) 0));
2864+
PHP_OCI_CALL_RETURN(errstatus, OCIHandleAlloc, ((dvoid *) session_pool->env, (dvoid **)&(session_pool->err), (ub4) OCI_HTYPE_ERROR,(size_t) 0, (dvoid **) 0));
28462865

2847-
if (OCI_G(errcode) != OCI_SUCCESS) {
2848-
php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
2866+
if (errstatus != OCI_SUCCESS) {
2867+
OCI_G(errcode) = php_oci_error(OCI_G(err), errstatus TSRMLS_CC);
28492868
iserror = 1;
28502869
goto exit_create_spool;
28512870
}
@@ -2859,42 +2878,42 @@ static php_oci_spool *php_oci_create_spool(char *username, int username_len, cha
28592878

28602879
#if ((OCI_MAJOR_VERSION > 11) || ((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION >= 2)))
28612880
/* {{{ Allocate auth handle for session pool */
2862-
PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIHandleAlloc, (session_pool->env, (dvoid **)&(spoolAuth), OCI_HTYPE_AUTHINFO, 0, NULL));
2881+
PHP_OCI_CALL_RETURN(errstatus, OCIHandleAlloc, (session_pool->env, (dvoid **)&(spoolAuth), OCI_HTYPE_AUTHINFO, 0, NULL));
28632882

2864-
if (OCI_G(errcode) != OCI_SUCCESS) {
2865-
php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
2883+
if (errstatus != OCI_SUCCESS) {
2884+
OCI_G(errcode) = php_oci_error(OCI_G(err), errstatus TSRMLS_CC);
28662885
iserror = 1;
28672886
goto exit_create_spool;
28682887
}
28692888
/* }}} */
28702889

28712890
/* {{{ Set the edition attribute on the auth handle */
28722891
if (OCI_G(edition)) {
2873-
PHP_OCI_CALL_RETURN(OCI_G(errcode),OCIAttrSet, ((dvoid *) spoolAuth, (ub4) OCI_HTYPE_AUTHINFO, (dvoid *) OCI_G(edition), (ub4)(strlen(OCI_G(edition))), (ub4)OCI_ATTR_EDITION, OCI_G(err)));
2892+
PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, ((dvoid *) spoolAuth, (ub4) OCI_HTYPE_AUTHINFO, (dvoid *) OCI_G(edition), (ub4)(strlen(OCI_G(edition))), (ub4)OCI_ATTR_EDITION, OCI_G(err)));
28742893

2875-
if (OCI_G(errcode) != OCI_SUCCESS) {
2876-
php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
2894+
if (errstatus != OCI_SUCCESS) {
2895+
OCI_G(errcode) = php_oci_error(OCI_G(err), errstatus TSRMLS_CC);
28772896
iserror = 1;
28782897
goto exit_create_spool;
28792898
}
28802899
}
28812900
/* }}} */
28822901

28832902
/* {{{ Set the driver name attribute on the auth handle */
2884-
PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) spoolAuth, (ub4) OCI_HTYPE_AUTHINFO, (dvoid *) PHP_OCI8_DRIVER_NAME, (ub4) sizeof(PHP_OCI8_DRIVER_NAME)-1, (ub4) OCI_ATTR_DRIVER_NAME, OCI_G(err)));
2903+
PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, ((dvoid *) spoolAuth, (ub4) OCI_HTYPE_AUTHINFO, (dvoid *) PHP_OCI8_DRIVER_NAME, (ub4) sizeof(PHP_OCI8_DRIVER_NAME)-1, (ub4) OCI_ATTR_DRIVER_NAME, OCI_G(err)));
28852904

2886-
if (OCI_G(errcode) != OCI_SUCCESS) {
2887-
php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
2905+
if (errstatus != OCI_SUCCESS) {
2906+
OCI_G(errcode) = php_oci_error(OCI_G(err), errstatus TSRMLS_CC);
28882907
iserror = 1;
28892908
goto exit_create_spool;
28902909
}
28912910
/* }}} */
28922911

28932912
/* {{{ Set the auth handle on the session pool */
2894-
PHP_OCI_CALL_RETURN(OCI_G(errcode),OCIAttrSet, ((dvoid *) (session_pool->poolh),(ub4) OCI_HTYPE_SPOOL, (dvoid *) spoolAuth, (ub4)0, (ub4)OCI_ATTR_SPOOL_AUTH, OCI_G(err)));
2913+
PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, ((dvoid *) (session_pool->poolh),(ub4) OCI_HTYPE_SPOOL, (dvoid *) spoolAuth, (ub4)0, (ub4)OCI_ATTR_SPOOL_AUTH, OCI_G(err)));
28952914

2896-
if (OCI_G(errcode) != OCI_SUCCESS) {
2897-
php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
2915+
if (errstatus != OCI_SUCCESS) {
2916+
OCI_G(errcode) = php_oci_error(OCI_G(err), errstatus TSRMLS_CC);
28982917
iserror = 1;
28992918
goto exit_create_spool;
29002919
}
@@ -2904,10 +2923,10 @@ static php_oci_spool *php_oci_create_spool(char *username, int username_len, cha
29042923
/* Create the homogeneous session pool - We have different session pools for every different
29052924
* username, password, charset and dbname.
29062925
*/
2907-
PHP_OCI_CALL_RETURN(OCI_G(errcode), OCISessionPoolCreate,(session_pool->env, OCI_G(err), session_pool->poolh, (OraText **)&session_pool->poolname, &session_pool->poolname_len, (OraText *)dbname, (ub4)dbname_len, 0, UB4MAXVAL, 1,(OraText *)username, (ub4)username_len, (OraText *)password,(ub4)password_len, poolmode));
2926+
PHP_OCI_CALL_RETURN(errstatus, OCISessionPoolCreate,(session_pool->env, OCI_G(err), session_pool->poolh, (OraText **)&session_pool->poolname, &session_pool->poolname_len, (OraText *)dbname, (ub4)dbname_len, 0, UB4MAXVAL, 1,(OraText *)username, (ub4)username_len, (OraText *)password,(ub4)password_len, poolmode));
29082927

2909-
if (OCI_G(errcode) != OCI_SUCCESS) {
2910-
php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
2928+
if (errstatus != OCI_SUCCESS) {
2929+
OCI_G(errcode) = php_oci_error(OCI_G(err), errstatus TSRMLS_CC);
29112930
iserror = 1;
29122931
}
29132932

@@ -3477,11 +3496,11 @@ static sword php_oci_ping_init(php_oci_connection *connection, OCIError *errh TS
34773496
*
34783497
* DTrace output for connections that may have become invalid and marked for reopening
34793498
*/
3480-
void php_oci_dtrace_check_connection(php_oci_connection *connection, sword errcode, ub4 serverStatus)
3499+
void php_oci_dtrace_check_connection(php_oci_connection *connection, sb4 errcode, ub4 serverStatus)
34813500
{
34823501
#ifdef HAVE_OCI8_DTRACE
34833502
if (DTRACE_OCI8_CHECK_CONNECTION_ENABLED()) {
3484-
DTRACE_OCI8_CHECK_CONNECTION(connection, connection && connection->is_open ? 1 : 0, (int)errcode, (unsigned long)serverStatus);
3503+
DTRACE_OCI8_CHECK_CONNECTION(connection, connection && connection->is_open ? 1 : 0, (long)errcode, (unsigned long)serverStatus);
34853504
}
34863505
#endif /* HAVE_OCI8_DTRACE */
34873506
}

0 commit comments

Comments
 (0)