Skip to content

Commit dc98f2f

Browse files
author
Rahul Priyadarshi
committed
Fixed: Garbage value for VARCHAR type OUT variable of stored-procedure
1 parent ae808ba commit dc98f2f

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

ibm_db2.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ typedef struct _conn_handle_struct {
108108
long c_case_mode;
109109
long c_cursor_type;
110110
#ifdef PASE /* i5 override php.ini */
111+
long c_i5_allow_commit;
111112
long c_i5_dbcs_alloc;
112113
long c_i5_sys_naming;
113114
char * c_i5_pending_cmd;
@@ -184,7 +185,7 @@ typedef struct _stmt_handle_struct {
184185

185186
/* {{{ Every user visible function must have an entry in ibm_db2_functions[].
186187
*/
187-
function_entry ibm_db2_functions[] = {
188+
zend_function_entry ibm_db2_functions[] = {
188189
PHP_FE(db2_connect, NULL)
189190
PHP_FE(db2_commit, NULL)
190191
PHP_FE(db2_pconnect, NULL)
@@ -1561,7 +1562,6 @@ static void _php_db2_assign_options( void *handle, int type, char *opt_key, zval
15611562
php_error_docref(NULL TSRMLS_CC, E_WARNING, "i5_fetch_only (DB2_I5_FETCH_ON, DB2_I5_FETCH_OFF)");
15621563
}
15631564
#endif /* PASE */
1564-
#ifndef PASE /* i5/OS not support yet */
15651565
} else if (!STRCASECMP(opt_key, "userid")) {
15661566
rc = SQLSetConnectAttr((SQLHDBC)((conn_handle*)handle)->hdbc, SQL_ATTR_INFO_USERID, (SQLPOINTER)option_str, SQL_NTS);
15671567
if ( rc == SQL_ERROR ) {
@@ -1582,6 +1582,7 @@ static void _php_db2_assign_options( void *handle, int type, char *opt_key, zval
15821582
if ( rc == SQL_ERROR ) {
15831583
_php_db2_check_sql_errors((SQLHSTMT)((conn_handle*)handle)->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1 TSRMLS_CC);
15841584
}
1585+
#ifndef PASE /* i5/OS not support yet */
15851586
} else if (!STRCASECMP(opt_key, "deferred_prepare")) {
15861587
switch (option_num) {
15871588
case DB2_DEFERRED_PREPARE_ON:
@@ -1979,8 +1980,10 @@ static void _php_db2_clear_stmt_err_cache(TSRMLS_D)
19791980
*/
19801981
static void _php_db2_clear_exec_many_err_cache( stmt_handle *stmt )
19811982
{
1982-
efree(stmt->exec_many_err_msg);
1983-
stmt->exec_many_err_msg = NULL;
1983+
if ( stmt->exec_many_err_msg != NULL ) {
1984+
efree(stmt->exec_many_err_msg);
1985+
stmt->exec_many_err_msg = NULL;
1986+
}
19841987
}
19851988
/* }}} */
19861989

@@ -2002,7 +2005,7 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
20022005
int reused = 0;
20032006
int hKeyLen = 0;
20042007
char *hKey = NULL;
2005-
list_entry newEntry;
2008+
zend_rsrc_list_entry newEntry;
20062009
char server[2048];
20072010
#ifdef PASE /* i5/OS incompatible v6 change */
20082011
long attr = SQL_TRUE;
@@ -2040,7 +2043,7 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
20402043
do {
20412044
/* Check if we already have a connection for this userID & database combination */
20422045
if (isPersistent) {
2043-
list_entry *entry;
2046+
zend_rsrc_list_entry *entry;
20442047
hKeyLen = strlen(database) + strlen(uid) + strlen(password) + 9;
20452048
hKey = (char *) ecalloc(1, hKeyLen);
20462049

@@ -2231,7 +2234,7 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
22312234
memset(&newEntry, 0, sizeof(newEntry));
22322235
Z_TYPE(newEntry) = le_pconn_struct;
22332236
newEntry.ptr = conn_res;
2234-
if (zend_hash_update(&EG(persistent_list), hKey, hKeyLen, (void *) &newEntry, sizeof(list_entry), NULL)==FAILURE) {
2237+
if (zend_hash_update(&EG(persistent_list), hKey, hKeyLen, (void *) &newEntry, sizeof(zend_rsrc_list_entry), NULL)==FAILURE) {
22352238
rc = SQL_ERROR;
22362239
/* TBD: What error to return?, for now just generic SQL_ERROR */
22372240
}
@@ -3720,7 +3723,7 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b
37203723
if (curr->param_type == DB2_PARAM_INOUT)
37213724
#endif
37223725
memset(Z_STRVAL_PP(bind_data)+origlen,0x20, curr->param_size-origlen);
3723-
if (nullterm) Z_STRVAL_PP(bind_data)[curr->param_size] = '\0';
3726+
if (nullterm) Z_STRVAL_PP(bind_data)[origlen] = '\0';
37243727
Z_STRLEN_PP(bind_data) = curr->param_size;
37253728
}
37263729
#ifdef PASE /* help out PHP script trunc trailing chars -- LUW too? */
@@ -3910,7 +3913,8 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b
39103913
#endif /* PASE */
39113914
paramValuePtr = (SQLPOINTER)((curr->value)->value.str.val);
39123915
break;
3913-
#ifdef PASE /* i5/OS should be SQL_NTS to avoid extra spaces */
3916+
/*Not only PASE this applies to LUW too*/
3917+
/*#ifdef PASE /* i5/OS should be SQL_NTS to avoid extra spaces */
39143918
case SQL_VARCHAR:
39153919
valueType = SQL_C_CHAR;
39163920
curr->bind_indicator = SQL_NTS;
@@ -3921,7 +3925,7 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b
39213925
curr->bind_indicator = SQL_NTS; /* 20 */
39223926
paramValuePtr = (SQLPOINTER)((curr->value)->value.str.val);
39233927
break;
3924-
#endif /* PASE */
3928+
/*#endif /* PASE */
39253929
/* This option should handle most other types such as DATE, VARCHAR etc */
39263930
default:
39273931
valueType = SQL_C_CHAR;
@@ -4310,6 +4314,13 @@ PHP_FUNCTION(db2_execute)
43104314
Z_STRLEN_P(tmp_curr->value) = strlen(Z_STRVAL_P(tmp_curr->value));
43114315

43124316
}
4317+
else if (Z_TYPE_P( tmp_curr->value ) == IS_STRING
4318+
&& tmp_curr->bind_indicator == SQL_NULL_DATA) {
4319+
if((tmp_curr->value)->value.str.val != NULL || (tmp_curr->value)->value.str.len != 0) {
4320+
efree((tmp_curr->value)->value.str.val);
4321+
}
4322+
Z_TYPE_P(tmp_curr->value) = IS_NULL;
4323+
}
43134324
else if (Z_TYPE_P(tmp_curr->value) == IS_LONG || Z_TYPE_P(tmp_curr->value) == IS_BOOL) {
43144325
/* bind in the value of long_value instead */
43154326
tmp_curr->value->value.lval = (long)tmp_curr->long_value;
@@ -4489,6 +4500,15 @@ PHP_FUNCTION(db2_next_result)
44894500
_php_db2_check_sql_errors(stmt_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1 TSRMLS_CC);
44904501
RETURN_FALSE;
44914502
}
4503+
#ifdef PASEFORGETIT /* John Broich try SQLMoreResults (did not work though) */
4504+
rc = SQLMoreResults((SQLHSTMT)stmt_res->hstmt);
4505+
if( rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
4506+
return_value = stmt;
4507+
} else {
4508+
_php_db2_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
4509+
RETURN_FALSE;
4510+
}
4511+
#else /* LUW */
44924512
rc = SQLNextResult((SQLHSTMT)stmt_res->hstmt, (SQLHSTMT)new_hstmt);
44934513
if( rc != SQL_SUCCESS ) {
44944514
if(rc < SQL_SUCCESS) {
@@ -4518,6 +4538,7 @@ PHP_FUNCTION(db2_next_result)
45184538
new_stmt_res->hdbc = stmt_res->hdbc;
45194539

45204540
ZEND_REGISTER_RESOURCE(return_value, new_stmt_res, le_stmt_struct);
4541+
#endif /* PASE */
45214542
} else {
45224543
RETURN_FALSE;
45234544
}
@@ -6758,6 +6779,9 @@ PHP_FUNCTION(db2_last_insert_id)
67586779
/* {{{ static int _ibm_db_chaining_flag(stmt_handle *stmt_res, SQLINTEGER flag, error_msg_node *error_list, int client_err_cnt TSRMLS_DC)
67596780
*/
67606781
static int _ibm_db_chaining_flag( stmt_handle *stmt_res, SQLINTEGER flag, error_msg_node *error_list, int client_err_cnt TSRMLS_DC ) {
6782+
#ifdef PASE /* i5/OS unsupported */
6783+
return SQL_ERROR;
6784+
#else /* LUW */
67616785
int rc;
67626786
rc = SQLSetStmtAttr((SQLHSTMT)stmt_res->hstmt, flag, (SQLPOINTER)SQL_TRUE, SQL_IS_INTEGER);
67636787
if ( flag == SQL_ATTR_CHAINING_BEGIN ) {
@@ -6793,6 +6817,7 @@ static int _ibm_db_chaining_flag( stmt_handle *stmt_res, SQLINTEGER flag, error_
67936817
}
67946818
}
67956819
return rc;
6820+
#endif /* i5/OS unsupported */
67966821
}
67976822
/* }}} */
67986823

@@ -6821,6 +6846,9 @@ static void _build_client_err_list( error_msg_node *head_error_list, char *err_m
68216846
execute a prepared statement */
68226847
PHP_FUNCTION( db2_execute_many )
68236848
{
6849+
#ifdef PASE /* i5/OS unsupported */
6850+
RETURN_FALSE;
6851+
#else /* LUW */
68246852
int argc = ZEND_NUM_ARGS();
68256853
int stmt_id = -1;
68266854
zval *stmt = NULL;
@@ -6983,6 +7011,7 @@ PHP_FUNCTION( db2_execute_many )
69837011
RETURN_FALSE;
69847012
}
69857013
RETURN_LONG(row_cnt);
7014+
#endif /* i5/OS unsupported */
69867015
}
69877016
/* }}} */
69887017

0 commit comments

Comments
 (0)