Skip to content

Commit 5cc6969

Browse files
author
Ambrish Bhargava
committed
Adding Real datatype support
1 parent 45c9a0d commit 5cc6969

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

ibm_db2.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ typedef union {
113113
SQLINTEGER i_val;
114114
SQLDOUBLE d_val;
115115
SQLFLOAT f_val;
116+
SQLREAL r_val;
116117
SQLSMALLINT s_val;
117118
SQLCHAR *str_val;
118119
} db2_row_data_type;
@@ -1767,6 +1768,13 @@ static int _php_db2_bind_column_helper(stmt_handle *stmt_res TSRMLS_DC)
17671768
break;
17681769

17691770
case SQL_REAL:
1771+
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
1772+
SQL_C_FLOAT, &row_data->r_val, sizeof(row_data->r_val),
1773+
(SQLINTEGER *)(&stmt_res->row_data[i].out_length));
1774+
if ( rc == SQL_ERROR ) {
1775+
_php_db2_check_sql_errors((SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1 TSRMLS_CC);
1776+
}
1777+
break;
17701778
case SQL_FLOAT:
17711779
rc = SQLBindCol((SQLHSTMT)stmt_res->hstmt, (SQLUSMALLINT)(i+1),
17721780
SQL_C_DEFAULT, &row_data->f_val, sizeof(row_data->f_val),
@@ -5220,6 +5228,14 @@ static void _php_db2_bind_fetch_helper(INTERNAL_FUNCTION_PARAMETERS, int op)
52205228
break;
52215229

52225230
case SQL_REAL:
5231+
if ( op & DB2_FETCH_ASSOC ) {
5232+
add_assoc_double(return_value, (char *)stmt_res->column_info[i].name, row_data->r_val);
5233+
}
5234+
if ( op & DB2_FETCH_INDEX ) {
5235+
add_index_double(return_value, i, row_data->r_val);
5236+
}
5237+
break;
5238+
52235239
case SQL_FLOAT:
52245240
if ( op & DB2_FETCH_ASSOC ) {
52255241
add_assoc_double(return_value, (char *)stmt_res->column_info[i].name, row_data->f_val);

package.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
</maintainer>
2626
</maintainers>
2727
<release>
28-
<version>1.8.1</version>
29-
<date>2008-02-09</date>
28+
<version>1.8.2</version>
29+
<date>2009-03-09</date>
3030
<license>Apache License 2.0</license>
3131
<state>stable</state>
3232
<notes>
33-
Adding Mac OS support.
34-
Adding DecFloat Datatype support.
35-
Updating test case names.
33+
Adding Real Datatype support.
3634
</notes>
3735
<configureoptions>
3836
<configureoption name="with-IBM_DB2"
@@ -268,6 +266,7 @@
268266
<file name="test_decfloat.phpt" role="test" />
269267
<file name="test_last_insert_id.phpt" role="test" />
270268
<file name="test_last_insert_id_V5V6.phpt" role="test" />
269+
<file name="test_RealDataType.phpt" role="test" />
271270
<file name="test_trusted_context_connect.phpt" role="test" />
272271
<file name="test_trusted_context_pconnect.phpt" role="test" />
273272
</dir>

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.1"
25+
#define PHP_IBM_DB2_VERSION "1.8.2"
2626

2727
#ifndef PHP_IBM_DB2_H
2828
#define PHP_IBM_DB2_H

tests/test_RealDataType.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
IBM-DB2: Real datatype test.
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
require_once('connection.inc');
9+
$conn = db2_connect($database, $user, $password);
10+
11+
if ($conn) {
12+
// Dropping the test table, if exeist.
13+
$res = @db2_exec($conn, "DROP TABLE TEST1R");
14+
15+
// Creating new test table.
16+
$res = @db2_exec($conn, "CREATE TABLE TEST1R (TZ_OFFSET REAL)");
17+
18+
// Inserting values to the test table.
19+
$res = db2_exec($conn, "INSERT INTO TEST1R VALUES(-2.34)");
20+
21+
$res = db2_exec($conn, "SELECT tz_offset from test1R");
22+
23+
while ($row = db2_fetch_both($res)) {
24+
var_dump($row);
25+
}
26+
27+
// Dropping the test table.
28+
$res = @db2_exec($conn, "DROP TABLE TEST1R");
29+
30+
db2_close($conn);
31+
} else {
32+
print "Connection not created" . "\n";
33+
}
34+
?>
35+
--EXPECT--
36+
array(2) {
37+
["TZ_OFFSET"]=>
38+
float(-2.3399999141693)
39+
[0]=>
40+
float(-2.3399999141693)
41+
}

0 commit comments

Comments
 (0)