Skip to content

Commit a24fa9b

Browse files
committed
Added support for PHP 7.2
1 parent 28e478d commit a24fa9b

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

ibm_db2.c

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ typedef struct _conn_handle_struct {
239239
#ifdef PASE /* IBM i overrides php.ini */
240240
long c_i5_dbcs_alloc; /* orig - IBM i 6x space for CCSID<>UTF-8 convert (DBCS customer issue) */
241241
long c_i5_max_pconnect; /* 1.9.7 - IBM i count max usage connection recycle (customer issue months live connection) */
242+
long c_i5_executing; /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
242243
#endif /* PASE */
243244
/* 1.9.7 - IBM i + LUW 10.5 system naming on (*libl)/file.mbr */
244245
long c_i5_sys_naming; /* 1.9.7 - IBM i + LUW DB2 Connect 10.5 system naming (customer *LIBL issues) */
@@ -284,8 +285,8 @@ typedef struct _stmt_handle_struct {
284285
long cursor_type;
285286
long s_case_mode;
286287
long s_rowcount;
287-
#ifdef PASE /* IBM i override php.ini */
288-
long s_i5_dbcs_alloc;
288+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
289+
conn_handle * s_i5_conn_parent;
289290
#endif /* PASE */
290291
SQLSMALLINT error_recno_tracker;
291292
SQLSMALLINT errormsg_recno_tracker;
@@ -829,8 +830,8 @@ static stmt_handle *_db2_new_stmt_struct(conn_handle* conn_res)
829830
stmt_res->cursor_type = conn_res->c_cursor_type;
830831
stmt_res->s_case_mode = conn_res->c_case_mode;
831832

832-
#ifdef PASE /* IBM i allow 6x DBCS convert php.ini */
833-
stmt_res->s_i5_dbcs_alloc = conn_res->c_i5_dbcs_alloc;
833+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
834+
stmt_res->s_i5_conn_parent = conn_res;
834835
#endif /* PASE */
835836

836837
stmt_res->expansion_factor = conn_res->expansion_factor;
@@ -2172,7 +2173,7 @@ static int _php_db2_get_result_set_info(stmt_handle *stmt_res TSRMLS_DC)
21722173
break;
21732174
}
21742175
#ifdef PASE /* i5/OS DBCS may have up to 6 times growth in column alloc size on convert */
2175-
if (stmt_res->s_i5_dbcs_alloc > 0) {
2176+
if (stmt_res->s_i5_conn_parent->c_i5_dbcs_alloc > 0) {
21762177
switch (stmt_res->column_info[i].type) {
21772178
case SQL_CHAR:
21782179
case SQL_VARCHAR:
@@ -2579,6 +2580,11 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
25792580
reused = 1;
25802581
} /* else will re-connect since connection is dead */
25812582
#else
2583+
/* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
2584+
if (conn_res->c_i5_executing) {
2585+
conn_res->flag_pconnect = 9;
2586+
conn_res->c_i5_executing = 0;
2587+
} else {
25822588
/* 1.9.7 - IBM i remote persistent connection or long lived local (customer issue dead connection) */
25832589
/* 1.9.7 - IBM i i5/OS DB2 Maid Service (monitor QSQSRVR jobs) */
25842590
/* 1.9.7 - IBM i level 4: try conn new statement (check statement) */
@@ -2638,6 +2644,7 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
26382644
/* close sets conn_res->flag_pconnect=9 */
26392645
_php_db2_close_now(conn_res, 1 TSRMLS_CC);
26402646
}
2647+
} /* 1.9.9 executing */
26412648
reused = 1;
26422649
#endif /* PASE */
26432650
}
@@ -2708,6 +2715,7 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
27082715
}
27092716
#ifdef PASE /* 1.9.7 - IBM i count max usage connection recycle (customer issue months live connection) */
27102717
conn_res->c_i5_max_pconnect = IBM_DB2_G(i5_max_pconnect);
2718+
conn_res->c_i5_executing = 0; /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
27112719
#endif /* PASE */
27122720
}
27132721

@@ -4254,7 +4262,13 @@ static int _php_db2_execute_stmt(stmt_handle *stmt_res TSRMLS_DC)
42544262
{
42554263
int rc;
42564264

4265+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
4266+
stmt_res->s_i5_conn_parent->c_i5_executing = 1;
4267+
#endif /* PASE */
42574268
rc = SQLExecute((SQLHSTMT)stmt_res->hstmt);
4269+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
4270+
stmt_res->s_i5_conn_parent->c_i5_executing = 0;
4271+
#endif /* PASE */
42584272
if ( rc == SQL_ERROR ) {
42594273
_php_db2_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
42604274
}
@@ -4312,7 +4326,13 @@ PHP_FUNCTION(db2_exec)
43124326
}
43134327
}
43144328

4329+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
4330+
stmt_res->s_i5_conn_parent->c_i5_executing = 1;
4331+
#endif /* PASE */
43154332
rc = SQLExecDirect((SQLHSTMT)stmt_res->hstmt, stmt_string , stmt_string_len);
4333+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
4334+
stmt_res->s_i5_conn_parent->c_i5_executing = 0;
4335+
#endif /* PASE */
43164336
if ( rc == SQL_ERROR ) {
43174337
_php_db2_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
43184338
}
@@ -4548,7 +4568,10 @@ static int _php_db2_bind_pad(param_node *curr, int nullterm, int isvarying, int
45484568
*/
45494569
if (IS_INTERNED(ZEND_STR(*data))) {
45504570
#if PHP_MAJOR_VERSION >= 7
4551-
Z_STR_P(*data) = zend_string_init(ZEND_Z_STRVAL_PP(data), ZEND_Z_STRLEN_PP(data), 0);
4571+
/* Need use macro assignment to avoid leak in php 7. (Thanks Dimitry)
4572+
* Z_STR_P(*data) = zend_string_init(ZEND_Z_STRVAL_PP(data), ZEND_Z_STRLEN_PP(data), 0);
4573+
*/
4574+
ZVAL_STR(*data, zend_string_init(ZEND_Z_STRVAL_PP(data), ZEND_Z_STRLEN_PP(data), 0));
45524575
#else
45534576
ZEND_Z_STRVAL_PP(data) = estrndup(ZEND_Z_STRVAL_PP(data), ZEND_Z_STRLEN_PP(data));
45544577
#endif
@@ -4557,7 +4580,10 @@ static int _php_db2_bind_pad(param_node *curr, int nullterm, int isvarying, int
45574580
/* make enough space for full write */
45584581
if (*poriglen < curr->param_size) {
45594582
#if PHP_MAJOR_VERSION >= 7
4560-
Z_STR_P(*data) = zend_string_extend(Z_STR_P(*data), curr->param_size + nullterm, 0);
4583+
/* Need use macro assignment in php 7 (follow pattern zend_string_init)
4584+
* Z_STR_P(*data) = zend_string_extend(Z_STR_P(*data), curr->param_size + nullterm, 0);
4585+
*/
4586+
ZVAL_STR(*data, zend_string_extend(Z_STR_P(*data), curr->param_size + nullterm, 0));
45614587
#else
45624588
ZEND_Z_STRVAL_PP(data) = erealloc(ZEND_Z_STRVAL_PP(data), curr->param_size + nullterm);
45634589
#endif
@@ -5077,7 +5103,7 @@ PHP_FUNCTION(db2_execute)
50775103
}
50785104

50795105
#if PHP_MAJOR_VERSION >= 7
5080-
if (parameters_array && Z_TYPE_P(parameters_array) == IS_ARRAY && (Z_TYPE_FLAGS_P(parameters_array) & IS_TYPE_IMMUTABLE)) {
5106+
if (parameters_array && Z_TYPE_P(parameters_array) == IS_ARRAY && (Z_TYPE_FLAGS_P(parameters_array) & (IS_TYPE_COPYABLE & !IS_TYPE_REFCOUNTED))) {
50815107
SEPARATE_ARRAY(parameters_array);
50825108
}
50835109
#endif
@@ -5180,7 +5206,13 @@ PHP_FUNCTION(db2_execute)
51805206
} else {
51815207
/* No Parameters */
51825208
/* We just execute the statement. No additional work needed. */
5209+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
5210+
stmt_res->s_i5_conn_parent->c_i5_executing = 1;
5211+
#endif /* PASE */
51835212
rc = SQLExecute((SQLHSTMT)stmt_res->hstmt);
5213+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
5214+
stmt_res->s_i5_conn_parent->c_i5_executing = 0;
5215+
#endif /* PASE */
51845216
if ( rc == SQL_ERROR ) {
51855217
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed");
51865218
_php_db2_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
@@ -5189,7 +5221,13 @@ PHP_FUNCTION(db2_execute)
51895221
RETURN_TRUE;
51905222
}
51915223
/* Execute Stmt -- All parameters bound */
5224+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
5225+
stmt_res->s_i5_conn_parent->c_i5_executing = 1;
5226+
#endif /* PASE */
51925227
rc = SQLExecute((SQLHSTMT)stmt_res->hstmt);
5228+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
5229+
stmt_res->s_i5_conn_parent->c_i5_executing = 0;
5230+
#endif /* PASE */
51935231
if ( rc == SQL_ERROR ) {
51945232
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed");
51955233
_php_db2_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
@@ -5438,8 +5476,8 @@ PHP_FUNCTION(db2_next_result)
54385476
new_stmt_res->s_bin_mode = stmt_res->s_bin_mode;
54395477
new_stmt_res->cursor_type = stmt_res->cursor_type;
54405478
new_stmt_res->s_case_mode = stmt_res->s_case_mode;
5441-
#ifdef PASE /* i5 override php.ini */
5442-
new_stmt_res->s_i5_dbcs_alloc = stmt_res->s_i5_dbcs_alloc;
5479+
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
5480+
new_stmt_res->s_i5_conn_parent = stmt_res->s_i5_conn_parent;
54435481
#endif /* PASE */
54445482
new_stmt_res->head_cache_list = NULL;
54455483
new_stmt_res->current_node = NULL;
@@ -5953,7 +5991,7 @@ static RETCODE _php_db2_get_length(stmt_handle* stmt_res, SQLUSMALLINT col_num,
59535991
}
59545992
#ifdef PASE /* i5/OS special DBCS */
59555993
if (*sLength != SQL_NULL_DATA){
5956-
if (stmt_res->s_i5_dbcs_alloc > 0) {
5994+
if (stmt_res->s_i5_conn_parent->c_i5_dbcs_alloc > 0) {
59575995
switch (stmt_res->column_info[col_num-1].type) {
59585996
case SQL_CHAR:
59595997
case SQL_VARCHAR:
@@ -7779,7 +7817,7 @@ PHP_FUNCTION( db2_execute_many )
77797817
}
77807818

77817819
#if PHP_MAJOR_VERSION >= 7
7782-
if (params && Z_TYPE_P(params) == IS_ARRAY && (Z_TYPE_FLAGS_P(params) & IS_TYPE_IMMUTABLE)) {
7820+
if (params && Z_TYPE_P(params) == IS_ARRAY && (Z_TYPE_FLAGS_P(params) & (IS_TYPE_COPYABLE & !IS_TYPE_REFCOUNTED))) {
77837821
SEPARATE_ARRAY(params);
77847822
}
77857823
#endif

php_ibm_db2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
$Id$
2424
*/
2525

26-
#define PHP_IBM_DB2_VERSION "2.0.1"
26+
#define PHP_IBM_DB2_VERSION "2.0.4"
2727

2828
#ifndef PHP_IBM_DB2_H
2929
#define PHP_IBM_DB2_H

0 commit comments

Comments
 (0)