Skip to content

Commit 0eb85c4

Browse files
author
Ambrish Bhargava
committed
Adding Mac OS Support. Adding Declfloat datatype. Renaming test cases.
1 parent 1109316 commit 0eb85c4

File tree

5 files changed

+420
-331
lines changed

5 files changed

+420
-331
lines changed

config.m4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,31 @@ if test "$PHP_IBM_DB2" != "no"; then
2525
AC_MSG_CHECKING(Looking for DB2 CLI libraries)
2626
for i in $SEARCH_PATH ; do
2727
AC_MSG_CHECKING([ in $i])
28-
if test -r $i/libdb2.so || test -r $i/libdb2.a || test -r $i/libdb400.a ; then
28+
if test -r $i/libdb2.so || test -r $i/libdb2.a || test -r $i/libdb400.a || test -r $i/libdb2.dylib ; then
2929
LIB_DIR="$i/"
3030
AC_MSG_RESULT(found)
3131
break
3232
else
3333
AC_MSG_RESULT()
3434
fi
3535
AC_MSG_CHECKING([ in $i/lib64])
36-
if test -r $i/lib64/libdb2.so || test -r $i/lib64/libdb2.a || test -r $i/lib64/libdb400.a ; then
36+
if test -r $i/lib64/libdb2.so || test -r $i/lib64/libdb2.a || test -r $i/lib64/libdb400.a || test -r $i/lib64/libdb2.dylib ; then
3737
LIB_DIR="$i/lib64/"
3838
AC_MSG_RESULT(found)
3939
break
4040
else
4141
AC_MSG_RESULT()
4242
fi
4343
AC_MSG_CHECKING([ in $i/lib32])
44-
if test -r $i/lib32/libdb2.so || test -r $i/lib32/libdb2.a || test -r $i/lib32/libdb400.a ; then
44+
if test -r $i/lib32/libdb2.so || test -r $i/lib32/libdb2.a || test -r $i/lib32/libdb400.a || test -r $i/lib32/libdb2.dylib ; then
4545
LIB_DIR="$i/lib32/"
4646
AC_MSG_RESULT(found)
4747
break
4848
else
4949
AC_MSG_RESULT()
5050
fi
5151
AC_MSG_CHECKING([ in $i/lib])
52-
if test -r $i/lib/libdb2.so || test -r $i/lib/libdb2.a || test -r $i/lib/libdb400.a ; then
52+
if test -r $i/lib/libdb2.so || test -r $i/lib/libdb2.a || test -r $i/lib/libdb400.a || test -r $i/lib/libdb2.dylib ; then
5353
LIB_DIR="$i/lib/"
5454
AC_MSG_RESULT(found)
5555
break

ibm_db2.c

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static void _php_db2_assign_options( void* handle, int type, char* opt_key, zval
4848
static int _php_db2_parse_options( zval* options, int type, void* handle TSRMLS_DC );
4949
static void _php_db2_clear_conn_err_cache(TSRMLS_D);
5050
static void _php_db2_clear_stmt_err_cache(TSRMLS_D);
51+
static void _php_db2_set_decfloat_rounding_mode_client(void* handle TSRMLS_DC);
5152
static char * _php_db2_instance_name;
5253
static int is_ios, is_zos; /* 1 == TRUE; 0 == FALSE; */
5354
#ifdef PASE
@@ -426,6 +427,7 @@ static void _php_db2_free_result_struct(stmt_handle* handle)
426427
case SQL_DECIMAL:
427428
case SQL_NUMERIC:
428429
case SQL_XML:
430+
case SQL_DECFLOAT:
429431
if ( handle->row_data[i].data.str_val != NULL ) {
430432
efree(handle->row_data[i].data.str_val);
431433
handle->row_data[i].data.str_val = NULL;
@@ -1732,7 +1734,8 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
17321734
case SQL_TYPE_TIMESTAMP:
17331735
case SQL_DATETIME:
17341736
case SQL_BIGINT:
1735-
in_length = stmt_res->column_info[i].size + 1;
1737+
case SQL_DECFLOAT:
1738+
in_length = stmt_res->column_info[i].size + 2;
17361739
if(column_type == SQL_BIGINT) {
17371740
in_length++;
17381741
}
@@ -2042,7 +2045,15 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
20422045
SQLFreeHandle(SQL_HANDLE_ENV, conn_res->henv);
20432046
break;
20442047
}
2045-
2048+
#ifdef CLI_DBC_SERVER_TYPE_DB2LUW
2049+
#ifdef SQL_ATTR_DECFLOAT_ROUNDING_MODE
2050+
/**
2051+
* Code for setting SQL_ATTR_DECFLOAT_ROUNDING_MODE
2052+
* for implementation of Decfloat Datatype
2053+
* */
2054+
_php_db2_set_decfloat_rounding_mode_client(conn_res TSRMLS_CC);
2055+
#endif
2056+
#endif
20462057
/* Get the server name */
20472058
memset(server, 0, sizeof(server));
20482059
rc = SQLGetInfo(conn_res->hdbc, SQL_DBMS_NAME, (SQLPOINTER)server, 2048, NULL);
@@ -2087,6 +2098,83 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
20872098
}
20882099
/* }}} */
20892100

2101+
#ifdef CLI_DBC_SERVER_TYPE_DB2LUW
2102+
#ifdef SQL_ATTR_DECFLOAT_ROUNDING_MODE
2103+
/**
2104+
* Function for implementation of DECFLOAT Datatype
2105+
*
2106+
* Description :
2107+
* This function retrieves the value of special register decflt_rounding
2108+
* from the database server which signifies the current rounding mode set
2109+
* on the server. For using decfloat, the rounding mode has to be in sync
2110+
* on the client as well as server. Thus we set here on the client, the
2111+
* same rounding mode as the server.
2112+
* @return: success or failure
2113+
* */
2114+
static void _php_db2_set_decfloat_rounding_mode_client(void* handle TSRMLS_DC)
2115+
{
2116+
SQLCHAR decflt_rounding[20];
2117+
SQLHANDLE hstmt;
2118+
SQLHDBC hdbc = ((conn_handle*) handle)->hdbc;
2119+
int rc = 0;
2120+
int rounding_mode;
2121+
SQLINTEGER decfloat;
2122+
2123+
SQLCHAR *stmt = (SQLCHAR *)"values current decfloat rounding mode";
2124+
2125+
/* Allocate a Statement Handle */
2126+
rc = SQLAllocHandle(SQL_HANDLE_STMT, (SQLHDBC) hdbc, &hstmt);
2127+
if (rc == SQL_ERROR) {
2128+
_php_db2_db_check_sql_errors((SQLHDBC) hdbc, SQL_HANDLE_DBC, rc, 1,
2129+
NULL, -1, 1 TSRMLS_CC);
2130+
return;
2131+
}
2132+
rc = SQLExecDirect((SQLHSTMT)hstmt, (SQLPOINTER)stmt, SQL_NTS);
2133+
if ( rc == SQL_ERROR ) {
2134+
_php_db2_check_sql_errors(hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
2135+
}
2136+
if ( rc < SQL_SUCCESS ) {
2137+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement Execute Failed");
2138+
SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
2139+
return;
2140+
}
2141+
2142+
rc = SQLBindCol((SQLHSTMT)hstmt, 1, SQL_C_DEFAULT, decflt_rounding, 20, NULL);
2143+
if (rc == SQL_ERROR) {
2144+
_php_db2_db_check_sql_errors((SQLHANDLE) hdbc, SQL_HANDLE_DBC, rc, 1,
2145+
NULL, -1, 1 TSRMLS_CC);
2146+
return;
2147+
}
2148+
2149+
rc = SQLFetch(hstmt);
2150+
rc = SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
2151+
/* Now setting up the same rounding mode on the client*/
2152+
if(strcmp(decflt_rounding, "ROUND_HALF_EVEN") == 0) {
2153+
rounding_mode = SQL_ROUND_HALF_EVEN;
2154+
}
2155+
if(strcmp(decflt_rounding, "ROUND_HALF_UP") == 0) {
2156+
rounding_mode = SQL_ROUND_HALF_UP;
2157+
}
2158+
if(strcmp(decflt_rounding, "ROUND_DOWN") == 0) {
2159+
rounding_mode = SQL_ROUND_DOWN;
2160+
}
2161+
if(strcmp(decflt_rounding, "ROUND_CEILING") == 0) {
2162+
rounding_mode = SQL_ROUND_CEILING;
2163+
}
2164+
if(strcmp(decflt_rounding, "ROUND_FLOOR") == 0) {
2165+
rounding_mode = SQL_ROUND_FLOOR;
2166+
}
2167+
#ifndef PASE
2168+
rc = SQLSetConnectAttr((SQLHDBC)hdbc, SQL_ATTR_DECFLOAT_ROUNDING_MODE, (SQLPOINTER)rounding_mode, SQL_NTS);
2169+
#else
2170+
rc = SQLSetConnectAttr((SQLHDBC)hdbc, SQL_ATTR_DECFLOAT_ROUNDING_MODE, (SQLPOINTER)&rounding_mode, SQL_NTS);
2171+
#endif
2172+
2173+
return;
2174+
}
2175+
#endif
2176+
#endif
2177+
20902178
/* {{{ static void _php_db2_clear_conn_err_cache (TSRMLS_D)
20912179
*/
20922180
static void _php_db2_clear_conn_err_cache(TSRMLS_D)
@@ -3399,6 +3487,7 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b
33993487
#endif /* PASE */
34003488
case SQL_DECIMAL:
34013489
case SQL_NUMERIC:
3490+
case SQL_DECFLOAT:
34023491
case SQL_TYPE_DATE:
34033492
case SQL_DATETIME:
34043493
case SQL_TYPE_TIME:
@@ -4418,6 +4507,7 @@ PHP_FUNCTION(db2_field_type)
44184507
case SQL_DOUBLE:
44194508
case SQL_DECIMAL:
44204509
case SQL_NUMERIC:
4510+
case SQL_DECFLOAT:
44214511
str_val = "real";
44224512
break;
44234513
case SQL_CLOB:
@@ -4723,6 +4813,7 @@ PHP_FUNCTION(db2_result)
47234813
case SQL_BIGINT:
47244814
case SQL_DECIMAL:
47254815
case SQL_NUMERIC:
4816+
case SQL_DECFLOAT:
47264817

47274818
#ifdef PASE /* i5/OS example of "too small" allocation convert problem SQL_C_CHAR */
47284819
switch(column_type) {
@@ -5099,6 +5190,7 @@ static void _php_db2_bind_fetch_helper(INTERNAL_FUNCTION_PARAMETERS, int op)
50995190
case SQL_BIGINT:
51005191
case SQL_DECIMAL:
51015192
case SQL_NUMERIC:
5193+
case SQL_DECFLOAT:
51025194

51035195
if ( op & DB2_FETCH_ASSOC ) {
51045196
add_assoc_stringl(return_value, (char *)stmt_res->column_info[i].name,

0 commit comments

Comments
 (0)