Index: ingres.c =================================================================== RCS file: /repository/pecl/ingres/ingres.c,v retrieving revision 1.1 diff -u -w -r1.1 ingres.c --- ingres.c 14 Apr 2008 17:02:26 -0000 1.1 +++ ingres.c 27 May 2008 16:15:13 -0000 @@ -16,7 +16,7 @@ | http://www.eclips-software.com | | mailto:idev@eclips-software.com | | Ingres Corporation, http://ingres.com | - | Authors: David Hénot | + | Authors: David H�not | | Grant Croker | +----------------------------------------------------------------------+ */ @@ -271,6 +271,7 @@ static int _rollback_transaction(II_LINK *ii_link TSRMLS_DC) { IIAPI_ROLLBACKPARM rollbackParm; + IIAPI_GETEINFOPARM error_info; /* clean up any un-freed statements/results */ _free_ii_link_result_list(ii_link TSRMLS_CC); @@ -286,9 +287,35 @@ switch((rollbackParm.rb_genParm).gp_status) { case IIAPI_ST_SUCCESS: + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_rollback_transaction: IIAPI_ST_SUCCESS"); + break; + case IIAPI_ST_MESSAGE: + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_rollback_transaction: IIAPI_ST_MESSAGE"); + break; + case IIAPI_ST_WARNING: + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_rollback_transaction: IIAPI_ST_WARNING"); + break; case IIAPI_ST_NO_DATA: + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_rollback_transaction: IIAPI_ST_NO_DATA"); + break; + case IIAPI_ST_FAILURE: + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_rollback_transaction: IIAPI_ST_FAILURE"); + error_info.ge_errorHandle = (rollbackParm.rb_genParm).gp_errorHandle; + IIapi_getErrorInfo(&error_info); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_rollback_transaction : IIAPI_ST_FAILURE: %d - %s", error_info.ge_errorCode, error_info.ge_message); break; default: + error_info.ge_errorHandle = (rollbackParm.rb_genParm).gp_errorHandle; + IIapi_getErrorInfo(&error_info); + if (error_info.ge_status == IIAPI_ST_SUCCESS) + { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_rollback_transaction : %d - %s", error_info.ge_errorCode, error_info.ge_message); + } + else + { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_rollback_transaction : Unable to perform internal rollback"); + } + php_error_docref(NULL TSRMLS_CC, E_WARNING, "_rollback_transaction : Unable to rollback transaction"); } @@ -303,6 +330,10 @@ static int _commit_transaction(II_LINK *ii_link TSRMLS_DC) { IIAPI_COMMITPARM commitParm; + if (IIG(ingres_trace)) + { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_commit_transaction: started"); + } if ( ii_link->tranHandle != NULL ) { @@ -315,6 +346,10 @@ if (ii_success(&(commitParm.cm_genParm), &ii_link->errorHandle TSRMLS_CC) == II_FAIL) { + if (IIG(ingres_trace)) + { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_commit_transaction: no success"); + } return II_FAIL; } @@ -382,6 +417,10 @@ IIAPI_DISCONNPARM disconnParm; IIAPI_GETEINFOPARM error_info; + if (IIG(ingres_trace)) + { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_close_ii_link: started"); + } /* clean up any un-freed statements/results */ _free_ii_link_result_list(ii_link TSRMLS_CC); @@ -440,7 +479,10 @@ free(ii_link); IIG(num_links)--; - + if (IIG(ingres_trace)) + { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "_close_ii_link: done"); + } } /* }}} */ @@ -504,14 +546,14 @@ ii_link->stmtHandle = NULL; break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "_close_ii_link : Unable to close statement"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "_free_ii_result_link_list : Unable to close statement"); } /* if (ii_success(&(closeParm.cl_genParm), &ii_link->errorHandle TSRMLS_CC) == II_FAIL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "_close_ii_link : Unable to close statement"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "_free_ii_result_link_list : Unable to close statement"); } else { ii_link->stmtHandle = NULL; } @@ -607,6 +649,7 @@ disconnParm.dc_connHandle = ii_link->connHandle; IIapi_disconnect(&disconnParm); + ii_sync(&(disconnParm.dc_genParm)); ii_link->connHandle = NULL; } @@ -803,6 +846,11 @@ /* {{{ End of request */ PHP_RSHUTDOWN_FUNCTION(ingres) { + if (IIG(error_text) != NULL) + { + efree(IIG(error_text)); + IIG(error_text) = NULL; + } return SUCCESS; } /* }}} */ @@ -1221,6 +1269,7 @@ if ( php_ii_set_connect_options(options, ii_link, db TSRMLS_CC ) == II_FAIL ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to set options provided"); + efree(hashed_details); RETURN_FALSE; } } @@ -1309,8 +1358,10 @@ zend_list_addref((int) ii_link); Z_LVAL_P(return_value) = (int) ii_link; + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Freeing hashed_details"); Z_TYPE_P(return_value) = IS_RESOURCE; efree(hashed_details); + hashed_details = NULL; return; } else { zend_hash_del(&EG(regular_list), hashed_details, hashed_details_length + 1); @@ -1426,7 +1477,11 @@ } } + if (hashed_details != NULL) + { efree(hashed_details); + hashed_details = NULL; + } if (IIG(trace_connect)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Exit php_ii_do_connect"); @@ -1516,10 +1571,12 @@ char *paramtypes = NULL; int query_len=0; int paramtypes_len=0; - II_LINK *ii_link; - II_RESULT *ii_result; + II_LINK *ii_link = {0}; + II_RESULT *ii_result = {0}; IIAPI_QUERYPARM queryParm; IIAPI_GETDESCRPARM getDescrParm; + IIAPI_CANCELPARM cancelParm; + IIAPI_CLOSEPARM closeParm; HashTable *arr_hash; int elementCount; @@ -1528,6 +1585,10 @@ char *converted_query = NULL; int query_type; int converted_query_len; + ii_result_entry *result_ptr = NULL; + short int result_resource = FALSE; + int type = 0; + char *type_name = NULL; ii_result_entry *result_entry; @@ -1539,6 +1600,69 @@ ZEND_FETCH_RESOURCE2(ii_link, II_LINK*, &link, -1, "Ingres Link", le_ii_link, le_ii_plink); + /* If the last statement produced no rows we should call IIapi_close() else it will be lost */ + /* Row returning statements will have a result resource that references the stmtHandle. */ + + if (ii_link->stmtHandle != NULL) + { + /* Is this stmtHandle associated with a result resource? */ + if (ii_link->result_list_ptr) + { + result_ptr = (ii_result_entry *)ii_link->result_list_ptr; + while (result_ptr) + { + ii_result = (II_RESULT *)zend_list_find(result_ptr->result_id, &type); + if ((ii_result) && (type == le_ii_result)) + { + if (ii_result->stmtHandle == ii_link->stmtHandle) + { + /* Found it */ + result_resource = TRUE; + break; + } + } + /* Next */ + result_ptr = (ii_result_entry *)result_ptr->next_result_ptr; + } + } + if (result_resource == FALSE) + { + /* Close the statement since it is not associated with any current resource */ + if (IIG(ingres_trace)) + { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Closing a non-result resource statHandle"); + } + + /* Cancel query processing. */ + cancelParm.cn_genParm.gp_callback = NULL; + cancelParm.cn_genParm.gp_closure = NULL; + cancelParm.cn_stmtHandle = ii_link->stmtHandle; + + IIapi_cancel(&cancelParm ); + + ii_sync(&(cancelParm.cn_genParm)); + + /* Free query resources. */ + closeParm.cl_genParm.gp_callback = NULL; + closeParm.cl_genParm.gp_closure = NULL; + closeParm.cl_stmtHandle = ii_link->stmtHandle; + + IIapi_close( &closeParm ); + + ii_sync(&(closeParm.cl_genParm)); + + switch((closeParm.cl_genParm).gp_status) + { + case IIAPI_ST_SUCCESS: + case IIAPI_ST_NO_DATA: + ii_link->stmtHandle = NULL; + break; + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error: %d - Unable to close non-result resource statement", (closeParm.cl_genParm).gp_status); + } + } + } + /* determine what sort of query is being executed */ query_type = php_ii_query_type(query TSRMLS_CC); @@ -1835,6 +1959,11 @@ efree(converted_query); converted_query = NULL; } + if (ii_result) + { + free(ii_result); + ii_result = NULL; + } RETURN_FALSE; } @@ -2749,8 +2878,8 @@ { resource = zend_list_find(ii_result->link_id, &type); type_name = zend_rsrc_list_get_rsrc_type(ii_result->link_id TSRMLS_CC); - /* Is it an "ingres connection" ? */ - if (strcmp("ingres connection\0",type_name) == 0 ) + /* Is it an "ingres (persistent) connection" ? */ + if ((strcmp("ingres connection\0",type_name) == 0 ) || (strcmp("ingres persistent connection\0",type_name) == 0 )) { this_ptr = (char *)((II_LINK *)resource)->result_list_ptr; result_entry = ((II_LINK *)resource)->result_list_ptr; @@ -3472,7 +3601,7 @@ II_RESULT *ii_result; II_INT2 row_count=1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC ,"r|lll" , &result, &row_position, &row_count, &result_type) == FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC ,"r|lll" , &result, &result_type, &row_position, &row_count) == FAILURE) { RETURN_FALSE; }