Skip to content

Commit 9e6c6e3

Browse files
author
Ambrish Bhargava
committed
Adding query timeout support
1 parent 8c087b0 commit 9e6c6e3

File tree

7 files changed

+497
-110
lines changed

7 files changed

+497
-110
lines changed

TODO

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
TODO:
2-
Implement persistent connections.
3-
Implement binary data type support (BLOB, FOR BIT DATA, GRAPHIC DATA).
4-
Implement db2_cursor_type, db2_free_stmt functions.
5-
Implement remaining metadata functions.
6-
Add tests for more data types in more fetch methods.

ibm_db2.c

Lines changed: 272 additions & 88 deletions
Large diffs are not rendered by default.

package.xml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@ Cloudscape, and Apache Derby databases.
2222
<email>[email protected]</email>
2323
<active>yes</active>
2424
</lead>
25-
<date>2009-12-24</date>
26-
<time>12:25:59</time>
25+
<date>2010-03-31</date>
26+
<time>15:17:22</time>
2727
<version>
28-
<release>1.8.3</release>
29-
<api>1.8.3</api>
28+
<release>1.8.4</release>
29+
<api>1.8.4</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 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.
37+
Adding support for query time out.
38+
Fixing problem with DATE/TIME datatype.
39+
i5/OS Add new attribute DB2_I5_JOB_SORT_ON/OFF (php.ini ibm_db2.i5_job_sort).
40+
i5/OS Fix BIGINT string type to help with larger values.
41+
i5/OS Fix "early" terminate fetch loops due to CLOB/BLOB zero length.
42+
i5/OS Fix db2_pclose() to allow reset persistent connections.
4043
</notes>
4144
<contents>
4245
<dir name="/">
@@ -259,7 +262,9 @@ Fixed: GRAPHIC, VARGRAPHIC Data type error.
259262
<file baseinstalldir="ibm_db2" name="test_decfloat.phpt" role="test" />
260263
<file baseinstalldir="ibm_db2" name="test_last_insert_id.phpt" role="test" />
261264
<file baseinstalldir="ibm_db2" name="test_last_insert_id_V5V6.phpt" role="test" />
265+
<file baseinstalldir="ibm_db2" name="test_queryTimeout.phpt" role="test" />
262266
<file baseinstalldir="ibm_db2" name="test_RealDataType.phpt" role="test" />
267+
<file baseinstalldir="ibm_db2" name="test_timestamp.phpt" role="test" />
263268
<file baseinstalldir="ibm_db2" name="test_trusted_context_connect.phpt" role="test" />
264269
<file baseinstalldir="ibm_db2" name="test_trusted_context_pconnect.phpt" role="test" />
265270
<file baseinstalldir="ibm_db2" name="test_000_PrepareDb.phpt" role="test" />

php_ibm_db2.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
$Id$
2323
*/
2424

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

2727
#ifndef PHP_IBM_DB2_H
2828
#define PHP_IBM_DB2_H
@@ -124,10 +124,15 @@ extern zend_module_entry ibm_db2_module_entry;
124124

125125
/*** new set options */
126126
#ifdef PASE
127+
#define SQL_BINARY_V6 -2
128+
#define SQL_VARBINARY_V6 -3
129+
#define SQL_C_BINARY_V6 SQL_BINARY_V6
127130
#define DB2_I5_FETCH_ON SQL_TRUE
128131
#define DB2_I5_FETCH_OFF SQL_FALSE
129132
#define DB2_I5_NAMING_ON SQL_TRUE
130133
#define DB2_I5_NAMING_OFF SQL_FALSE
134+
#define DB2_I5_JOB_SORT_ON SQL_TRUE
135+
#define DB2_I5_JOB_SORT_OFF SQL_FALSE
131136
#define DB2_I5_DBCS_ALLOC_ON SQL_TRUE
132137
#define DB2_I5_DBCS_ALLOC_OFF SQL_FALSE
133138
#define DB2_I5_TXN_NO_COMMIT SQL_TXN_NO_COMMIT
@@ -263,11 +268,12 @@ ZEND_BEGIN_MODULE_GLOBALS(ibm_db2)
263268
char __php_conn_err_state[SQL_SQLSTATE_SIZE + 1];
264269
char __php_stmt_err_msg[DB2_MAX_ERR_MSG_LEN];
265270
char __php_stmt_err_state[SQL_SQLSTATE_SIZE + 1];
266-
#ifdef PASE /* i5/OS ease of use turn off commit */
271+
#ifdef PASE /* i5/OS ease of use turn off/on */
267272
long i5_allow_commit;
268273
long i5_dbcs_alloc;
269274
long i5_all_pconnect;
270275
long i5_ignore_userid;
276+
long i5_job_sort; /* SQL_ATTR_JOB_SORT_SEQUENCE (new PTF) */
271277
#endif /* PASE */
272278
ZEND_END_MODULE_GLOBALS(ibm_db2)
273279

tests/connection.inc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
$database = 'sample';
4-
$user = 'db2inst1';
5-
$password = 'password';
3+
$database = 'testdb';
4+
$user = 'ambrish';
5+
$password = 'login123';
66
$hostname = 'localhost';
7-
$port = 60000;
7+
$port = 60036;
88

99
$db = $database;
1010
$username = $user;
@@ -17,10 +17,10 @@ if (!$prepconn) die('skip');
1717
$server = db2_server_info($prepconn);
1818
if ($server->DBMS_NAME == "QSQ" || $server->DBMS_NAME == "AS") {
1919
if ($server->DBMS_VER > "06000") $rel = "V6";
20-
else $rel = "V5";
20+
else $rel = "/V5/";
2121
// PASE test_xxx_V5V6.phpt
22-
if (eregi("V6|V5", $_SERVER["PHP_SELF"])) {
23-
if (!eregi($rel, $_SERVER["PHP_SELF"])) {
22+
if (preg_match("/V6|V5/", $_SERVER["PHP_SELF"])) {
23+
if (!preg_match($rel, $_SERVER["PHP_SELF"])) {
2424
die('skip');
2525
}
2626
}
@@ -39,7 +39,7 @@ if ($server->DBMS_NAME == "QSQ" || $server->DBMS_NAME == "AS") {
3939
}
4040
}
4141
else {
42-
if (eregi("V5|V6",$_SERVER["PHP_SELF"])) die('skip');
42+
if (preg_match("/V5|V6/", $_SERVER["PHP_SELF"])) die('skip');
4343
}
4444

4545
db2_close($prepconn);

tests/test_queryTimeout.phpt

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
--TEST--
2+
IBM-DB2: Query Time Out 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+
echo "Connection pass.\n";
13+
$createQuery = "CREATE TABLE querytimeout(id INTEGER, value INTEGER)";
14+
$dropQuery = "DROP TABLE querytimeout";
15+
16+
$rc = @db2_exec ($conn, $dropQuery);
17+
$rc = db2_exec ($conn, $createQuery);
18+
19+
$insertQuery = "INSERT INTO querytimeout (id, value) VALUES(?, ?)";
20+
21+
$stmt = db2_prepare ($conn, $insertQuery);
22+
23+
db2_set_option($conn, array("query_timeout" => "500"), 1);
24+
25+
for($i = 0;$i < 10;$i++) {
26+
$rc = db2_execute($stmt, array($i, $i + $i));
27+
}
28+
29+
$selectQuery = "SELECT * FROM querytimeout";
30+
31+
$stmt = db2_prepare($conn, $selectQuery);
32+
33+
db2_set_option($stmt, array("query_timeout" => 1), 2);
34+
35+
db2_execute($stmt);
36+
37+
while ($row = db2_fetch_array($stmt)) {
38+
print_r($row);
39+
}
40+
41+
db2_close($conn);
42+
} else {
43+
echo "Connection fail.\n";
44+
echo db2_conn_errormsg() . "\n";
45+
}
46+
?>
47+
--EXPECTF--
48+
Connection pass.
49+
50+
Warning: db2_set_option(): QUERY TIMEOUT attribute can only be set on statement resources in %s on line 18
51+
Array
52+
(
53+
[0] => 0
54+
[1] => 0
55+
)
56+
Array
57+
(
58+
[0] => 1
59+
[1] => 2
60+
)
61+
Array
62+
(
63+
[0] => 2
64+
[1] => 4
65+
)
66+
Array
67+
(
68+
[0] => 3
69+
[1] => 6
70+
)
71+
Array
72+
(
73+
[0] => 4
74+
[1] => 8
75+
)
76+
Array
77+
(
78+
[0] => 5
79+
[1] => 10
80+
)
81+
Array
82+
(
83+
[0] => 6
84+
[1] => 12
85+
)
86+
Array
87+
(
88+
[0] => 7
89+
[1] => 14
90+
)
91+
Array
92+
(
93+
[0] => 8
94+
[1] => 16
95+
)
96+
Array
97+
(
98+
[0] => 9
99+
[1] => 18
100+
)

tests/test_timestamp.phpt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
--TEST--
2+
IBM-DB2: Timestamp data type 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+
echo "Error connecting to database " . db2_conn_errormsg() ."\n";
13+
exit;
14+
}
15+
16+
// Drop/Create source and target tables
17+
@db2_exec($conn, "DROP TABLE src");
18+
@db2_exec($conn, "DROP TABLE targ");
19+
20+
db2_exec($conn, "CREATE TABLE src (c1 INT, c2 TIMESTAMP)");
21+
db2_exec($conn, "CREATE TABLE targ (c1 INT, c2 TIMESTAMP)");
22+
23+
// If you insert NULL as the timestamp into the src table, the later insert
24+
// will NOT work.
25+
db2_exec($conn, "INSERT INTO src VALUES (NULL, '1981-05-13 12:56:46.000000')");
26+
db2_exec($conn, "INSERT INTO src VALUES (1, NULL)");
27+
db2_exec($conn, "INSERT INTO src VALUES (1, '1981-05-13 12:56:46.000000')");
28+
29+
$rs = db2_exec($conn, "SELECT c1, c2 FROM src ORDER BY c2");
30+
31+
$prep = db2_prepare ($conn, "INSERT INTO targ VALUES (?, ?)");
32+
33+
echo "Transfering data from src table to targ table:\n";
34+
while($valuesOut = db2_fetch_array($rs)) {
35+
$rs1 = db2_execute($prep, $valuesOut);
36+
if (!$rs1) {
37+
echo "Error inserting into targ \n";
38+
var_dump($valuesOut);
39+
exit;
40+
}
41+
}
42+
43+
echo "Values from src table:\n";
44+
$rs = db2_exec($conn, "SELECT c1, c2 FROM src ORDER BY c2");
45+
while($valuesOut = db2_fetch_array($rs)) {
46+
var_dump($valuesOut);
47+
}
48+
49+
echo "Values from targ table:\n";
50+
$rs = db2_exec($conn, "SELECT c1, c2 FROM targ ORDER BY c2");
51+
while($valuesOut = db2_fetch_array($rs)) {
52+
var_dump($valuesOut);
53+
}
54+
55+
db2_close($conn);
56+
57+
?>
58+
--EXPECT--
59+
Transfering data from src table to targ table:
60+
Values from src table:
61+
array(2) {
62+
[0]=>
63+
NULL
64+
[1]=>
65+
string(26) "1981-05-13 12:56:46.000000"
66+
}
67+
array(2) {
68+
[0]=>
69+
int(1)
70+
[1]=>
71+
string(26) "1981-05-13 12:56:46.000000"
72+
}
73+
array(2) {
74+
[0]=>
75+
int(1)
76+
[1]=>
77+
NULL
78+
}
79+
Values from targ table:
80+
array(2) {
81+
[0]=>
82+
NULL
83+
[1]=>
84+
string(26) "1981-05-13 12:56:46.000000"
85+
}
86+
array(2) {
87+
[0]=>
88+
int(1)
89+
[1]=>
90+
string(26) "1981-05-13 12:56:46.000000"
91+
}
92+
array(2) {
93+
[0]=>
94+
int(1)
95+
[1]=>
96+
NULL
97+
}

0 commit comments

Comments
 (0)