Skip to content

Commit 8c087b0

Browse files
author
Ambrish Bhargava
committed
Fixing #14347, #16257 and problem related to GRAPHIC and VARGRAHIC Datatypes
1 parent a2aa6ca commit 8c087b0

File tree

3 files changed

+51
-37
lines changed

3 files changed

+51
-37
lines changed

ibm_db2.c

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,22 +1676,32 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
16761676
#endif
16771677
case SQL_WCHAR:
16781678
case SQL_WVARCHAR:
1679-
case SQL_GRAPHIC:
1680-
case SQL_VARGRAPHIC:
16811679
#ifndef PASE /* i5/OS SQL_DBCLOB */
16821680
case SQL_DBCLOB:
16831681
#endif /* not PASE */
16841682
#ifndef PASE /* i5/OS SQL_LONGVARCHAR is SQL_VARCHAR */
16851683
case SQL_LONGVARCHAR:
16861684
case SQL_WLONGVARCHAR:
16871685
case SQL_LONGVARGRAPHIC:
1688-
#else /* i5/OS Until i5 DB2 PTF wide spread - SQL_C_CHAR works (replace orig i5 SqlGetData scheme) */
1689-
target_type = SQL_C_CHAR;
16901686
#endif /* PASE */
1687+
target_type = SQL_C_CHAR;
16911688
in_length = stmt_res->column_info[i].size+1;
16921689
row_data->str_val = (SQLCHAR *)ecalloc(1, in_length);
16931690

1694-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1691+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
1692+
target_type, row_data->str_val, in_length,
1693+
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
1694+
if ( rc == SQL_ERROR ) {
1695+
_php_db2_check_sql_errors((SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
1696+
}
1697+
break;
1698+
case SQL_GRAPHIC:
1699+
case SQL_VARGRAPHIC:
1700+
target_type = SQL_C_CHAR;
1701+
in_length = (stmt_res->column_info[i].size + 1) * 2 + 1;
1702+
row_data->str_val = (SQLCHAR *) ecalloc (1, in_length);
1703+
1704+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT) (i + 1),
16951705
target_type, row_data->str_val, in_length,
16961706
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
16971707
if ( rc == SQL_ERROR ) {
@@ -1709,20 +1719,20 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
17091719
#endif /* PASE */
17101720
case SQL_VARBINARY:
17111721
if ( stmt_res->s_bin_mode == DB2_CONVERT ) {
1712-
in_length = 2*(stmt_res->column_info[i].size)+1;
1722+
in_length = 2 * (stmt_res->column_info[i].size) + 1;
17131723
row_data->str_val = (SQLCHAR *)ecalloc(1, in_length);
17141724

1715-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1725+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
17161726
SQL_C_CHAR, row_data->str_val, in_length,
17171727
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
17181728
if ( rc == SQL_ERROR ) {
17191729
_php_db2_check_sql_errors((SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
17201730
}
17211731
} else {
1722-
in_length = stmt_res->column_info[i].size+1;
1732+
in_length = stmt_res->column_info[i].size + 1;
17231733
row_data->str_val = (SQLCHAR *)ecalloc(1, in_length);
17241734

1725-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1735+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
17261736
SQL_C_DEFAULT, row_data->str_val, in_length,
17271737
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
17281738
if ( rc == SQL_ERROR ) {
@@ -1750,7 +1760,7 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
17501760
break;
17511761

17521762
case SQL_SMALLINT:
1753-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1763+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
17541764
SQL_C_DEFAULT, &row_data->s_val, sizeof(row_data->s_val),
17551765
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
17561766
if ( rc == SQL_ERROR ) {
@@ -1759,7 +1769,7 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
17591769
break;
17601770

17611771
case SQL_INTEGER:
1762-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1772+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
17631773
SQL_C_DEFAULT, &row_data->i_val, sizeof(row_data->i_val),
17641774
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
17651775
if ( rc == SQL_ERROR ) {
@@ -1768,15 +1778,15 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
17681778
break;
17691779

17701780
case SQL_REAL:
1771-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1781+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
17721782
SQL_C_FLOAT, &row_data->r_val, sizeof(row_data->r_val),
17731783
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
17741784
if ( rc == SQL_ERROR ) {
17751785
_php_db2_check_sql_errors((SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
17761786
}
17771787
break;
17781788
case SQL_FLOAT:
1779-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1789+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
17801790
SQL_C_DEFAULT, &row_data->f_val, sizeof(row_data->f_val),
17811791
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
17821792
if ( rc == SQL_ERROR ) {
@@ -1785,7 +1795,7 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
17851795
break;
17861796

17871797
case SQL_DOUBLE:
1788-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1798+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
17891799
SQL_C_DEFAULT, &row_data->d_val, sizeof(row_data->d_val),
17901800
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
17911801
if ( rc == SQL_ERROR ) {
@@ -1798,7 +1808,7 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
17981808
in_length = stmt_res->column_info[i].size +
17991809
stmt_res->column_info[i].scale + 2 + 1;
18001810
row_data->str_val = (SQLCHAR *)ecalloc(1, in_length);
1801-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1811+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
18021812
SQL_C_CHAR, row_data->str_val, in_length,
18031813
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
18041814
if ( rc == SQL_ERROR ) {
@@ -1810,7 +1820,7 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
18101820
stmt_res->row_data[i].out_length = 0;
18111821
stmt_res->column_info[i].loc_type = SQL_CLOB_LOCATOR;
18121822
stmt_res->column_info[i].loc_ind = 0;
1813-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1823+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
18141824
stmt_res->column_info[i].loc_type, &stmt_res->column_info[i].lob_loc, 4,
18151825
&stmt_res->column_info[i].loc_ind);
18161826
if ( rc == SQL_ERROR ) {
@@ -1821,7 +1831,7 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
18211831
stmt_res->row_data[i].out_length = 0;
18221832
stmt_res->column_info[i].loc_type = SQL_BLOB_LOCATOR;
18231833
stmt_res->column_info[i].loc_ind = 0;
1824-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1834+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
18251835
stmt_res->column_info[i].loc_type, &stmt_res->column_info[i].lob_loc, 4,
18261836
&stmt_res->column_info[i].loc_ind);
18271837
if ( rc == SQL_ERROR ) {
@@ -1833,7 +1843,7 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
18331843
stmt_res->row_data[i].out_length = 0;
18341844
stmt_res->column_info[i].loc_type = SQL_DBCLOB_LOCATOR;
18351845
stmt_res->column_info[i].loc_ind = 0;
1836-
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1846+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i + 1),
18371847
stmt_res->column_info[i].loc_type, &stmt_res->column_info[i].lob_loc, 4,
18381848
&stmt_res->column_info[i].loc_ind);
18391849
if ( rc == SQL_ERROR ) {
@@ -2492,9 +2502,9 @@ PHP_FUNCTION(db2_bind_param)
24922502
}
24932503
/* }}} */
24942504

2495-
/* {{{ static int _php_db2_close_helper( INTERNAL_FUNCTION_PARAMETERS )
2505+
/* {{{ static void _php_db2_close_helper( INTERNAL_FUNCTION_PARAMETERS )
24962506
*/
2497-
static int _php_db2_close_helper( INTERNAL_FUNCTION_PARAMETERS, int endpconnect )
2507+
static void _php_db2_close_helper( INTERNAL_FUNCTION_PARAMETERS, int endpconnect )
24982508
{
24992509
int argc = ZEND_NUM_ARGS();
25002510
int connection_id = -1;
@@ -2512,7 +2522,9 @@ static int _php_db2_close_helper( INTERNAL_FUNCTION_PARAMETERS, int endpconnect
25122522
"Connection Resource", le_conn_struct, le_pconn_struct);
25132523

25142524
#ifdef PASE /* db2_pclose - last ditch persistent close */
2515-
if (endpconnect) conn_res->flag_pconnect=0;
2525+
if (endpconnect) {
2526+
conn_res->flag_pconnect = 0;
2527+
}
25162528
#endif /* PASE */
25172529

25182530
if ( conn_res->handle_active && !conn_res->flag_pconnect ) {
@@ -2559,7 +2571,7 @@ static int _php_db2_close_helper( INTERNAL_FUNCTION_PARAMETERS, int endpconnect
25592571
Closes a database connection */
25602572
PHP_FUNCTION(db2_close)
25612573
{
2562-
return _php_db2_close_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
2574+
_php_db2_close_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
25632575
}
25642576
/* }}} */
25652577

@@ -2568,7 +2580,7 @@ PHP_FUNCTION(db2_close)
25682580
Closes a database connection */
25692581
PHP_FUNCTION(db2_pclose)
25702582
{
2571-
return _php_db2_close_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
2583+
_php_db2_close_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
25722584
}
25732585
/* }}} */
25742586
#endif /* PASE */
@@ -3963,12 +3975,16 @@ PHP_FUNCTION(db2_execute)
39633975
curr_ptr = curr_ptr->next;
39643976

39653977
/* Free Values */
3966-
if ( Z_TYPE_P(prev_ptr->value) == IS_STRING ) {
3967-
efree((prev_ptr->value)->value.str.val);
3968-
}
3978+
if (prev_ptr->value != NULL) {
3979+
if ( Z_TYPE_P(prev_ptr->value) == IS_STRING ) {
3980+
if((prev_ptr->value)->value.str.val != NULL || (prev_ptr->value)->value.str.len != 0) {
3981+
efree((prev_ptr->value)->value.str.val);
3982+
}
3983+
}
39693984

3970-
if( prev_ptr->param_type != DB2_PARAM_OUT && prev_ptr->param_type != DB2_PARAM_INOUT ){
3971-
efree(prev_ptr->value);
3985+
if( prev_ptr->param_type != DB2_PARAM_OUT && prev_ptr->param_type != DB2_PARAM_INOUT ){
3986+
efree(prev_ptr->value);
3987+
}
39723988
}
39733989
efree(prev_ptr);
39743990

@@ -6376,11 +6392,7 @@ PHP_FUNCTION(db2_last_insert_id)
63766392
}
63776393

63786394
/* Selecting last insert ID from current connection resource. */
6379-
#ifdef PASE /* i5/OS no shortcut */
63806395
sql = "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1";
6381-
#else
6382-
sql = "VALUES IDENTITY_VAL_LOCAL()";
6383-
#endif
63846396
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, strlen(sql));
63856397
if ( rc == SQL_ERROR ) {
63866398
_php_db2_check_sql_errors((SQLHDBC)conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1 TSRMLS_CC);

package.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ Cloudscape, and Apache Derby databases.
2222
<email>[email protected]</email>
2323
<active>yes</active>
2424
</lead>
25-
<date>2009-11-06</date>
25+
<date>2009-12-24</date>
2626
<time>12:25:59</time>
2727
<version>
28-
<release>1.8.2</release>
29-
<api>1.8.2</api>
28+
<release>1.8.3</release>
29+
<api>1.8.3</api>
3030
</version>
3131
<stability>
3232
<release>stable</release>
3333
<api>stable</api>
3434
</stability>
3535
<license>Apache License 2.0</license>
3636
<notes>
37-
Fixed 15601: Adding Real Datatype support.
37+
Fixed 14347: ibm_db2 1.6.6 fails to compile (still a problem w/ 1.8.2).
38+
Fixed 16257: db2_execute() Segfault on an empty string as a bind parameter.
39+
Fixed: GRAPHIC, VARGRAPHIC Data type error.
3840
</notes>
3941
<contents>
4042
<dir name="/">

php_ibm_db2.h

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

25-
#define PHP_IBM_DB2_VERSION "1.8.2"
25+
#define PHP_IBM_DB2_VERSION "1.8.3"
2626

2727
#ifndef PHP_IBM_DB2_H
2828
#define PHP_IBM_DB2_H

0 commit comments

Comments
 (0)