@@ -48,6 +48,7 @@ static void _php_db2_assign_options( void* handle, int type, char* opt_key, zval
48
48
static int _php_db2_parse_options ( zval * options , int type , void * handle TSRMLS_DC );
49
49
static void _php_db2_clear_conn_err_cache (TSRMLS_D );
50
50
static void _php_db2_clear_stmt_err_cache (TSRMLS_D );
51
+ static void _php_db2_set_decfloat_rounding_mode_client (void * handle TSRMLS_DC );
51
52
static char * _php_db2_instance_name ;
52
53
static int is_ios , is_zos ; /* 1 == TRUE; 0 == FALSE; */
53
54
#ifdef PASE
@@ -426,6 +427,7 @@ static void _php_db2_free_result_struct(stmt_handle* handle)
426
427
case SQL_DECIMAL :
427
428
case SQL_NUMERIC :
428
429
case SQL_XML :
430
+ case SQL_DECFLOAT :
429
431
if ( handle -> row_data [i ].data .str_val != NULL ) {
430
432
efree (handle -> row_data [i ].data .str_val );
431
433
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)
1732
1734
case SQL_TYPE_TIMESTAMP :
1733
1735
case SQL_DATETIME :
1734
1736
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 ;
1736
1739
if (column_type == SQL_BIGINT ) {
1737
1740
in_length ++ ;
1738
1741
}
@@ -2042,7 +2045,15 @@ static int _php_db2_connect_helper( INTERNAL_FUNCTION_PARAMETERS, conn_handle **
2042
2045
SQLFreeHandle (SQL_HANDLE_ENV , conn_res -> henv );
2043
2046
break ;
2044
2047
}
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
2046
2057
/* Get the server name */
2047
2058
memset (server , 0 , sizeof (server ));
2048
2059
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 **
2087
2098
}
2088
2099
/* }}} */
2089
2100
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
+
2090
2178
/* {{{ static void _php_db2_clear_conn_err_cache (TSRMLS_D)
2091
2179
*/
2092
2180
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
3399
3487
#endif /* PASE */
3400
3488
case SQL_DECIMAL :
3401
3489
case SQL_NUMERIC :
3490
+ case SQL_DECFLOAT :
3402
3491
case SQL_TYPE_DATE :
3403
3492
case SQL_DATETIME :
3404
3493
case SQL_TYPE_TIME :
@@ -4418,6 +4507,7 @@ PHP_FUNCTION(db2_field_type)
4418
4507
case SQL_DOUBLE :
4419
4508
case SQL_DECIMAL :
4420
4509
case SQL_NUMERIC :
4510
+ case SQL_DECFLOAT :
4421
4511
str_val = "real" ;
4422
4512
break ;
4423
4513
case SQL_CLOB :
@@ -4723,6 +4813,7 @@ PHP_FUNCTION(db2_result)
4723
4813
case SQL_BIGINT :
4724
4814
case SQL_DECIMAL :
4725
4815
case SQL_NUMERIC :
4816
+ case SQL_DECFLOAT :
4726
4817
4727
4818
#ifdef PASE /* i5/OS example of "too small" allocation convert problem SQL_C_CHAR */
4728
4819
switch (column_type ) {
@@ -5099,6 +5190,7 @@ static void _php_db2_bind_fetch_helper(INTERNAL_FUNCTION_PARAMETERS, int op)
5099
5190
case SQL_BIGINT :
5100
5191
case SQL_DECIMAL :
5101
5192
case SQL_NUMERIC :
5193
+ case SQL_DECFLOAT :
5102
5194
5103
5195
if ( op & DB2_FETCH_ASSOC ) {
5104
5196
add_assoc_stringl (return_value , (char * )stmt_res -> column_info [i ].name ,
0 commit comments