cvs: pecl /ibm_db2 CREDITS ibm_db2.c package.xml php_ibm_db2.h
| From: | Kellen Bombardier | Date: | Thu, 23 Feb 2006 16:38:36 +0000 |
| Subject: | cvs: pecl /ibm_db2 CREDITS ibm_db2.c package.xml php_ibm_db2.h | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-5249@lists.php.net to get a copy of this message | ||
kfbombar Thu Feb 23 16:38:36 2006 UTC
Modified files:
/pecl/ibm_db2 CREDITS package.xml ibm_db2.c php_ibm_db2.h
Log:
Prep for next beta release.
http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/CREDITS?r1=1.3&r2=1.4&diff_format=u Index: pecl/ibm_db2/CREDITS diff -u pecl/ibm_db2/CREDITS:1.3 pecl/ibm_db2/CREDITS:1.4 --- pecl/ibm_db2/CREDITS:1.3 Wed Aug 31 00:15:56 2005 +++ pecl/ibm_db2/CREDITS Thu Feb 23 16:38:35 2006 @@ -1,2 +1,2 @@ IBM_DB2 -Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, Dan Scott, Helmut Tessarek, Edin Kadribasic +Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, Dan Scott, Helmut Tessarek, Edin Kadribasic, Kellen Bombardier http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/package.xml?r1=1.10&r2=1.11&diff_format=u Index: pecl/ibm_db2/package.xml diff -u pecl/ibm_db2/package.xml:1.10 pecl/ibm_db2/package.xml:1.11 --- pecl/ibm_db2/package.xml:1.10 Thu Feb 23 16:20:12 2006 +++ pecl/ibm_db2/package.xml Thu Feb 23 16:38:35 2006 @@ -18,7 +18,7 @@ <release> <version>1.2.0</version> - <date>2006-01-26</date> + <date>2006-02-23</date> <license>Apache License 2.0</license> <state>beta</state> <notes> @@ -29,6 +29,7 @@ Handle null characters within SQL values (bug 6572). Avoid appending a null character to CLOB values (bug 6755). Enable default cursor type to be set as a connection attribute. + Provide initial support for native XML data type. </notes> <configureoptions> <configureoption name="with-IBM_DB2" prompt="DB2 Installation Directory?" /> @@ -56,6 +57,8 @@ <file name="test_003.phpt" role="test" /> <file name="test_004.phpt" role="test" /> <file name="test_005.phpt" role="test" /> + <file name="test_006.phpt" role="test" /> + <file name="test_007.phpt" role="test" /> <file name="test_010.phpt" role="test" /> <file name="test_011.phpt" role="test" /> <file name="test_012.phpt" role="test" /> @@ -81,6 +84,7 @@ <file name="test_041.phpt" role="test" /> <file name="test_042.phpt" role="test" /> <file name="test_043.phpt" role="test" /> + <file name="test_044.phpt" role="test" /> <file name="test_045.phpt" role="test" /> <file name="test_046.phpt" role="test" /> <file name="test_047.phpt" role="test" /> @@ -95,6 +99,7 @@ <file name="test_063.phpt" role="test" /> <file name="test_064.phpt" role="test" /> <file name="test_065.phpt" role="test" /> + <file name="test_066.phpt" role="test" /> <file name="test_070.phpt" role="test" /> <file name="test_071.phpt" role="test" /> <file name="test_080.phpt" role="test" /> @@ -146,6 +151,8 @@ <file name="test_190.phpt" role="test" /> <file name="test_191.phpt" role="test" /> <file name="test_192.phpt" role="test" /> + <file name="test_193.phpt" role="test" /> + <file name="test_194.phpt" role="test" /> <file name="test_200.phpt" role="test" /> <file name="test_201.phpt" role="test" /> <file name="test_210.phpt" role="test" /> @@ -168,6 +175,7 @@ <file name="test_6561.phpt" role="test" /> <file name="test_6572.phpt" role="test" /> <file name="test_6755.phpt" role="test" /> + <file name="test_6792.phpt" role="test" /> </dir> </filelist> </release> http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/ibm_db2.c?r1=1.43&r2=1.44&diff_format=u Index: pecl/ibm_db2/ibm_db2.c diff -u pecl/ibm_db2/ibm_db2.c:1.43 pecl/ibm_db2/ibm_db2.c:1.44 --- pecl/ibm_db2/ibm_db2.c:1.43 Thu Feb 16 17:45:11 2006 +++ pecl/ibm_db2/ibm_db2.c Thu Feb 23 16:38:35 2006 @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | (C) Copyright IBM Corporation 2005,2006 | + | (C) Copyright IBM Corporation 2006. | +----------------------------------------------------------------------+ | | | Licensed under the Apache License, Version 2.0 (the "License"); you | @@ -15,10 +15,10 @@ | permissions and limitations under the License. | +----------------------------------------------------------------------+ | Authors: Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, | - | Dan Scott, Helmut Tessarek | + | Dan Scott, Helmut Tessarek, Kellen Bombardier | +----------------------------------------------------------------------+ - $Id: ibm_db2.c,v 1.43 2006/02/16 17:45:11 tessus Exp $ + $Id: ibm_db2.c,v 1.44 2006/02/23 16:38:35 kfbombar Exp $ */ #define MODULE_RELEASE "1.2.0" @@ -59,6 +59,8 @@ SQLSMALLINT scale; /* Decimal scale */ SQLUINTEGER file_options; /* File options if DB2_PARAM_FILE */ SQLINTEGER bind_indicator; /* indicator variable for SQLBindParameter */ + SQLINTEGER long_value; /* Value if this is an SQL_C_LONG type */ + SQLSMALLINT short_strlen; /* Length of string if this is an SQL_C_STRING type */ int param_num; /* param number in stmt */ int param_type; /* Type of param - INP/OUT/INP-OUT/FILE */ char *varname; /* bound variable name */ @@ -302,6 +304,7 @@ case SQL_BIGINT: case SQL_DECIMAL: case SQL_NUMERIC: + case SQL_XML: if ( handle->row_data[i].data.str_val != NULL ) { efree(handle->row_data[i].data.str_val); handle->row_data[i].data.str_val = NULL; @@ -405,6 +408,7 @@ /* This is how CLI defines SQL_C_LONG */ REGISTER_LONG_CONSTANT("DB2_LONG", SQL_INTEGER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DB2_CHAR", SQL_CHAR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DB2_XML", SQL_XML, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DB2_CASE_NATURAL", 0, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DB2_CASE_LOWER", 1, CONST_CS | CONST_PERSISTENT); @@ -430,9 +434,9 @@ putenv("DB2NOEXITLIST=TRUE"); #endif - le_conn_struct = zend_register_list_destructors_ex( _php_db2_free_conn_struct, NULL, "conn struct", module_number); - le_pconn_struct = zend_register_list_destructors_ex(NULL, _php_db2_free_pconn_struct, "pconn struct", module_number); - le_stmt_struct = zend_register_list_destructors_ex( _php_db2_free_stmt_struct, NULL, "stmt struct", module_number); + le_conn_struct = zend_register_list_destructors_ex( _php_db2_free_conn_struct, NULL, DB2_CONN_NAME, module_number); + le_pconn_struct = zend_register_list_destructors_ex(NULL, _php_db2_free_pconn_struct, DB2_PCONN_NAME, module_number); + le_stmt_struct = zend_register_list_destructors_ex( _php_db2_free_stmt_struct, NULL, DB2_STMT_NAME, module_number); return SUCCESS; } /* }}} */ @@ -856,6 +860,15 @@ } break; + case SQL_XML: + in_length = stmt_res->column_info[i].size+1; + row_data->str_val = (SQLCHAR *)ecalloc(1, in_length); + + rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1), + SQL_C_BINARY, row_data->str_val, in_length, + (SQLINTEGER *)(&stmt_res->row_data[i].out_length)); + break; + case SQL_TYPE_DATE: case SQL_TYPE_TIME: case SQL_TYPE_TIMESTAMP: @@ -2038,9 +2051,9 @@ } /* }}} */ -/* {{{ static param_node* build_list( stmt_res, param_no, data_type, precision, scale, nullable ) +/* {{{ static param_node* _php_db2_build_list( stmt_res, param_no, data_type, precision, scale, nullable ) */ -static param_node* build_list( stmt_handle *stmt_res, int param_no, SQLSMALLINT data_type, SQLUINTEGER precision, SQLSMALLINT scale, SQLSMALLINT nullable ) +static param_node* _php_db2_build_list( stmt_handle *stmt_res, int param_no, SQLSMALLINT data_type, SQLUINTEGER precision, SQLSMALLINT scale, SQLSMALLINT nullable ) { param_node *tmp_curr = NULL, *curr = stmt_res->head_cache_list, *prev = NULL; @@ -2054,6 +2067,7 @@ tmp_curr->param_num = param_no; tmp_curr->file_options = SQL_FILE_READ; tmp_curr->param_type = DB2_PARAM_IN; + tmp_curr->long_value = 0; MAKE_STD_ZVAL(tmp_curr->value); while ( curr != NULL ) { @@ -2101,26 +2115,22 @@ curr->bind_indicator = 0; /* Bind file name string */ + curr->short_strlen = (SQLSMALLINT) ((curr->value)->value.str.len); rc = SQLBindFileToParam((SQLHSTMT)stmt_res->hstmt, curr->param_num, curr->data_type, (SQLCHAR *)((curr->value)->value.str.val), - (SQLSMALLINT *)&((curr->value)->value.str.len), &(curr->file_options), + (SQLSMALLINT *)&curr->short_strlen, &(curr->file_options), Z_STRLEN_P(curr->value), &(curr->bind_indicator)); return rc; } switch(Z_TYPE_PP(bind_data)) { + case IS_BOOL: case IS_LONG: + curr->long_value = (SQLINTEGER)(curr->value)->value.lval; rc = SQLBindParameter(stmt_res->hstmt, curr->param_num, curr->param_type, SQL_C_LONG, curr->data_type, - curr->param_size, curr->scale, &((curr->value)->value.lval), 0, NULL); - break; - - /* Convert BOOLEAN types to LONG for DB2 / Cloudscape */ - case IS_BOOL: - rc = SQLBindParameter(stmt_res->hstmt, curr->param_num, - curr->param_type, SQL_C_LONG, curr->data_type, curr->param_size, - curr->scale, &((curr->value)->value.lval), 0, NULL); + curr->param_size, curr->scale, &curr->long_value, 0, NULL); break; case IS_DOUBLE: @@ -2147,6 +2157,7 @@ case SQL_BINARY: case SQL_LONGVARBINARY: case SQL_VARBINARY: + case SQL_XML: /* account for bin_mode settings as well */ curr->bind_indicator = (curr->value)->value.str.len; valueType = SQL_C_BINARY; @@ -2241,7 +2252,7 @@ return rc; } - curr = build_list( stmt_res, param_no, data_type, precision, scale, nullable ); + curr = _php_db2_build_list( stmt_res, param_no, data_type, precision, scale, nullable ); rc = _php_db2_bind_data( stmt_res, curr, data); if ( rc == SQL_ERROR ) { @@ -2300,165 +2311,171 @@ /* Execute */ /* Return values back to symbol table for OUT params */ - if (stmt) { + if (!stmt) { + return; + } - ZEND_FETCH_RESOURCE(stmt_res, stmt_handle*, &stmt, stmt_id, "Statement Resource", le_stmt_struct); + ZEND_FETCH_RESOURCE(stmt_res, stmt_handle*, &stmt, stmt_id, "Statement Resource", le_stmt_struct); - /* Free any cursors that might have been allocated in a previous call to SQLExecute */ - SQLFreeStmt((SQLHSTMT)stmt_res->hstmt, SQL_CLOSE); + /* Free any cursors that might have been allocated in a previous call to SQLExecute */ + SQLFreeStmt((SQLHSTMT)stmt_res->hstmt, SQL_CLOSE); - /* This ensures that each call to db2_execute start from scratch */ - stmt_res->current_node = stmt_res->head_cache_list; + /* This ensures that each call to db2_execute start from scratch */ + stmt_res->current_node = stmt_res->head_cache_list; - rc = SQLNumParams((SQLHSTMT)stmt_res->hstmt, (SQLSMALLINT*)&num); + rc = SQLNumParams((SQLHSTMT)stmt_res->hstmt, (SQLSMALLINT*)&num); + + if ( num != 0 ) { + /* Parameter Handling */ + if ( parameters_array != NULL ) { + /* Make sure db2_bind_param has been called */ + /* If the param list is NULL -- ERROR */ + if ( stmt_res->head_cache_list == NULL ) { + bind_params = 1; + } + + numOpts = zend_hash_num_elements(Z_ARRVAL_P(parameters_array)); + if (numOpts > num) { + /* More are passed in -- Warning - Use the max number present */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param count incorrect"); + numOpts = stmt_res->num_params; + } else if (numOpts < num) { + /* If there are less params passed in, than are present -- Error */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param count incorrect"); + RETURN_FALSE; + } - if ( num != 0 ) { - /* Parameter Handling */ - if ( parameters_array != NULL ) { - /* Make sure db2_bind_param has been called */ - /* If the param list is NULL -- ERROR */ - if ( stmt_res->head_cache_list == NULL ) { - bind_params = 1; - } + zend_hash_internal_pointer_reset(Z_ARRVAL_P(parameters_array)); + for ( i = 0; i < numOpts; i++) { + /* Bind values from the parameters_array to params */ + zend_hash_get_current_data(Z_ARRVAL_P(parameters_array), (void**)&data); - numOpts = zend_hash_num_elements(Z_ARRVAL_P(parameters_array)); - if (numOpts > num) { - /* More are passed in -- Warning - Use the max number present */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param count incorrect"); - numOpts = stmt_res->num_params; - } else if (numOpts < num) { - /* If there are less params passed in, than are present -- Error */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param count incorrect"); + /* + The 0 denotes that you work only with the current node. + The 4th argument specifies whether the data passed in + has been described. So we need to call SQLDescribeParam + before binding depending on this. + */ + rc = _php_db2_execute_helper(stmt_res, data, 0, bind_params TSRMLS_CC); + if ( rc == SQL_ERROR) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binding Error"); RETURN_FALSE; } - zend_hash_internal_pointer_reset(Z_ARRVAL_P(parameters_array)); - for ( i = 0; i < numOpts; i++) { - /* Bind values from the parameters_array to params */ - zend_hash_get_current_data(Z_ARRVAL_P(parameters_array), (void**)&data); - - /* - The 0 denotes that you work only with the current node. - The 4th argument specifies whether the data passed in - has been described. So we need to call SQLDescribeParam - before binding depending on this. - */ - rc = _php_db2_execute_helper(stmt_res, data, 0, bind_params TSRMLS_CC); - if ( rc == SQL_ERROR) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binding Error"); - RETURN_FALSE; - } + /* Move array ptr forward */ + zend_hash_move_forward(Z_ARRVAL_P(parameters_array)); + } + } else { + /* No additional params passed in. Use values already bound. */ + if ( num > stmt_res->num_params ) { + /* More parameters than we expected */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "More parameters bound than present"); + } else if ( num < stmt_res->num_params ) { + /* Fewer parameters than we expected */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Less parameters bound than present"); + RETURN_FALSE; + } - /* Move array ptr forward */ - zend_hash_move_forward(Z_ARRVAL_P(parameters_array)); - } + /* Param cache node list is empty -- No params bound */ + if ( stmt_res->head_cache_list == NULL ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameters not bound"); + RETURN_FALSE; } else { - /* No additional params passed in. Use values already bound. */ - if ( num > stmt_res->num_params ) { - /* More parameters than we expected */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "More parameters bound than present"); - } else if ( num < stmt_res->num_params ) { - /* Fewer parameters than we expected */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Less parameters bound than present"); + /* The 1 denotes that you work with the whole list */ + /* And bind sequentially */ + rc = _php_db2_execute_helper(stmt_res, NULL, 1, 0 TSRMLS_CC); + if ( rc == SQL_ERROR ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binding Error 3"); RETURN_FALSE; } - - /* Param cache node list is empty -- No params bound */ - if ( stmt_res->head_cache_list == NULL ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameters not bound"); - RETURN_FALSE; - } else { - /* The 1 denotes that you work with the whole list */ - /* And bind sequentially */ - rc = _php_db2_execute_helper(stmt_res, NULL, 1, 0 TSRMLS_CC); - if ( rc == SQL_ERROR ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binding Error 3"); - RETURN_FALSE; - } - } - } - } else { - /* No Parameters */ - /* We just execute the statement. No additional work needed. */ - rc = SQLExecute((SQLHSTMT)stmt_res->hstmt); - if ( rc == SQL_ERROR ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed"); - RETURN_FALSE; } - RETURN_TRUE; } - - /* Execute Stmt -- All parameters bound */ + } else { + /* No Parameters */ + /* We just execute the statement. No additional work needed. */ rc = SQLExecute((SQLHSTMT)stmt_res->hstmt); if ( rc == SQL_ERROR ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed"); - RETVAL_FALSE; + RETURN_FALSE; } + RETURN_TRUE; + } - if ( rc == SQL_NEED_DATA ) { - while ( (SQLParamData((SQLHSTMT)stmt_res->hstmt, (SQLPOINTER *)&valuePtr)) == SQL_NEED_DATA ) { - /* passing data value for a parameter */ - rc = SQLPutData((SQLHSTMT)stmt_res->hstmt, (SQLPOINTER)(((zvalue_value*)valuePtr)->str.val), ((zvalue_value*)valuePtr)->str.len); - if ( rc == SQL_ERROR ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sending data failed"); - RETVAL_FALSE; - } + /* Execute Stmt -- All parameters bound */ + rc = SQLExecute((SQLHSTMT)stmt_res->hstmt); + if ( rc == SQL_ERROR ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed"); + RETVAL_FALSE; + } + + if ( rc == SQL_NEED_DATA ) { + while ( (SQLParamData((SQLHSTMT)stmt_res->hstmt, (SQLPOINTER *)&valuePtr)) == SQL_NEED_DATA ) { + /* passing data value for a parameter */ + rc = SQLPutData((SQLHSTMT)stmt_res->hstmt, (SQLPOINTER)(((zvalue_value*)valuePtr)->str.val), ((zvalue_value*)valuePtr)->str.len); + if ( rc == SQL_ERROR ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sending data failed"); + RETVAL_FALSE; } } + } - /* cleanup dynamic bindings if present */ - if ( bind_params == 1 ) { - /* Free param cache list */ - curr_ptr = stmt_res->head_cache_list; - prev_ptr = stmt_res->head_cache_list; - - while (curr_ptr != NULL) { - curr_ptr = curr_ptr->next; - - /* Free Values */ - if ( Z_TYPE_P(prev_ptr->value) == IS_STRING ) { - efree((prev_ptr->value)->value.str.val); - } + /* cleanup dynamic bindings if present */ + if ( bind_params == 1 ) { + /* Free param cache list */ + curr_ptr = stmt_res->head_cache_list; + prev_ptr = stmt_res->head_cache_list; - efree(prev_ptr->value); - efree(prev_ptr); + while (curr_ptr != NULL) { + curr_ptr = curr_ptr->next; - prev_ptr = curr_ptr; + /* Free Values */ + if ( Z_TYPE_P(prev_ptr->value) == IS_STRING ) { + efree((prev_ptr->value)->value.str.val); } - stmt_res->head_cache_list = NULL; - stmt_res->num_params = 0; - } else { - /* Bind the IN/OUT Params back into the active symbol table */ - tmp_curr = stmt_res->head_cache_list; - while (tmp_curr != NULL) { - switch(tmp_curr->param_type) { - case DB2_PARAM_OUT: - case DB2_PARAM_INOUT: - if( Z_TYPE_P( tmp_curr->value ) == IS_STRING && - (tmp_curr->bind_indicator != SQL_NULL_DATA - && tmp_curr->bind_indicator != SQL_NO_TOTAL )){ - /* - if the length of the string out parameter is returned - then correct the length of the corresponding php variable - */ - tmp_curr->value->value.str.val[tmp_curr->bind_indicator] = 0; - tmp_curr->value->value.str.len = tmp_curr->bind_indicator; - } - /* cant use zend_hash_update because the symbol need not exist. It might need to be created */ - ZEND_SET_SYMBOL(EG(active_symbol_table), tmp_curr->varname, tmp_curr->value); + efree(prev_ptr->value); + efree(prev_ptr); - default: - break; - } - tmp_curr = tmp_curr->next; - } + prev_ptr = curr_ptr; } - if ( rc != SQL_ERROR ) { - RETURN_TRUE; + stmt_res->head_cache_list = NULL; + stmt_res->num_params = 0; + } else { + /* Bind the IN/OUT Params back into the active symbol table */ + tmp_curr = stmt_res->head_cache_list; + while (tmp_curr != NULL) { + switch(tmp_curr->param_type) { + case DB2_PARAM_OUT: + case DB2_PARAM_INOUT: + if( Z_TYPE_P( tmp_curr->value ) == IS_STRING && + (tmp_curr->bind_indicator != SQL_NULL_DATA + && tmp_curr->bind_indicator != SQL_NO_TOTAL )){ + /* + if the length of the string out parameter is returned + then correct the length of the corresponding php variable + */ + tmp_curr->value->value.str.val[tmp_curr->bind_indicator] = 0; + tmp_curr->value->value.str.len = tmp_curr->bind_indicator; + } + else if (Z_TYPE_P(tmp_curr->value) == IS_LONG || + Z_TYPE_P(tmp_curr->value) == IS_BOOL) { + /* bind in the value of long_value instead */ + tmp_curr->value->value.lval = (long)tmp_curr->long_value; + } + /* cant use zend_hash_update because the symbol need not exist. It might need to be created */ + ZEND_SET_SYMBOL(EG(active_symbol_table), tmp_curr->varname, tmp_curr->value); + + default: + break; + } + tmp_curr = tmp_curr->next; } } + + if ( rc != SQL_ERROR ) { + RETURN_TRUE; + } } /* }}} */ @@ -2954,6 +2971,9 @@ case SQL_BLOB: str_val = "blob"; break; + case SQL_XML: + str_val = "xml"; + break; case SQL_TYPE_DATE: str_val = "date"; break; @@ -3088,7 +3108,7 @@ /* }}} */ /* {{{ static RETCODE _php_db2_get_data(stmt_handle *stmt_res, int col_num, short ctype, void *buff, int in_length, SQLINTEGER *out_length) */ -static RETCODE _php_db2_get_data(stmt_handle *stmt_res, int col_num, short ctype, void *buff, int in_length, SQLINTEGER *out_length) +static RETCODE _php_db2_get_data(stmt_handle *stmt_res, SQLUSMALLINT col_num, SQLSMALLINT ctype, SQLPOINTER buff, SQLLEN in_length, SQLLEN *out_length) { RETCODE rc=SQL_SUCCESS; @@ -3106,14 +3126,14 @@ zval *stmt = NULL; zval *column = NULL; stmt_handle *stmt_res; - long col_num; - RETCODE rc; - void *out_ptr; - char *out_char_ptr; + SQLSMALLINT col_num = 0; + RETCODE rc = 0; + void *out_ptr = NULL; + char *out_char_ptr = NULL; SQLINTEGER in_length, out_length=-10; /*Initialize out_length to some meaningless value*/ SQLSMALLINT column_type, lob_bind_type= SQL_C_BINARY; - double double_val; - long long_val; + SQLDOUBLE double_val = 0; + SQLINTEGER long_val = 0; if (zend_parse_parameters(argc TSRMLS_CC, "rz", &stmt, &column) == FAILURE) { return; @@ -3125,7 +3145,7 @@ if(Z_TYPE_P(column) == IS_STRING) { col_num = _php_db2_get_column_by_name(stmt_res, Z_STRVAL_P(column), -1); } else { - col_num = Z_LVAL_P(column); + col_num = (SQLSMALLINT)Z_LVAL_P(column); } /* get column header info*/ @@ -3172,7 +3192,7 @@ case SQL_SMALLINT: case SQL_INTEGER: - rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_LONG, &long_val, sizeof(long_val), &out_length); + rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_LONG, (SQLPOINTER)&long_val, sizeof(long_val), &out_length); if ( rc == SQL_ERROR ) { RETURN_FALSE; } @@ -3186,7 +3206,7 @@ case SQL_REAL: case SQL_FLOAT: case SQL_DOUBLE: - rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_DOUBLE, &double_val, sizeof(double_val), &out_length); + rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_DOUBLE, (SQLPOINTER)&double_val, sizeof(double_val), &out_length); if ( rc == SQL_ERROR ) { RETURN_FALSE; } @@ -3256,6 +3276,27 @@ break; } break; + + case SQL_XML: + rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_BINARY, NULL, 0, (SQLINTEGER *)&in_length); + if ( rc == SQL_ERROR ) { + RETURN_FALSE; + } + if (in_length == SQL_NULL_DATA) { + RETURN_NULL(); + } + out_ptr = (SQLPOINTER)ecalloc(1, in_length); + if ( out_ptr == NULL ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Allocate Memory for XML Data"); + RETURN_FALSE; + } + rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_BINARY, out_ptr, in_length, &out_length); + if (rc == SQL_ERROR) { + RETURN_FALSE; + } + RETVAL_STRINGL((char*)out_ptr,out_length, 0); + break; + default: break; } @@ -3484,6 +3525,42 @@ } break; + case SQL_XML: + out_ptr = NULL; + rc = _php_db2_get_data(stmt_res, i+1, SQL_C_BINARY, NULL, 0, (SQLINTEGER *)&tmp_length); + if ( rc == SQL_ERROR ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Determine XML Size"); + RETURN_FALSE; + } + + if (tmp_length == SQL_NULL_DATA) { + if ( op & DB2_FETCH_ASSOC ) { + add_assoc_null(return_value, (char *)stmt_res->column_info[i].name); + } + if ( op & DB2_FETCH_INDEX ) { + add_index_null(return_value, i); + } + } else { + out_ptr = (SQLPOINTER)ecalloc(1, tmp_length); + + if ( out_ptr == NULL ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Allocate Memory for XML Data"); + RETURN_FALSE; + } + rc = _php_db2_get_data(stmt_res, i+1, SQL_C_BINARY, out_ptr, tmp_length, &out_length); + if (rc == SQL_ERROR) { + RETURN_FALSE; + } + + if ( op & DB2_FETCH_ASSOC ) { + add_assoc_stringl(return_value, (char *)stmt_res->column_info[i].name, (char *)out_ptr, out_length, 0); + } + if ( op & DB2_FETCH_INDEX ) { + add_index_stringl(return_value, i, (char *)out_ptr, out_length, DB2_FETCH_BOTH & op); + } + } + break; + case SQL_CLOB: out_ptr = NULL; rc = _php_db2_get_data(stmt_res, i+1, SQL_C_CHAR, NULL, 0, (SQLINTEGER *)&tmp_length); @@ -3520,7 +3597,6 @@ } } break; - default: break; } http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/php_ibm_db2.h?r1=1.16&r2=1.17&diff_format=u Index: pecl/ibm_db2/php_ibm_db2.h diff -u pecl/ibm_db2/php_ibm_db2.h:1.16 pecl/ibm_db2/php_ibm_db2.h:1.17 --- pecl/ibm_db2/php_ibm_db2.h:1.16 Fri Nov 25 17:44:50 2005 +++ pecl/ibm_db2/php_ibm_db2.h Thu Feb 23 16:38:35 2006 @@ -19,7 +19,7 @@ | Dan Scott, Helmut Tessarek | +----------------------------------------------------------------------+ - $Id: php_ibm_db2.h,v 1.16 2005/11/25 17:44:50 dbs Exp $ + $Id: php_ibm_db2.h,v 1.17 2006/02/23 16:38:35 kfbombar Exp $ */ #ifndef PHP_IBM_DB2_H @@ -33,6 +33,11 @@ #include <stdlib.h> #include <sqlcli1.h> +/* needed for backward compatibility (SQL_XML not defined prior to DB2 v9) */ +#ifndef SQL_XML +#define SQL_XML -500 +#endif + #ifdef PHP_WIN32 #define PHP_IBM_DB2_API __declspec(dllexport) #else @@ -53,6 +58,15 @@ /* DB2 instance environment variable */ #define DB2_VAR_INSTANCE "DB2INSTANCE=" +/* Visual name for the connection */ +#define DB2_CONN_NAME "DB2 Connection" + +/* Visual name for the persistent connection */ +#define DB2_PCONN_NAME "DB2 Persistent Connection" + +/* Visual name for the statement */ +#define DB2_STMT_NAME "DB2 Statement" + /******** Makes code compatible with the options used by the user */ #define DB2_BINARY 1 #define DB2_CONVERT 2 @@ -144,7 +158,7 @@ and END macros here: */ ZEND_BEGIN_MODULE_GLOBALS(ibm_db2) - int bin_mode; + long bin_mode; char __php_conn_err_msg[DB2_MAX_ERR_MSG_LEN]; char __php_conn_err_state[SQL_SQLSTATE_SIZE + 1]; char __php_stmt_err_msg[DB2_MAX_ERR_MSG_LEN];
http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/CREDITS?r1=1.3&r2=1.4&diff_format=u Index: pecl/ibm_db2/CREDITS diff -u pecl/ibm_db2/CREDITS:1.3 pecl/ibm_db2/CREDITS:1.4 --- pecl/ibm_db2/CREDITS:1.3 Wed Aug 31 00:15:56 2005 +++ pecl/ibm_db2/CREDITS Thu Feb 23 16:38:35 2006 @@ -1,2 +1,2 @@ IBM_DB2 -Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, Dan Scott, Helmut Tessarek, Edin Kadribasic +Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, Dan Scott, Helmut Tessarek, Edin Kadribasic, Kellen Bombardier http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/package.xml?r1=1.10&r2=1.11&diff_format=u Index: pecl/ibm_db2/package.xml diff -u pecl/ibm_db2/package.xml:1.10 pecl/ibm_db2/package.xml:1.11 --- pecl/ibm_db2/package.xml:1.10 Thu Feb 23 16:20:12 2006 +++ pecl/ibm_db2/package.xml Thu Feb 23 16:38:35 2006 @@ -18,7 +18,7 @@ <release> <version>1.2.0</version> - <date>2006-01-26</date> + <date>2006-02-23</date> <license>Apache License 2.0</license> <state>beta</state> <notes> @@ -29,6 +29,7 @@ Handle null characters within SQL values (bug 6572). Avoid appending a null character to CLOB values (bug 6755). Enable default cursor type to be set as a connection attribute. + Provide initial support for native XML data type. </notes> <configureoptions> <configureoption name="with-IBM_DB2" prompt="DB2 Installation Directory?" /> @@ -56,6 +57,8 @@ <file name="test_003.phpt" role="test" /> <file name="test_004.phpt" role="test" /> <file name="test_005.phpt" role="test" /> + <file name="test_006.phpt" role="test" /> + <file name="test_007.phpt" role="test" /> <file name="test_010.phpt" role="test" /> <file name="test_011.phpt" role="test" /> <file name="test_012.phpt" role="test" /> @@ -81,6 +84,7 @@ <file name="test_041.phpt" role="test" /> <file name="test_042.phpt" role="test" /> <file name="test_043.phpt" role="test" /> + <file name="test_044.phpt" role="test" /> <file name="test_045.phpt" role="test" /> <file name="test_046.phpt" role="test" /> <file name="test_047.phpt" role="test" /> @@ -95,6 +99,7 @@ <file name="test_063.phpt" role="test" /> <file name="test_064.phpt" role="test" /> <file name="test_065.phpt" role="test" /> + <file name="test_066.phpt" role="test" /> <file name="test_070.phpt" role="test" /> <file name="test_071.phpt" role="test" /> <file name="test_080.phpt" role="test" /> @@ -146,6 +151,8 @@ <file name="test_190.phpt" role="test" /> <file name="test_191.phpt" role="test" /> <file name="test_192.phpt" role="test" /> + <file name="test_193.phpt" role="test" /> + <file name="test_194.phpt" role="test" /> <file name="test_200.phpt" role="test" /> <file name="test_201.phpt" role="test" /> <file name="test_210.phpt" role="test" /> @@ -168,6 +175,7 @@ <file name="test_6561.phpt" role="test" /> <file name="test_6572.phpt" role="test" /> <file name="test_6755.phpt" role="test" /> + <file name="test_6792.phpt" role="test" /> </dir> </filelist> </release> http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/ibm_db2.c?r1=1.43&r2=1.44&diff_format=u Index: pecl/ibm_db2/ibm_db2.c diff -u pecl/ibm_db2/ibm_db2.c:1.43 pecl/ibm_db2/ibm_db2.c:1.44 --- pecl/ibm_db2/ibm_db2.c:1.43 Thu Feb 16 17:45:11 2006 +++ pecl/ibm_db2/ibm_db2.c Thu Feb 23 16:38:35 2006 @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | (C) Copyright IBM Corporation 2005,2006 | + | (C) Copyright IBM Corporation 2006. | +----------------------------------------------------------------------+ | | | Licensed under the Apache License, Version 2.0 (the "License"); you | @@ -15,10 +15,10 @@ | permissions and limitations under the License. | +----------------------------------------------------------------------+ | Authors: Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, | - | Dan Scott, Helmut Tessarek | + | Dan Scott, Helmut Tessarek, Kellen Bombardier | +----------------------------------------------------------------------+ - $Id: ibm_db2.c,v 1.43 2006/02/16 17:45:11 tessus Exp $ + $Id: ibm_db2.c,v 1.44 2006/02/23 16:38:35 kfbombar Exp $ */ #define MODULE_RELEASE "1.2.0" @@ -59,6 +59,8 @@ SQLSMALLINT scale; /* Decimal scale */ SQLUINTEGER file_options; /* File options if DB2_PARAM_FILE */ SQLINTEGER bind_indicator; /* indicator variable for SQLBindParameter */ + SQLINTEGER long_value; /* Value if this is an SQL_C_LONG type */ + SQLSMALLINT short_strlen; /* Length of string if this is an SQL_C_STRING type */ int param_num; /* param number in stmt */ int param_type; /* Type of param - INP/OUT/INP-OUT/FILE */ char *varname; /* bound variable name */ @@ -302,6 +304,7 @@ case SQL_BIGINT: case SQL_DECIMAL: case SQL_NUMERIC: + case SQL_XML: if ( handle->row_data[i].data.str_val != NULL ) { efree(handle->row_data[i].data.str_val); handle->row_data[i].data.str_val = NULL; @@ -405,6 +408,7 @@ /* This is how CLI defines SQL_C_LONG */ REGISTER_LONG_CONSTANT("DB2_LONG", SQL_INTEGER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DB2_CHAR", SQL_CHAR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DB2_XML", SQL_XML, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DB2_CASE_NATURAL", 0, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("DB2_CASE_LOWER", 1, CONST_CS | CONST_PERSISTENT); @@ -430,9 +434,9 @@ putenv("DB2NOEXITLIST=TRUE"); #endif - le_conn_struct = zend_register_list_destructors_ex( _php_db2_free_conn_struct, NULL, "conn struct", module_number); - le_pconn_struct = zend_register_list_destructors_ex(NULL, _php_db2_free_pconn_struct, "pconn struct", module_number); - le_stmt_struct = zend_register_list_destructors_ex( _php_db2_free_stmt_struct, NULL, "stmt struct", module_number); + le_conn_struct = zend_register_list_destructors_ex( _php_db2_free_conn_struct, NULL, DB2_CONN_NAME, module_number); + le_pconn_struct = zend_register_list_destructors_ex(NULL, _php_db2_free_pconn_struct, DB2_PCONN_NAME, module_number); + le_stmt_struct = zend_register_list_destructors_ex( _php_db2_free_stmt_struct, NULL, DB2_STMT_NAME, module_number); return SUCCESS; } /* }}} */ @@ -856,6 +860,15 @@ } break; + case SQL_XML: + in_length = stmt_res->column_info[i].size+1; + row_data->str_val = (SQLCHAR *)ecalloc(1, in_length); + + rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1), + SQL_C_BINARY, row_data->str_val, in_length, + (SQLINTEGER *)(&stmt_res->row_data[i].out_length)); + break; + case SQL_TYPE_DATE: case SQL_TYPE_TIME: case SQL_TYPE_TIMESTAMP: @@ -2038,9 +2051,9 @@ } /* }}} */ -/* {{{ static param_node* build_list( stmt_res, param_no, data_type, precision, scale, nullable ) +/* {{{ static param_node* _php_db2_build_list( stmt_res, param_no, data_type, precision, scale, nullable ) */ -static param_node* build_list( stmt_handle *stmt_res, int param_no, SQLSMALLINT data_type, SQLUINTEGER precision, SQLSMALLINT scale, SQLSMALLINT nullable ) +static param_node* _php_db2_build_list( stmt_handle *stmt_res, int param_no, SQLSMALLINT data_type, SQLUINTEGER precision, SQLSMALLINT scale, SQLSMALLINT nullable ) { param_node *tmp_curr = NULL, *curr = stmt_res->head_cache_list, *prev = NULL; @@ -2054,6 +2067,7 @@ tmp_curr->param_num = param_no; tmp_curr->file_options = SQL_FILE_READ; tmp_curr->param_type = DB2_PARAM_IN; + tmp_curr->long_value = 0; MAKE_STD_ZVAL(tmp_curr->value); while ( curr != NULL ) { @@ -2101,26 +2115,22 @@ curr->bind_indicator = 0; /* Bind file name string */ + curr->short_strlen = (SQLSMALLINT) ((curr->value)->value.str.len); rc = SQLBindFileToParam((SQLHSTMT)stmt_res->hstmt, curr->param_num, curr->data_type, (SQLCHAR *)((curr->value)->value.str.val), - (SQLSMALLINT *)&((curr->value)->value.str.len), &(curr->file_options), + (SQLSMALLINT *)&curr->short_strlen, &(curr->file_options), Z_STRLEN_P(curr->value), &(curr->bind_indicator)); return rc; } switch(Z_TYPE_PP(bind_data)) { + case IS_BOOL: case IS_LONG: + curr->long_value = (SQLINTEGER)(curr->value)->value.lval; rc = SQLBindParameter(stmt_res->hstmt, curr->param_num, curr->param_type, SQL_C_LONG, curr->data_type, - curr->param_size, curr->scale, &((curr->value)->value.lval), 0, NULL); - break; - - /* Convert BOOLEAN types to LONG for DB2 / Cloudscape */ - case IS_BOOL: - rc = SQLBindParameter(stmt_res->hstmt, curr->param_num, - curr->param_type, SQL_C_LONG, curr->data_type, curr->param_size, - curr->scale, &((curr->value)->value.lval), 0, NULL); + curr->param_size, curr->scale, &curr->long_value, 0, NULL); break; case IS_DOUBLE: @@ -2147,6 +2157,7 @@ case SQL_BINARY: case SQL_LONGVARBINARY: case SQL_VARBINARY: + case SQL_XML: /* account for bin_mode settings as well */ curr->bind_indicator = (curr->value)->value.str.len; valueType = SQL_C_BINARY; @@ -2241,7 +2252,7 @@ return rc; } - curr = build_list( stmt_res, param_no, data_type, precision, scale, nullable ); + curr = _php_db2_build_list( stmt_res, param_no, data_type, precision, scale, nullable ); rc = _php_db2_bind_data( stmt_res, curr, data); if ( rc == SQL_ERROR ) { @@ -2300,165 +2311,171 @@ /* Execute */ /* Return values back to symbol table for OUT params */ - if (stmt) { + if (!stmt) { + return; + } - ZEND_FETCH_RESOURCE(stmt_res, stmt_handle*, &stmt, stmt_id, "Statement Resource", le_stmt_struct); + ZEND_FETCH_RESOURCE(stmt_res, stmt_handle*, &stmt, stmt_id, "Statement Resource", le_stmt_struct); - /* Free any cursors that might have been allocated in a previous call to SQLExecute */ - SQLFreeStmt((SQLHSTMT)stmt_res->hstmt, SQL_CLOSE); + /* Free any cursors that might have been allocated in a previous call to SQLExecute */ + SQLFreeStmt((SQLHSTMT)stmt_res->hstmt, SQL_CLOSE); - /* This ensures that each call to db2_execute start from scratch */ - stmt_res->current_node = stmt_res->head_cache_list; + /* This ensures that each call to db2_execute start from scratch */ + stmt_res->current_node = stmt_res->head_cache_list; - rc = SQLNumParams((SQLHSTMT)stmt_res->hstmt, (SQLSMALLINT*)&num); + rc = SQLNumParams((SQLHSTMT)stmt_res->hstmt, (SQLSMALLINT*)&num); + + if ( num != 0 ) { + /* Parameter Handling */ + if ( parameters_array != NULL ) { + /* Make sure db2_bind_param has been called */ + /* If the param list is NULL -- ERROR */ + if ( stmt_res->head_cache_list == NULL ) { + bind_params = 1; + } + + numOpts = zend_hash_num_elements(Z_ARRVAL_P(parameters_array)); + if (numOpts > num) { + /* More are passed in -- Warning - Use the max number present */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param count incorrect"); + numOpts = stmt_res->num_params; + } else if (numOpts < num) { + /* If there are less params passed in, than are present -- Error */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param count incorrect"); + RETURN_FALSE; + } - if ( num != 0 ) { - /* Parameter Handling */ - if ( parameters_array != NULL ) { - /* Make sure db2_bind_param has been called */ - /* If the param list is NULL -- ERROR */ - if ( stmt_res->head_cache_list == NULL ) { - bind_params = 1; - } + zend_hash_internal_pointer_reset(Z_ARRVAL_P(parameters_array)); + for ( i = 0; i < numOpts; i++) { + /* Bind values from the parameters_array to params */ + zend_hash_get_current_data(Z_ARRVAL_P(parameters_array), (void**)&data); - numOpts = zend_hash_num_elements(Z_ARRVAL_P(parameters_array)); - if (numOpts > num) { - /* More are passed in -- Warning - Use the max number present */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param count incorrect"); - numOpts = stmt_res->num_params; - } else if (numOpts < num) { - /* If there are less params passed in, than are present -- Error */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Param count incorrect"); + /* + The 0 denotes that you work only with the current node. + The 4th argument specifies whether the data passed in + has been described. So we need to call SQLDescribeParam + before binding depending on this. + */ + rc = _php_db2_execute_helper(stmt_res, data, 0, bind_params TSRMLS_CC); + if ( rc == SQL_ERROR) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binding Error"); RETURN_FALSE; } - zend_hash_internal_pointer_reset(Z_ARRVAL_P(parameters_array)); - for ( i = 0; i < numOpts; i++) { - /* Bind values from the parameters_array to params */ - zend_hash_get_current_data(Z_ARRVAL_P(parameters_array), (void**)&data); - - /* - The 0 denotes that you work only with the current node. - The 4th argument specifies whether the data passed in - has been described. So we need to call SQLDescribeParam - before binding depending on this. - */ - rc = _php_db2_execute_helper(stmt_res, data, 0, bind_params TSRMLS_CC); - if ( rc == SQL_ERROR) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binding Error"); - RETURN_FALSE; - } + /* Move array ptr forward */ + zend_hash_move_forward(Z_ARRVAL_P(parameters_array)); + } + } else { + /* No additional params passed in. Use values already bound. */ + if ( num > stmt_res->num_params ) { + /* More parameters than we expected */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "More parameters bound than present"); + } else if ( num < stmt_res->num_params ) { + /* Fewer parameters than we expected */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Less parameters bound than present"); + RETURN_FALSE; + } - /* Move array ptr forward */ - zend_hash_move_forward(Z_ARRVAL_P(parameters_array)); - } + /* Param cache node list is empty -- No params bound */ + if ( stmt_res->head_cache_list == NULL ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameters not bound"); + RETURN_FALSE; } else { - /* No additional params passed in. Use values already bound. */ - if ( num > stmt_res->num_params ) { - /* More parameters than we expected */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "More parameters bound than present"); - } else if ( num < stmt_res->num_params ) { - /* Fewer parameters than we expected */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Less parameters bound than present"); + /* The 1 denotes that you work with the whole list */ + /* And bind sequentially */ + rc = _php_db2_execute_helper(stmt_res, NULL, 1, 0 TSRMLS_CC); + if ( rc == SQL_ERROR ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binding Error 3"); RETURN_FALSE; } - - /* Param cache node list is empty -- No params bound */ - if ( stmt_res->head_cache_list == NULL ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameters not bound"); - RETURN_FALSE; - } else { - /* The 1 denotes that you work with the whole list */ - /* And bind sequentially */ - rc = _php_db2_execute_helper(stmt_res, NULL, 1, 0 TSRMLS_CC); - if ( rc == SQL_ERROR ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binding Error 3"); - RETURN_FALSE; - } - } - } - } else { - /* No Parameters */ - /* We just execute the statement. No additional work needed. */ - rc = SQLExecute((SQLHSTMT)stmt_res->hstmt); - if ( rc == SQL_ERROR ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed"); - RETURN_FALSE; } - RETURN_TRUE; } - - /* Execute Stmt -- All parameters bound */ + } else { + /* No Parameters */ + /* We just execute the statement. No additional work needed. */ rc = SQLExecute((SQLHSTMT)stmt_res->hstmt); if ( rc == SQL_ERROR ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed"); - RETVAL_FALSE; + RETURN_FALSE; } + RETURN_TRUE; + } - if ( rc == SQL_NEED_DATA ) { - while ( (SQLParamData((SQLHSTMT)stmt_res->hstmt, (SQLPOINTER *)&valuePtr)) == SQL_NEED_DATA ) { - /* passing data value for a parameter */ - rc = SQLPutData((SQLHSTMT)stmt_res->hstmt, (SQLPOINTER)(((zvalue_value*)valuePtr)->str.val), ((zvalue_value*)valuePtr)->str.len); - if ( rc == SQL_ERROR ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sending data failed"); - RETVAL_FALSE; - } + /* Execute Stmt -- All parameters bound */ + rc = SQLExecute((SQLHSTMT)stmt_res->hstmt); + if ( rc == SQL_ERROR ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed"); + RETVAL_FALSE; + } + + if ( rc == SQL_NEED_DATA ) { + while ( (SQLParamData((SQLHSTMT)stmt_res->hstmt, (SQLPOINTER *)&valuePtr)) == SQL_NEED_DATA ) { + /* passing data value for a parameter */ + rc = SQLPutData((SQLHSTMT)stmt_res->hstmt, (SQLPOINTER)(((zvalue_value*)valuePtr)->str.val), ((zvalue_value*)valuePtr)->str.len); + if ( rc == SQL_ERROR ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sending data failed"); + RETVAL_FALSE; } } + } - /* cleanup dynamic bindings if present */ - if ( bind_params == 1 ) { - /* Free param cache list */ - curr_ptr = stmt_res->head_cache_list; - prev_ptr = stmt_res->head_cache_list; - - while (curr_ptr != NULL) { - curr_ptr = curr_ptr->next; - - /* Free Values */ - if ( Z_TYPE_P(prev_ptr->value) == IS_STRING ) { - efree((prev_ptr->value)->value.str.val); - } + /* cleanup dynamic bindings if present */ + if ( bind_params == 1 ) { + /* Free param cache list */ + curr_ptr = stmt_res->head_cache_list; + prev_ptr = stmt_res->head_cache_list; - efree(prev_ptr->value); - efree(prev_ptr); + while (curr_ptr != NULL) { + curr_ptr = curr_ptr->next; - prev_ptr = curr_ptr; + /* Free Values */ + if ( Z_TYPE_P(prev_ptr->value) == IS_STRING ) { + efree((prev_ptr->value)->value.str.val); } - stmt_res->head_cache_list = NULL; - stmt_res->num_params = 0; - } else { - /* Bind the IN/OUT Params back into the active symbol table */ - tmp_curr = stmt_res->head_cache_list; - while (tmp_curr != NULL) { - switch(tmp_curr->param_type) { - case DB2_PARAM_OUT: - case DB2_PARAM_INOUT: - if( Z_TYPE_P( tmp_curr->value ) == IS_STRING && - (tmp_curr->bind_indicator != SQL_NULL_DATA - && tmp_curr->bind_indicator != SQL_NO_TOTAL )){ - /* - if the length of the string out parameter is returned - then correct the length of the corresponding php variable - */ - tmp_curr->value->value.str.val[tmp_curr->bind_indicator] = 0; - tmp_curr->value->value.str.len = tmp_curr->bind_indicator; - } - /* cant use zend_hash_update because the symbol need not exist. It might need to be created */ - ZEND_SET_SYMBOL(EG(active_symbol_table), tmp_curr->varname, tmp_curr->value); + efree(prev_ptr->value); + efree(prev_ptr); - default: - break; - } - tmp_curr = tmp_curr->next; - } + prev_ptr = curr_ptr; } - if ( rc != SQL_ERROR ) { - RETURN_TRUE; + stmt_res->head_cache_list = NULL; + stmt_res->num_params = 0; + } else { + /* Bind the IN/OUT Params back into the active symbol table */ + tmp_curr = stmt_res->head_cache_list; + while (tmp_curr != NULL) { + switch(tmp_curr->param_type) { + case DB2_PARAM_OUT: + case DB2_PARAM_INOUT: + if( Z_TYPE_P( tmp_curr->value ) == IS_STRING && + (tmp_curr->bind_indicator != SQL_NULL_DATA + && tmp_curr->bind_indicator != SQL_NO_TOTAL )){ + /* + if the length of the string out parameter is returned + then correct the length of the corresponding php variable + */ + tmp_curr->value->value.str.val[tmp_curr->bind_indicator] = 0; + tmp_curr->value->value.str.len = tmp_curr->bind_indicator; + } + else if (Z_TYPE_P(tmp_curr->value) == IS_LONG || + Z_TYPE_P(tmp_curr->value) == IS_BOOL) { + /* bind in the value of long_value instead */ + tmp_curr->value->value.lval = (long)tmp_curr->long_value; + } + /* cant use zend_hash_update because the symbol need not exist. It might need to be created */ + ZEND_SET_SYMBOL(EG(active_symbol_table), tmp_curr->varname, tmp_curr->value); + + default: + break; + } + tmp_curr = tmp_curr->next; } } + + if ( rc != SQL_ERROR ) { + RETURN_TRUE; + } } /* }}} */ @@ -2954,6 +2971,9 @@ case SQL_BLOB: str_val = "blob"; break; + case SQL_XML: + str_val = "xml"; + break; case SQL_TYPE_DATE: str_val = "date"; break; @@ -3088,7 +3108,7 @@ /* }}} */ /* {{{ static RETCODE _php_db2_get_data(stmt_handle *stmt_res, int col_num, short ctype, void *buff, int in_length, SQLINTEGER *out_length) */ -static RETCODE _php_db2_get_data(stmt_handle *stmt_res, int col_num, short ctype, void *buff, int in_length, SQLINTEGER *out_length) +static RETCODE _php_db2_get_data(stmt_handle *stmt_res, SQLUSMALLINT col_num, SQLSMALLINT ctype, SQLPOINTER buff, SQLLEN in_length, SQLLEN *out_length) { RETCODE rc=SQL_SUCCESS; @@ -3106,14 +3126,14 @@ zval *stmt = NULL; zval *column = NULL; stmt_handle *stmt_res; - long col_num; - RETCODE rc; - void *out_ptr; - char *out_char_ptr; + SQLSMALLINT col_num = 0; + RETCODE rc = 0; + void *out_ptr = NULL; + char *out_char_ptr = NULL; SQLINTEGER in_length, out_length=-10; /*Initialize out_length to some meaningless value*/ SQLSMALLINT column_type, lob_bind_type= SQL_C_BINARY; - double double_val; - long long_val; + SQLDOUBLE double_val = 0; + SQLINTEGER long_val = 0; if (zend_parse_parameters(argc TSRMLS_CC, "rz", &stmt, &column) == FAILURE) { return; @@ -3125,7 +3145,7 @@ if(Z_TYPE_P(column) == IS_STRING) { col_num = _php_db2_get_column_by_name(stmt_res, Z_STRVAL_P(column), -1); } else { - col_num = Z_LVAL_P(column); + col_num = (SQLSMALLINT)Z_LVAL_P(column); } /* get column header info*/ @@ -3172,7 +3192,7 @@ case SQL_SMALLINT: case SQL_INTEGER: - rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_LONG, &long_val, sizeof(long_val), &out_length); + rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_LONG, (SQLPOINTER)&long_val, sizeof(long_val), &out_length); if ( rc == SQL_ERROR ) { RETURN_FALSE; } @@ -3186,7 +3206,7 @@ case SQL_REAL: case SQL_FLOAT: case SQL_DOUBLE: - rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_DOUBLE, &double_val, sizeof(double_val), &out_length); + rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_DOUBLE, (SQLPOINTER)&double_val, sizeof(double_val), &out_length); if ( rc == SQL_ERROR ) { RETURN_FALSE; } @@ -3256,6 +3276,27 @@ break; } break; + + case SQL_XML: + rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_BINARY, NULL, 0, (SQLINTEGER *)&in_length); + if ( rc == SQL_ERROR ) { + RETURN_FALSE; + } + if (in_length == SQL_NULL_DATA) { + RETURN_NULL(); + } + out_ptr = (SQLPOINTER)ecalloc(1, in_length); + if ( out_ptr == NULL ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Allocate Memory for XML Data"); + RETURN_FALSE; + } + rc = _php_db2_get_data(stmt_res, col_num+1, SQL_C_BINARY, out_ptr, in_length, &out_length); + if (rc == SQL_ERROR) { + RETURN_FALSE; + } + RETVAL_STRINGL((char*)out_ptr,out_length, 0); + break; + default: break; } @@ -3484,6 +3525,42 @@ } break; + case SQL_XML: + out_ptr = NULL; + rc = _php_db2_get_data(stmt_res, i+1, SQL_C_BINARY, NULL, 0, (SQLINTEGER *)&tmp_length); + if ( rc == SQL_ERROR ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Determine XML Size"); + RETURN_FALSE; + } + + if (tmp_length == SQL_NULL_DATA) { + if ( op & DB2_FETCH_ASSOC ) { + add_assoc_null(return_value, (char *)stmt_res->column_info[i].name); + } + if ( op & DB2_FETCH_INDEX ) { + add_index_null(return_value, i); + } + } else { + out_ptr = (SQLPOINTER)ecalloc(1, tmp_length); + + if ( out_ptr == NULL ) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Allocate Memory for XML Data"); + RETURN_FALSE; + } + rc = _php_db2_get_data(stmt_res, i+1, SQL_C_BINARY, out_ptr, tmp_length, &out_length); + if (rc == SQL_ERROR) { + RETURN_FALSE; + } + + if ( op & DB2_FETCH_ASSOC ) { + add_assoc_stringl(return_value, (char *)stmt_res->column_info[i].name, (char *)out_ptr, out_length, 0); + } + if ( op & DB2_FETCH_INDEX ) { + add_index_stringl(return_value, i, (char *)out_ptr, out_length, DB2_FETCH_BOTH & op); + } + } + break; + case SQL_CLOB: out_ptr = NULL; rc = _php_db2_get_data(stmt_res, i+1, SQL_C_CHAR, NULL, 0, (SQLINTEGER *)&tmp_length); @@ -3520,7 +3597,6 @@ } } break; - default: break; } http://cvs.php.net/viewcvs.cgi/pecl/ibm_db2/php_ibm_db2.h?r1=1.16&r2=1.17&diff_format=u Index: pecl/ibm_db2/php_ibm_db2.h diff -u pecl/ibm_db2/php_ibm_db2.h:1.16 pecl/ibm_db2/php_ibm_db2.h:1.17 --- pecl/ibm_db2/php_ibm_db2.h:1.16 Fri Nov 25 17:44:50 2005 +++ pecl/ibm_db2/php_ibm_db2.h Thu Feb 23 16:38:35 2006 @@ -19,7 +19,7 @@ | Dan Scott, Helmut Tessarek | +----------------------------------------------------------------------+ - $Id: php_ibm_db2.h,v 1.16 2005/11/25 17:44:50 dbs Exp $ + $Id: php_ibm_db2.h,v 1.17 2006/02/23 16:38:35 kfbombar Exp $ */ #ifndef PHP_IBM_DB2_H @@ -33,6 +33,11 @@ #include <stdlib.h> #include <sqlcli1.h> +/* needed for backward compatibility (SQL_XML not defined prior to DB2 v9) */ +#ifndef SQL_XML +#define SQL_XML -500 +#endif + #ifdef PHP_WIN32 #define PHP_IBM_DB2_API __declspec(dllexport) #else @@ -53,6 +58,15 @@ /* DB2 instance environment variable */ #define DB2_VAR_INSTANCE "DB2INSTANCE=" +/* Visual name for the connection */ +#define DB2_CONN_NAME "DB2 Connection" + +/* Visual name for the persistent connection */ +#define DB2_PCONN_NAME "DB2 Persistent Connection" + +/* Visual name for the statement */ +#define DB2_STMT_NAME "DB2 Statement" + /******** Makes code compatible with the options used by the user */ #define DB2_BINARY 1 #define DB2_CONVERT 2 @@ -144,7 +158,7 @@ and END macros here: */ ZEND_BEGIN_MODULE_GLOBALS(ibm_db2) - int bin_mode; + long bin_mode; char __php_conn_err_msg[DB2_MAX_ERR_MSG_LEN]; char __php_conn_err_state[SQL_SQLSTATE_SIZE + 1]; char __php_stmt_err_msg[DB2_MAX_ERR_MSG_LEN];