CVS update: php3/functions

From: Date: Wed, 12 May 1999 11:16:47 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-5551@lists.php.net to get a copy of this message
Date: Wednesday May 12, 1999 @ 7:16 Author: thies Update of /repository/php3/functions In directory php:/tmp/cvs-serv4865/functions Modified Files: oci8.c php3_oci8.h Log Message: much imporverd error-code handling Index: php3/functions/oci8.c diff -u php3/functions/oci8.c:1.93 php3/functions/oci8.c:1.94 --- php3/functions/oci8.c:1.93 Thu May 6 11:26:17 1999 +++ php3/functions/oci8.c Wed May 12 07:16:47 1999 @@ -33,7 +33,7 @@ #define OCI8_USE_EMALLOC 0 /* set this to 1 if you want to use the php memory manager! */ -/* $Id: oci8.c,v 1.93 1999/05/06 15:26:17 thies Exp $ */ +/* $Id: oci8.c,v 1.94 1999/05/12 11:16:47 thies Exp $ */ /* TODO list: * @@ -200,8 +200,10 @@ /* define callback function */ static sb4 oci8_define_callback(dvoid *, OCIDefine *, ub4, dvoid **, ub4 **, ub1 *, dvoid **, ub2 **); +#if 0 /* failover callback function */ static sb4 oci8_failover_callback(dvoid *svchp,dvoid* envhp,dvoid *fo_ctx,ub4 fo_type, ub4 fo_event); +#endif /* }}} */ /* {{{ extension function prototypes */ @@ -431,7 +433,12 @@ #endif OCIEnvInit(&OCI8_GLOBAL(php3_oci8_module).pEnv, OCI_DEFAULT, 0, NULL); - + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&OCI8_GLOBAL(php3_oci8_module).pError, + OCI_HTYPE_ERROR, + 0, + NULL); + return SUCCESS; } @@ -966,7 +973,6 @@ oci8_parse(oci8_connection *connection, char *query, int len, HashTable *list) { oci8_statement *statement; - sword error = 0; OCI8_TLS_VARS; statement = ecalloc(1,sizeof(oci8_statement)); @@ -982,11 +988,17 @@ NULL); if (len > 0) { - error = oci8_error(statement->pError, "OCIParse", - OCIStmtPrepare(statement->pStmt, connection->pError, - query, len, - OCI_NTV_SYNTAX, OCI_DEFAULT)); - if (error) { + connection->error = + oci8_error(connection->pError, + "OCIParse", + OCIStmtPrepare(statement->pStmt, + connection->pError, + query, + len, + OCI_NTV_SYNTAX, + OCI_DEFAULT)); + if (connection->error) { + /* XXX loose memory */ return 0; } } @@ -995,14 +1007,15 @@ { ub4 prefetch = 5*1024; - error = oci8_error(statement->pError, - "OCIAttrSet OCI_ATTR_PREFETCH_ROWS", - OCIAttrSet(statement->pStmt, - OCI_HTYPE_STMT, - &prefetch, - 0, - OCI_ATTR_PREFETCH_MEMORY, - &statement->pError)); + statement->error = + oci8_error(statement->pError, + "OCIAttrSet OCI_ATTR_PREFETCH_ROWS", + OCIAttrSet(statement->pStmt, + OCI_HTYPE_STMT, + &prefetch, + 0, + OCI_ATTR_PREFETCH_MEMORY, + &statement->pError)); } #endif @@ -1031,7 +1044,6 @@ OCIParam *param = 0; text *colname; ub4 counter; - sword error; ub2 define_type; ub2 stmttype; ub4 iters; @@ -1039,18 +1051,17 @@ ub2 storage_size2; OCI8_TLS_VARS; - error = oci8_error( - statement->pError, - "OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_STMT_TYPE", - OCIAttrGet( - (dvoid *)statement->pStmt, - OCI_HTYPE_STMT, - (ub2 *)&stmttype, - (ub4 *)0, - OCI_ATTR_STMT_TYPE, - statement->pError)); + statement->error = + oci8_error(statement->pError, + "OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_STMT_TYPE", + OCIAttrGet((dvoid *)statement->pStmt, + OCI_HTYPE_STMT, + (ub2 *)&stmttype, + (ub4 *)0, + OCI_ATTR_STMT_TYPE, + statement->pError)); - if (error) { + if (statement->error) { return 0; } @@ -1061,20 +1072,19 @@ } if (statement->last_query) { /* if we execute refcursors we don't have a query and we don't want to execute!!! */ - error = oci8_error( - statement->pError, - "OCIStmtExecute", - OCIStmtExecute( - statement->conn->pServiceContext, - statement->pStmt, - statement->pError, - iters, - 0, - NULL, - NULL, - mode)); + statement->error = + oci8_error(statement->pError, + "OCIStmtExecute", + OCIStmtExecute(statement->conn->pServiceContext, + statement->pStmt, + statement->pError, + iters, + 0, + NULL, + NULL, + mode)); - switch (error) { + switch (statement->error) { case 0: break; @@ -1108,17 +1118,16 @@ counter = 1; - error = oci8_error( - statement->pError, - "OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_PARAM_COUNT", - OCIAttrGet( - (dvoid *)statement->pStmt, - OCI_HTYPE_STMT, - (dvoid *)&colcount, - (ub4 *)0, - OCI_ATTR_PARAM_COUNT, - statement->pError)); - if (error) { + statement->error = + oci8_error(statement->pError, + "OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_PARAM_COUNT", + OCIAttrGet((dvoid *)statement->pStmt, + OCI_HTYPE_STMT, + (dvoid *)&colcount, + (ub4 *)0, + OCI_ATTR_PARAM_COUNT, + statement->pError)); + if (statement->error) { return 0; /* XXX we loose memory!!! */ } @@ -1136,60 +1145,57 @@ outcol->statement = statement; - error = oci8_error( - statement->pError, - "OCIParamGet OCI_HTYPE_STMT", - OCIParamGet( - (dvoid *)statement->pStmt, - OCI_HTYPE_STMT, - statement->pError, - (dvoid*)&param, - counter)); - if (error) { + statement->error = + oci8_error(statement->pError, + "OCIParamGet OCI_HTYPE_STMT", + OCIParamGet( + (dvoid *)statement->pStmt, + OCI_HTYPE_STMT, + statement->pError, + (dvoid*)&param, + counter)); + if (statement->error) { return 0; /* XXX we loose memory!!! */ } - error = oci8_error( - statement->pError, - "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_TYPE", - OCIAttrGet( - (dvoid *)param, - OCI_DTYPE_PARAM, - (dvoid *)&outcol->type, - (ub4 *)0, - OCI_ATTR_DATA_TYPE, - statement->pError)); - if (error) { + statement->error = + oci8_error(statement->pError, + "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_TYPE", + OCIAttrGet((dvoid *)param, + OCI_DTYPE_PARAM, + (dvoid *)&outcol->type, + (ub4 *)0, + OCI_ATTR_DATA_TYPE, + statement->pError)); + if (statement->error) { return 0; /* XXX we loose memory!!! */ } - error = oci8_error( - statement->pError, - "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_SIZE", - OCIAttrGet( - (dvoid *)param, - OCI_DTYPE_PARAM, - (dvoid *)&storage_size2, - (dvoid *)0, - OCI_ATTR_DATA_SIZE, - statement->pError)); - if (error) { + statement->error = + oci8_error(statement->pError, + "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_SIZE", + OCIAttrGet((dvoid *)param, + OCI_DTYPE_PARAM, + (dvoid *)&storage_size2, + (dvoid *)0, + OCI_ATTR_DATA_SIZE, + statement->pError)); + if (statement->error) { return 0; /* XXX we loose memory!!! */ } outcol->storage_size4 = storage_size2; - error = oci8_error( - statement->pError, - "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_NAME", - OCIAttrGet( - (dvoid *)param, - OCI_DTYPE_PARAM, - (dvoid **)&colname, /* XXX this string is NOT zero terminated!!!! */ - (ub4 *)&outcol->name_len, - (ub4)OCI_ATTR_NAME, - statement->pError)); - if (error) { + statement->error = + oci8_error(statement->pError, + "OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_NAME", + OCIAttrGet((dvoid *)param, + OCI_DTYPE_PARAM, + (dvoid **)&colname, /* XXX this string is NOT zero terminated!!!! */ + (ub4 *)&outcol->name_len, + (ub4)OCI_ATTR_NAME, + statement->pError)); + if (statement->error) { return 0; /* XXX we loose memory!!! */ } @@ -1244,34 +1250,32 @@ } - error = oci8_error( - statement->pError, - "OCIDefineByPos", - OCIDefineByPos( - statement->pStmt, /* IN/OUT handle to the requested SQL query */ - (OCIDefine **)&outcol->pDefine, /* IN/OUT pointer to a pointer to a define handle */ - statement->pError, /* IN/OUT An error handle */ - counter, /* IN position in the select list */ - (dvoid *)0, /* IN/OUT pointer to a buffer */ - outcol->storage_size4, /* IN The size of each valuep buffer in bytes */ - define_type, /* IN The data type */ - (dvoid *)&outcol->indicator, /* IN pointer to an indicator variable or arr */ - (ub2 *)&outcol->size2, /* IN/OUT Pointer to array of length of data fetched */ - (ub2 *)&outcol->retcode, /* OUT Pointer to array of column-level return codes */ - OCI_DYNAMIC_FETCH)); /* IN mode (OCI_DEFAULT, OCI_DYNAMIC_FETCH) */ - if (error) { + statement->error = + oci8_error(statement->pError, + "OCIDefineByPos", + OCIDefineByPos(statement->pStmt, /* IN/OUT handle to the requested SQL query */ + (OCIDefine **)&outcol->pDefine, /* IN/OUT pointer to a pointer to a define handle */ + statement->pError, /* IN/OUT An error handle */ + counter, /* IN position in the select list */ + (dvoid *)0, /* IN/OUT pointer to a buffer */ + outcol->storage_size4, /* IN The size of each valuep buffer in bytes */ + define_type, /* IN The data type */ + (dvoid *)&outcol->indicator, /* IN pointer to an indicator variable or arr */ + (ub2 *)&outcol->size2, /* IN/OUT Pointer to array of length of data fetched */ + (ub2 *)&outcol->retcode, /* OUT Pointer to array of column-level return codes */ + OCI_DYNAMIC_FETCH)); /* IN mode (OCI_DEFAULT, OCI_DYNAMIC_FETCH) */ + if (statement->error) { return 0; /* XXX we loose memory!!! */ } - error = oci8_error( - statement->pError, - "OCIDefineDynamic", - OCIDefineDynamic( - outcol->pDefine, - statement->pError, - outcol, - oci8_define_callback)); - if (error) { + statement->error = + oci8_error(statement->pError, + "OCIDefineDynamic", + OCIDefineDynamic(outcol->pDefine, + statement->pError, + outcol, + oci8_define_callback)); + if (statement->error) { return 0; /* XXX we loose memory!!! */ } } @@ -1285,16 +1289,18 @@ static int oci8_fetch(oci8_statement *statement, ub4 nrows, char *func) { - sword error; int i; oci8_out_column *column; pval *pval; OCI8_TLS_VARS; - error = OCIStmtFetch(statement->pStmt, statement->pError, nrows, - OCI_FETCH_NEXT, OCI_DEFAULT); + statement->error = + OCIStmtFetch(statement->pStmt, + statement->pError, nrows, + OCI_FETCH_NEXT, + OCI_DEFAULT); - if (error == OCI_NO_DATA) { + if (statement->error == OCI_NO_DATA) { /* XXX this is needed for REFCURSORS! */ if (statement->columns) { @@ -1304,10 +1310,12 @@ } statement->executed = 0; + statement->error = 0; /* OCI_NO_DATA is NO error for us!!! */ + return 0; } - if (error == OCI_SUCCESS_WITH_INFO || error == OCI_SUCCESS) { + if (statement->error == OCI_SUCCESS_WITH_INFO || statement->error == OCI_SUCCESS) { /* do the stuff needed for OCIDefineByName */ for (i = 0; i < statement->ncolumns; i++) { column = oci8_get_col(statement, i + 1, 0, "OCIFetch"); @@ -1344,7 +1352,7 @@ return 1; } - oci8_error(statement->pError, func, error); + oci8_error(statement->pError, func, statement->error); return 0; } @@ -1354,15 +1362,18 @@ static ub4 oci8_loaddesc(oci8_connection *connection, oci8_descriptor *mydescr, char **buffer) { - sword ociresult; ub4 loblen; OCI8_TLS_VARS; - ociresult = OCILobGetLength(connection->pServiceContext, connection->pError, mydescr->ocidescr, &loblen); + connection->error = + OCILobGetLength(connection->pServiceContext, + connection->pError, + mydescr->ocidescr, + &loblen); - if (ociresult) { - oci8_error(connection->pError, "OCILobGetLength", ociresult); + if (connection->error) { + oci8_error(connection->pError, "OCILobGetLength", connection->error); return 0; } @@ -1373,41 +1384,44 @@ } if (mydescr->type == OCI_DTYPE_FILE) { - ociresult = OCILobFileOpen(connection->pServiceContext, - connection->pError, - mydescr->ocidescr, - OCI_FILE_READONLY); - if (ociresult) { - oci8_error(connection->pError, "OCILobFileOpen", ociresult); + connection->error = + OCILobFileOpen(connection->pServiceContext, + connection->pError, + mydescr->ocidescr, + OCI_FILE_READONLY); + if (connection->error) { + oci8_error(connection->pError, "OCILobFileOpen",connection->error); efree(buffer); return 0; } } - ociresult = OCILobRead(connection->pServiceContext, - connection->pError, - mydescr->ocidescr, - &loblen, /* IN/OUT bytes toread/read */ - 1, /* offset (starts with 1) */ - (dvoid *) *buffer, - loblen, /* size of buffer */ - (dvoid *)0, - (OCICallbackLobRead) 0, /* callback... */ - (ub2) 0, /* The character set ID of the buffer data. */ - (ub1) SQLCS_IMPLICIT); /* The character set form of the buffer data. */ - - if (ociresult) { - oci8_error(connection->pError, "OCILobRead", ociresult); + connection->error = + OCILobRead(connection->pServiceContext, + connection->pError, + mydescr->ocidescr, + &loblen, /* IN/OUT bytes toread/read */ + 1, /* offset (starts with 1) */ + (dvoid *) *buffer, + loblen, /* size of buffer */ + (dvoid *)0, + (OCICallbackLobRead) 0, /* callback... */ + (ub2) 0, /* The character set ID of the buffer data. */ + (ub1) SQLCS_IMPLICIT); /* The character set form of the buffer data. */ + + if (connection->error) { + oci8_error(connection->pError, "OCILobRead", connection->error); efree(buffer); return 0; } if (mydescr->type == OCI_DTYPE_FILE) { - ociresult = OCILobFileClose(connection->pServiceContext, - connection->pError, - mydescr->ocidescr); - if (ociresult) { - oci8_error(connection->pError, "OCILobFileClose", ociresult); + connection->error = + OCILobFileClose(connection->pServiceContext, + connection->pError, + mydescr->ocidescr); + if (connection->error) { + oci8_error(connection->pError, "OCILobFileClose", connection->error); efree(buffer); return 0; } @@ -1422,7 +1436,7 @@ /* }}} */ /* {{{ oci8_failover_callback() */ - +#if 0 /* not needed yet ! */ static sb4 oci8_failover_callback(dvoid *svchp, dvoid* envhp, @@ -1495,7 +1509,7 @@ return 0; } - +#endif /* }}} */ /* {{{ oci8_define_callback() */ @@ -1718,7 +1732,6 @@ static oci8_session *oci8_open_user(oci8_server* server,char *username,char *password,int persistent,int exclusive) { - sword error; oci8_session *session = 0; OCISvcCtx *svchp = 0; char *hashed_details; @@ -1772,81 +1785,76 @@ session->server = server; /* allocate temporary Service Context */ - error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, - (dvoid **)&svchp, - OCI_HTYPE_SVCCTX, - 0, - NULL); - if (error != OCI_SUCCESS) { - oci8_error(server->pError, "oci8_open_user: OCIHandleAlloc OCI_HTYPE_SVCCTX", error); - goto CLEANUP; - } - - /* allocate private error-handle */ - error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, - (dvoid **)&session->pError, - OCI_HTYPE_ERROR, - 0, - NULL); - if (error != OCI_SUCCESS) { - oci8_error(server->pError, "oci8_open_user: OCIHandleAlloc OCI_HTYPE_ERROR", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&svchp, + OCI_HTYPE_SVCCTX, + 0, + NULL); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "oci8_open_user: OCIHandleAlloc OCI_HTYPE_SVCCTX", OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } /* allocate private session-handle */ - error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, - (dvoid **)&session->pSession, - OCI_HTYPE_SESSION, - 0, - NULL); - if (error != OCI_SUCCESS) { - oci8_error(server->pError, "oci8_open_user: OCIHandleAlloc OCI_HTYPE_SESSION", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&session->pSession, + OCI_HTYPE_SESSION, + 0, + NULL); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "oci8_open_user: OCIHandleAlloc OCI_HTYPE_SESSION", OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } /* Set the server handle in service handle */ - error = OCIAttrSet(svchp, - OCI_HTYPE_SVCCTX, - server->pServer, - 0, - OCI_ATTR_SERVER, - session->pError); - if (error != OCI_SUCCESS) { - oci8_error(session->pError, "oci8_open_user: OCIAttrSet OCI_ATTR_SERVER", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIAttrSet(svchp, + OCI_HTYPE_SVCCTX, + server->pServer, + 0, + OCI_ATTR_SERVER, + OCI8_GLOBAL(php3_oci8_module).pError); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "oci8_open_user: OCIAttrSet OCI_ATTR_SERVER", OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } /* set the username in user handle */ - error = OCIAttrSet((dvoid *) session->pSession, - (ub4) OCI_HTYPE_SESSION, - (dvoid *) username, - (ub4) strlen(username), - (ub4) OCI_ATTR_USERNAME, - session->pError); - if (error != OCI_SUCCESS) { - oci8_error(session->pError, "OCIAttrSet OCI_ATTR_USERNAME", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIAttrSet((dvoid *) session->pSession, + (ub4) OCI_HTYPE_SESSION, + (dvoid *) username, + (ub4) strlen(username), + (ub4) OCI_ATTR_USERNAME, + OCI8_GLOBAL(php3_oci8_module).pError); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "OCIAttrSet OCI_ATTR_USERNAME", OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } /* set the password in user handle */ - error = OCIAttrSet((dvoid *) session->pSession, - (ub4) OCI_HTYPE_SESSION, - (dvoid *) password, - (ub4) strlen(password), - (ub4) OCI_ATTR_PASSWORD, - session->pError); - if (error != OCI_SUCCESS) { - oci8_error(session->pError, "OCIAttrSet OCI_ATTR_PASSWORD", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIAttrSet((dvoid *) session->pSession, + (ub4) OCI_HTYPE_SESSION, + (dvoid *) password, + (ub4) strlen(password), + (ub4) OCI_ATTR_PASSWORD, + OCI8_GLOBAL(php3_oci8_module).pError); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "OCIAttrSet OCI_ATTR_PASSWORD", OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } - error = OCISessionBegin(svchp, - session->pError, - session->pSession, - (ub4) OCI_CRED_RDBMS, - (ub4) OCI_DEFAULT); - if (error != OCI_SUCCESS) { - oci8_error(session->pError, "OCISessionBegin", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCISessionBegin(svchp, + OCI8_GLOBAL(php3_oci8_module).pError, + session->pSession, + (ub4) OCI_CRED_RDBMS, + (ub4) OCI_DEFAULT); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "OCISessionBegin", OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } @@ -1893,7 +1901,6 @@ _oci8_close_user(oci8_session *session) { OCISvcCtx *svchp; - sword error; if (! session) { return; @@ -1903,44 +1910,48 @@ if (session->open) { /* Temporary Service Context */ - error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, - (dvoid **) &svchp, - (ub4) OCI_HTYPE_SVCCTX, - (size_t) 0, - (dvoid **) 0); + OCI8_GLOBAL(php3_oci8_module).error = + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **) &svchp, + (ub4) OCI_HTYPE_SVCCTX, + (size_t) 0, + (dvoid **) 0); - if (error != OCI_SUCCESS) { - oci8_error(session->pError, "_oci8_close_user OCIHandleAlloc OCI_HTYPE_SVCCTX", error); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "_oci8_close_user OCIHandleAlloc OCI_HTYPE_SVCCTX", OCI8_GLOBAL(php3_oci8_module).error); } /* Set the server handle in service handle */ - error = OCIAttrSet(svchp, - OCI_HTYPE_SVCCTX, - session->server->pServer, - 0, - OCI_ATTR_SERVER, - session->pError); - if (error != OCI_SUCCESS) { - oci8_error(session->pError, "_oci8_close_user: OCIAttrSet OCI_ATTR_SERVER", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIAttrSet(svchp, + OCI_HTYPE_SVCCTX, + session->server->pServer, + 0, + OCI_ATTR_SERVER, + OCI8_GLOBAL(php3_oci8_module).pError); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "_oci8_close_user: OCIAttrSet OCI_ATTR_SERVER", OCI8_GLOBAL(php3_oci8_module).error); } /* Set the Authentication handle in the service handle */ - error = OCIAttrSet(svchp, - OCI_HTYPE_SVCCTX, - session->pSession, - 0, - OCI_ATTR_SESSION, - session->pError); - if (error != OCI_SUCCESS) { - oci8_error(session->pError, "_oci8_close_user: OCIAttrSet OCI_ATTR_SESSION", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIAttrSet(svchp, + OCI_HTYPE_SVCCTX, + session->pSession, + 0, + OCI_ATTR_SESSION, + OCI8_GLOBAL(php3_oci8_module).pError); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "_oci8_close_user: OCIAttrSet OCI_ATTR_SESSION", OCI8_GLOBAL(php3_oci8_module).error); } - error = OCISessionEnd(svchp, - session->pError, - session->pSession, - (ub4) 0); - if (error != OCI_SUCCESS) { - oci8_error(session->pError, "_oci8_close_user: OCISessionEnd", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCISessionEnd(svchp, + OCI8_GLOBAL(php3_oci8_module).pError, + session->pSession, + (ub4) 0); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "_oci8_close_user: OCISessionEnd", OCI8_GLOBAL(php3_oci8_module).error); } } else { oci8_debug("_oci8_close_user: logging-off DEAD session"); @@ -1952,10 +1963,6 @@ OCIHandleFree((dvoid *) session->pSession, (ub4) OCI_HTYPE_SESSION); } - if (session->pError) { - OCIHandleFree((dvoid *) session->pError, (ub4) OCI_HTYPE_ERROR); - } - free(session); } @@ -1978,7 +1985,6 @@ static oci8_server *oci8_open_server(char *dbname,int persistent) { oci8_server *server = 0; - sword error; char *hashed_details; int hashed_details_length; OCI8_TLS_VARS; @@ -2024,25 +2030,20 @@ server->dbname = strdup(SAFE_STRING(dbname)); OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, - (dvoid **)&server->pError, - OCI_HTYPE_ERROR, - 0, - NULL); - - OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, (dvoid **)&server->pServer, OCI_HTYPE_SERVER, 0, NULL); - error = OCIServerAttach(server->pServer, - server->pError, - dbname, - strlen(dbname), - (ub4) OCI_DEFAULT); + OCI8_GLOBAL(php3_oci8_module).error = + OCIServerAttach(server->pServer, + OCI8_GLOBAL(php3_oci8_module).pError, + dbname, + strlen(dbname), + (ub4) OCI_DEFAULT); - if (error) { - oci8_error(server->pError, "oci8_open_server", error); + if (OCI8_GLOBAL(php3_oci8_module).error) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "oci8_open_server", OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } @@ -2051,6 +2052,7 @@ server->open = 1; +#if 0 server->failover.fo_ctx = (dvoid *) server; server->failover.callback_function = oci8_failover_callback; @@ -2059,12 +2061,13 @@ (dvoid *) &server->failover, (ub4) 0, (ub4) OCI_ATTR_FOCBK, - server->pError); + OCI8_GLOBAL(php3_oci8_module).pError); if (error) { - oci8_error(server->pError, "oci8_open_server OCIAttrSet OCI_ATTR_FOCBK", error); + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "oci8_open_server OCIAttrSet OCI_ATTR_FOCBK", error); goto CLEANUP; } +#endif oci8_debug("oci8_open_server new conn=%d dname=%s",server->num,server->dbname); @@ -2096,7 +2099,6 @@ static void _oci8_close_server(oci8_server *server) { - sword error; OCI8_TLS_VARS; if (! server) { @@ -2108,13 +2110,14 @@ /* XXX close server here */ if (server->open) { - if (server->pServer && server->pError) { - error = OCIServerDetach(server->pServer, - server->pError, - OCI_DEFAULT); + if (server->pServer && OCI8_GLOBAL(php3_oci8_module).pError) { + OCI8_GLOBAL(php3_oci8_module).error = + OCIServerDetach(server->pServer, + OCI8_GLOBAL(php3_oci8_module).pError, + OCI_DEFAULT); - if (error) { - oci8_error(server->pError, "oci8_close_server OCIServerDetach", error); + if (OCI8_GLOBAL(php3_oci8_module).error) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "oci8_close_server OCIServerDetach", OCI8_GLOBAL(php3_oci8_module).error); } } } else { @@ -2125,10 +2128,6 @@ OCIHandleFree((dvoid *) server->pServer, (ub4) OCI_HTYPE_SERVER); } - if (server->pError) { - OCIHandleFree((dvoid *) server->pError, (ub4) OCI_HTYPE_ERROR); - } - if (server->dbname) { free(server->dbname); } @@ -2147,7 +2146,6 @@ oci8_server *server = 0; oci8_session *session = 0; oci8_connection *connection = 0; - sword error; OCI8_TLS_VARS; if (getParameters(ht, 3, &userParam, &passParam, &dbParam) == SUCCESS) { @@ -2193,48 +2191,52 @@ connection->session = session; /* allocate our private error-handle */ - error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, - (dvoid **)&connection->pError, - OCI_HTYPE_ERROR, - 0, - NULL); - if (error != OCI_SUCCESS) { - oci8_error(server->pError, "oci8_do_connect: OCIHandleAlloc OCI_HTYPE_ERROR", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&connection->pError, + OCI_HTYPE_ERROR, + 0, + NULL); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "oci8_do_connect: OCIHandleAlloc OCI_HTYPE_ERROR",OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } /* allocate our service-context */ - error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, - (dvoid **)&connection->pServiceContext, - OCI_HTYPE_SVCCTX, - 0, - NULL); - if (error != OCI_SUCCESS) { - oci8_error(connection->pError, "oci8_do_connect: OCIHandleAlloc OCI_HTYPE_SVCCTX", error); + OCI8_GLOBAL(php3_oci8_module).error = + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&connection->pServiceContext, + OCI_HTYPE_SVCCTX, + 0, + NULL); + if (OCI8_GLOBAL(php3_oci8_module).error != OCI_SUCCESS) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError, "oci8_do_connect: OCIHandleAlloc OCI_HTYPE_SVCCTX",OCI8_GLOBAL(php3_oci8_module).error); goto CLEANUP; } /* Set the server handle in service handle */ - error = OCIAttrSet(connection->pServiceContext, - OCI_HTYPE_SVCCTX, - server->pServer, - 0, - OCI_ATTR_SERVER, - connection->pError); - if (error != OCI_SUCCESS) { - oci8_error(connection->pError, "oci8_do_connect: OCIAttrSet OCI_ATTR_SERVER", error); + connection->error = + OCIAttrSet(connection->pServiceContext, + OCI_HTYPE_SVCCTX, + server->pServer, + 0, + OCI_ATTR_SERVER, + connection->pError); + if (connection->error != OCI_SUCCESS) { + oci8_error(connection->pError, "oci8_do_connect: OCIAttrSet OCI_ATTR_SERVER", connection->error); goto CLEANUP; } - /* Set the Authentication handle in the service handle */ - error = OCIAttrSet(connection->pServiceContext, - OCI_HTYPE_SVCCTX, - session->pSession, - 0, - OCI_ATTR_SESSION, - connection->pError); - if (error != OCI_SUCCESS) { - oci8_error(connection->pError, "oci8_do_connect: OCIAttrSet OCI_ATTR_SESSION", error); + /* Set the Authentication handle in the service handle */ + connection->error = + OCIAttrSet(connection->pServiceContext, + OCI_HTYPE_SVCCTX, + session->pSession, + 0, + OCI_ATTR_SESSION, + connection->pError); + if (connection->error != OCI_SUCCESS) { + oci8_error(connection->pError, "oci8_do_connect: OCIAttrSet OCI_ATTR_SESSION", connection->error); goto CLEANUP; } @@ -2360,7 +2362,6 @@ oci8_statement *bindstmt; oci8_bind *bind, *tmp_bind; oci8_descriptor *descr; - sword error; ub2 ocitype; sb4 ocimaxlen; OCIStmt *mystmt = 0; @@ -2454,32 +2455,34 @@ bind->pStmt = mystmt; bind->maxsize = ocimaxlen; - error = OCIBindByName(statement->pStmt, /* statement handle */ - (OCIBind **)&bind->pBind, /* bind hdl (will alloc) */ - statement->pError, /* error handle */ - name->value.str.val, /* placeholder name */ - name->value.str.len, /* placeholder length */ - (dvoid *)0, /* in/out data */ - ocimaxlen, /* max size of input/output data */ - (ub2)ocitype, /* in/out data type */ - (dvoid *)&bind->indicator, /* indicator (ignored) */ - (ub2 *)0, /* size array (ignored) */ - (ub2 *)&bind->retcode, /* return code (ignored) */ - (ub4)0, /* maxarr_len (PL/SQL only?) */ - (ub4 *)0, /* actual array size (PL/SQL only?) */ - OCI_DATA_AT_EXEC /* mode */); - if (error != OCI_SUCCESS) { - oci8_error(statement->pError, "OCIBindByName", error); - RETURN_FALSE; - } - error = OCIBindDynamic(bind->pBind, - statement->pError, - (dvoid *)bind, - oci8_bind_in_callback, - (dvoid *)bind, - oci8_bind_out_callback); - if (error != OCI_SUCCESS) { - oci8_error(statement->pError, "OCIBindDynamic", error); + statement->error = + OCIBindByName(statement->pStmt, /* statement handle */ + (OCIBind **)&bind->pBind, /* bind hdl (will alloc) */ + statement->pError, /* error handle */ + name->value.str.val, /* placeholder name */ + name->value.str.len, /* placeholder length */ + (dvoid *)0, /* in/out data */ + ocimaxlen, /* max size of input/output data */ + (ub2)ocitype, /* in/out data type */ + (dvoid *)&bind->indicator, /* indicator (ignored) */ + (ub2 *)0, /* size array (ignored) */ + (ub2 *)&bind->retcode, /* return code (ignored) */ + (ub4)0, /* maxarr_len (PL/SQL only?) */ + (ub4 *)0, /* actual array size (PL/SQL only?) */ + OCI_DATA_AT_EXEC /* mode */); + if (statement->error != OCI_SUCCESS) { + oci8_error(statement->pError, "OCIBindByName", statement->error); + RETURN_FALSE; + } + statement->error = + OCIBindDynamic(bind->pBind, + statement->pError, + (dvoid *)bind, + oci8_bind_in_callback, + (dvoid *)bind, + oci8_bind_out_callback); + if (statement->error != OCI_SUCCESS) { + oci8_error(statement->pError, "OCIBindDynamic", statement->error); RETURN_FALSE; } @@ -2532,7 +2535,6 @@ OCILobLocator *mylob; oci8_connection *connection; oci8_descriptor *descr; - sword ociresult; ub4 loblen; OCI8_TLS_VARS; @@ -2575,23 +2577,25 @@ RETURN_FALSE; } - ociresult = OCILobWrite(connection->pServiceContext, - connection->pError, - mylob, - &loblen, - (ub4) 1, - (dvoid *) arg->value.str.val, - (ub4) loblen, - OCI_ONE_PIECE, - (dvoid *)0, - (OCICallbackLobWrite) 0, - (ub2) 0, - (ub1) SQLCS_IMPLICIT ); + + connection->error = + OCILobWrite(connection->pServiceContext, + connection->pError, + mylob, + &loblen, + (ub4) 1, + (dvoid *) arg->value.str.val, + (ub4) loblen, + OCI_ONE_PIECE, + (dvoid *)0, + (OCICallbackLobWrite) 0, + (ub2) 0, + (ub1) SQLCS_IMPLICIT ); oci8_debug("OCIsavedesc: size=%d",loblen); - if (ociresult) { - oci8_error(connection->pError, "OCILobWrite", ociresult); + if (connection->error) { + oci8_error(connection->pError, "OCILobWrite", connection->error); RETURN_FALSE; } @@ -2653,7 +2657,6 @@ void php3_oci8_newdescriptor(INTERNAL_FUNCTION_PARAMETERS) { pval *conn, *type; - sword ociresult; oci8_connection *connection; oci8_descriptor descr; int mylob; @@ -2686,10 +2689,15 @@ RETURN_FALSE; } - ociresult = OCIDescriptorAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv,(dvoid*)&(descr.ocidescr), descr.type, (size_t) 0, (dvoid **) 0); + OCI8_GLOBAL(php3_oci8_module).error = + OCIDescriptorAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid*)&(descr.ocidescr), + descr.type, + (size_t) 0, + (dvoid **) 0); - if (ociresult) { - oci8_error(connection->pError,"OCIDescriptorAlloc %d",ociresult); + if (OCI8_GLOBAL(php3_oci8_module).error) { + oci8_error(OCI8_GLOBAL(php3_oci8_module).pError,"OCIDescriptorAlloc %d",OCI8_GLOBAL(php3_oci8_module).error); RETURN_FALSE; } @@ -2726,7 +2734,6 @@ { pval *conn; oci8_connection *connection; - sword ociresult; OCI8_TLS_VARS; if (getParameters(ht, 1, &conn) == FAILURE) { @@ -2739,12 +2746,13 @@ RETURN_FALSE; } - ociresult = OCITransRollback(connection->pServiceContext,connection->pError, (ub4)0); + connection->error = + OCITransRollback(connection->pServiceContext, + connection->pError, + (ub4)0); - oci8_debug("OCITransRollback=%d",ociresult); - - if (ociresult) { - oci8_error(connection->pError, "OCIRollback", ociresult); + if (connection->error) { + oci8_error(connection->pError, "OCIRollback", connection->error); RETURN_FALSE; } @@ -2760,7 +2768,6 @@ { pval *conn; oci8_connection *connection; - sword ociresult; OCI8_TLS_VARS; if (getParameters(ht, 1, &conn) == FAILURE) { @@ -2773,10 +2780,13 @@ RETURN_FALSE; } - ociresult = OCITransCommit(connection->pServiceContext,connection->pError, (ub4)0); + connection->error = + OCITransCommit(connection->pServiceContext, + connection->pError, + (ub4)0); - if (ociresult) { - oci8_error(connection->pError, "OCICommit", ociresult); + if (connection->error) { + oci8_error(connection->pError, "OCICommit", connection->error); RETURN_FALSE; } @@ -3318,8 +3328,8 @@ } /* }}} */ -/* {{{ proto int OCIError(int stmt|conn) - Return the last error of stmt|conn. If no error happened returns false. +/* {{{ proto int OCIError([int stmt|conn]) + Return the last error of stmt|conn|global. If no error happened returns false. */ void php3_oci8_error(INTERNAL_FUNCTION_PARAMETERS) @@ -3330,23 +3340,31 @@ text errbuf[512]; ub4 errcode = 0; int type; + sword error = 0; dvoid *errh = NULL; OCI8_TLS_VARS; - if (getParameters(ht, 1, &mixed) == FAILURE) { - WRONG_PARAM_COUNT; + if (getParameters(ht, 1, &mixed) == SUCCESS) { + convert_to_long(mixed); + statement = (oci8_statement *)php3_list_find(mixed->value.lval, &type); + if (statement && OCI8_STMT_TYPE(type)) { + errh = statement->pError; + error = statement->error; + } else { + connection = (oci8_connection *)php3_list_find(mixed->value.lval, &type); + if (connection && OCI8_CONN_TYPE(type)) { + errh = connection->pError; + error = connection->error; + } + } + } else { + errh = OCI8_GLOBAL(php3_oci8_module).pError; + error = OCI8_GLOBAL(php3_oci8_module).error; } - convert_to_long(mixed); - statement = (oci8_statement *)php3_list_find(mixed->value.lval, &type); - if (statement && OCI8_STMT_TYPE(type)) { - errh = statement->pError; - } else { - connection = (oci8_connection *)php3_list_find(mixed->value.lval, &type); - if (connection && OCI8_CONN_TYPE(type)) { - errh = connection->pError; - } + if (! error) { /* no error set in the handle */ + RETURN_FALSE; } if (! errh) { @@ -3488,7 +3506,6 @@ oci8_connection *connection; pval *arg; int index, index_t; - sword error; char version[256]; OCI8_TLS_VARS; @@ -3501,11 +3518,14 @@ if (!connection || !OCI8_CONN_TYPE(index_t)) { RETURN_FALSE; } - error = OCIServerVersion(connection->pServiceContext, - connection->pError, version, sizeof(version), - OCI_HTYPE_SVCCTX); - if (error != OCI_SUCCESS) { - oci8_error(connection->pError, "OCIServerVersion", error); + connection->error = + OCIServerVersion(connection->pServiceContext, + connection->pError, + version, + sizeof(version), + OCI_HTYPE_SVCCTX); + if (connection->error != OCI_SUCCESS) { + oci8_error(connection->pError, "OCIServerVersion", connection->error); RETURN_FALSE; } RETURN_STRING(version,1); @@ -3523,7 +3543,6 @@ pval *stmt; oci8_statement *statement; ub2 stmttype; - sword error; OCI8_TLS_VARS; if (getParameters(ht, 1, &stmt) == FAILURE) { @@ -3535,11 +3554,15 @@ RETURN_FALSE; } - error = OCIAttrGet((dvoid *)statement->pStmt, OCI_HTYPE_STMT, - (ub2 *)&stmttype, (ub4 *)0, OCI_ATTR_STMT_TYPE, - statement->pError); - if (error != OCI_SUCCESS) { - oci8_error(statement->pError, "OCIStatementType", error); + statement->error = + OCIAttrGet((dvoid *)statement->pStmt, + OCI_HTYPE_STMT, + (ub2 *)&stmttype, + (ub4 *)0, + OCI_ATTR_STMT_TYPE, + statement->pError); + if (statement->error != OCI_SUCCESS) { + oci8_error(statement->pError, "OCIStatementType", statement->error); RETURN_FALSE; } @@ -3581,7 +3604,6 @@ pval *stmt; oci8_statement *statement; ub4 rowcount; - sword error; OCI8_TLS_VARS; if (getParameters(ht, 1, &stmt) == FAILURE) { @@ -3593,12 +3615,16 @@ RETURN_FALSE; } - error = OCIAttrGet((dvoid *)statement->pStmt, OCI_HTYPE_STMT, - (ub2 *)&rowcount, (ub4 *)0, OCI_ATTR_ROW_COUNT, - statement->pError); + statement->error = + OCIAttrGet((dvoid *)statement->pStmt, + OCI_HTYPE_STMT, + (ub2 *)&rowcount, + (ub4 *)0, + OCI_ATTR_ROW_COUNT, + statement->pError); - if (error != OCI_SUCCESS) { - oci8_error(statement->pError, "OCIRowCount", error); + if (statement->error != OCI_SUCCESS) { + oci8_error(statement->pError, "OCIRowCount", statement->error); RETURN_FALSE; } Index: php3/functions/php3_oci8.h diff -u php3/functions/php3_oci8.h:1.46 php3/functions/php3_oci8.h:1.47 --- php3/functions/php3_oci8.h:1.46 Thu May 6 08:52:03 1999 +++ php3/functions/php3_oci8.h Wed May 12 07:16:47 1999 @@ -58,7 +58,6 @@ int persistent; int open; char *dbname; - OCIError *pError; OCIServer *pServer; OCIFocbkStruct failover; } oci8_server; @@ -68,7 +67,6 @@ int persistent; int open; oci8_server *server; - OCIError *pError; OCISession *pSession; } oci8_session; @@ -77,6 +75,7 @@ int open; oci8_session *session; OCISvcCtx *pServiceContext; + sword error; OCIError *pError; HashTable *descriptors; int descriptors_count; @@ -98,6 +97,7 @@ typedef struct { int id; oci8_connection *conn; + sword error; OCIError *pError; OCIStmt *pStmt; char *last_query; @@ -141,6 +141,7 @@ } oci8_out_column; typedef struct { + sword error; OCIError *pError; char *default_username; char *default_password; -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#5551) next »