Skip to content

Commit 66acaba

Browse files
committed
Add more test coverage for ext/odbc
1 parent c9e5e1f commit 66acaba

21 files changed

+920
-0
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
odbc_close_all(): Basic test
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn1 = odbc_connect($dsn, $user, $pass);
13+
$conn2 = odbc_pconnect($dsn, $user, $pass);
14+
$result1 = odbc_columns($conn1, '', '', '', '');
15+
$result2 = odbc_columns($conn2, '', '', '', '');
16+
17+
var_dump($conn1);
18+
var_dump($conn2);
19+
var_dump($result1);
20+
var_dump($result2);
21+
22+
odbc_close_all();
23+
24+
var_dump($conn1);
25+
var_dump($conn2);
26+
var_dump($result1);
27+
var_dump($result2);
28+
29+
?>
30+
--EXPECTF--
31+
resource(5) of type (odbc link)
32+
resource(7) of type (odbc link persistent)
33+
resource(8) of type (odbc result)
34+
resource(9) of type (odbc result)
35+
resource(5) of type (Unknown)
36+
resource(7) of type (Unknown)
37+
resource(8) of type (Unknown)
38+
resource(9) of type (Unknown)

ext/odbc/tests/odbc_commit_001.phpt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
odbc_commit(): Basic test for odbc_commit()
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
odbc_exec($conn, 'CREATE TABLE commit_table (test INT)');
14+
15+
odbc_autocommit($conn, false);
16+
odbc_exec($conn, 'INSERT INTO commit_table VALUES(1)');
17+
var_dump(odbc_commit($conn));
18+
19+
$res = odbc_exec($conn, 'SELECT * FROM commit_table');
20+
var_dump(odbc_result($res, "test"));
21+
22+
?>
23+
--CLEAN--
24+
<?php
25+
require 'config.inc';
26+
$conn = odbc_connect($dsn, $user, $pass);
27+
odbc_exec($conn, 'DROP TABLE commit_table');
28+
?>
29+
--EXPECT--
30+
bool(true)
31+
string(1) "1"

ext/odbc/tests/odbc_cursor_001.phpt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Test odbc_cursor()
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
include 'config.inc';
10+
11+
$conn = odbc_connect($dsn, $user, $pass);
12+
13+
odbc_exec($conn, "CREATE TABLE cursor_table (id INT, whatever TEXT)");
14+
odbc_exec($conn, "INSERT INTO cursor_table VALUES (1, 'whatever')");
15+
$res = odbc_exec($conn, 'SELECT * FROM cursor_table');
16+
17+
var_dump(odbc_cursor($res));
18+
19+
odbc_close($conn);
20+
?>
21+
--CLEAN--
22+
<?php
23+
include 'config.inc';
24+
25+
$conn = odbc_connect($dsn, $user, $pass);
26+
odbc_exec($conn, "DROP TABLE cursor_table");
27+
?>
28+
--EXPECTF--
29+
string(%d) "SQL_CUR%s"
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
odbc_fetch_array(): Getting data from query
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
14+
odbc_exec($conn, 'CREATE TABLE fetch_array (foo INT)');
15+
odbc_exec($conn, 'INSERT INTO fetch_array VALUES (1)');
16+
odbc_exec($conn, 'INSERT INTO fetch_array VALUES (2)');
17+
odbc_exec($conn, 'INSERT INTO fetch_array VALUES (3)');
18+
19+
$res = odbc_exec($conn, 'SELECT * FROM fetch_array');
20+
21+
var_dump(odbc_fetch_array($res, 1));
22+
var_dump(odbc_fetch_array($res));
23+
var_dump(odbc_fetch_array($res, 3));
24+
var_dump(odbc_fetch_array($res, 4));
25+
26+
?>
27+
--CLEAN--
28+
<?php
29+
require 'config.inc';
30+
$conn = odbc_connect($dsn, $user, $pass);
31+
odbc_exec($conn, 'DROP TABLE fetch_array');
32+
?>
33+
--EXPECTF--
34+
array(1) {
35+
["foo"]=>
36+
string(1) "1"
37+
}
38+
array(1) {
39+
["foo"]=>
40+
string(1) "2"
41+
}
42+
array(1) {
43+
["foo"]=>
44+
string(1) "3"
45+
}
46+
bool(false)
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
odbc_fetch_into(): Getting data from query
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
14+
odbc_exec($conn, 'CREATE TABLE fetch_into (foo INT)');
15+
odbc_exec($conn, 'INSERT INTO fetch_into VALUES (1)');
16+
odbc_exec($conn, 'INSERT INTO fetch_into VALUES (2)');
17+
odbc_exec($conn, 'INSERT INTO fetch_into VALUES (3)');
18+
19+
$res = odbc_exec($conn, 'SELECT * FROM fetch_into');
20+
21+
$arr = [];
22+
var_dump(odbc_fetch_into($res, $arr, 1));
23+
var_dump($arr);
24+
$arr = [];
25+
var_dump(odbc_fetch_into($res, $arr));
26+
var_dump($arr);
27+
$arr = [];
28+
var_dump(odbc_fetch_into($res, $arr, 0));
29+
var_dump($arr);
30+
$arr = [];
31+
var_dump(odbc_fetch_into($res, $arr, 4));
32+
var_dump($arr);
33+
34+
?>
35+
--CLEAN--
36+
<?php
37+
require 'config.inc';
38+
$conn = odbc_connect($dsn, $user, $pass);
39+
odbc_exec($conn, 'DROP TABLE fetch_into');
40+
?>
41+
--EXPECTF--
42+
int(1)
43+
array(1) {
44+
[0]=>
45+
string(1) "1"
46+
}
47+
int(1)
48+
array(1) {
49+
[0]=>
50+
string(1) "2"
51+
}
52+
int(1)
53+
array(1) {
54+
[0]=>
55+
string(1) "3"
56+
}
57+
bool(false)
58+
array(0) {
59+
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
odbc_fetch_object(): Getting data from query
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
14+
odbc_exec($conn, 'CREATE TABLE fetch_object (foo INT)');
15+
odbc_exec($conn, 'INSERT INTO fetch_object VALUES (1)');
16+
odbc_exec($conn, 'INSERT INTO fetch_object VALUES (2)');
17+
odbc_exec($conn, 'INSERT INTO fetch_object VALUES (3)');
18+
19+
$res = odbc_exec($conn, 'SELECT * FROM fetch_object');
20+
21+
var_dump(odbc_fetch_object($res, 1));
22+
var_dump(odbc_fetch_object($res));
23+
var_dump(odbc_fetch_object($res, 0));
24+
var_dump(odbc_fetch_object($res, 4));
25+
26+
?>
27+
--CLEAN--
28+
<?php
29+
require 'config.inc';
30+
$conn = odbc_connect($dsn, $user, $pass);
31+
odbc_exec($conn, 'DROP TABLE fetch_object');
32+
?>
33+
--EXPECTF--
34+
object(stdClass)#%d (%d) {
35+
["foo"]=>
36+
string(1) "1"
37+
}
38+
object(stdClass)#%d (%d) {
39+
["foo"]=>
40+
string(1) "2"
41+
}
42+
object(stdClass)#%d (%d) {
43+
["foo"]=>
44+
string(1) "3"
45+
}
46+
bool(false)
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
odbc_fetch_row(): Getting data from query
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
14+
odbc_exec($conn, 'CREATE TABLE fetch_row (test INT)');
15+
16+
odbc_exec($conn, 'INSERT INTO fetch_row VALUES (1)');
17+
odbc_exec($conn, 'INSERT INTO fetch_row VALUES (2)');
18+
odbc_exec($conn, 'INSERT INTO fetch_row VALUES (3)');
19+
20+
$res = odbc_exec($conn, 'SELECT * FROM fetch_row');
21+
22+
var_dump(odbc_fetch_row($res, 0));
23+
24+
var_dump(odbc_fetch_row($res, null));
25+
var_dump(odbc_result($res, 'test'));
26+
27+
var_dump(odbc_fetch_row($res, null));
28+
var_dump(odbc_result($res, 'test'));
29+
30+
var_dump(odbc_fetch_row($res, 3));
31+
var_dump(odbc_result($res, 'test'));
32+
33+
var_dump(odbc_fetch_row($res, 4));
34+
35+
odbc_free_result($res);
36+
odbc_close($conn);
37+
?>
38+
--CLEAN--
39+
<?php
40+
require 'config.inc';
41+
$conn = odbc_connect($dsn, $user, $pass);
42+
odbc_exec($conn, 'DROP TABLE fetch_row');
43+
?>
44+
--EXPECTF--
45+
bool(false)
46+
bool(true)
47+
string(1) "1"
48+
bool(true)
49+
string(1) "2"
50+
bool(true)
51+
string(1) "3"
52+
bool(false)
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
odbc_field_len(): Getting the length of the field
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
14+
odbc_exec($conn, 'CREATE TABLE field_len (foo INT, bar TEXT, baz VARBINARY(50))');
15+
odbc_exec($conn, "INSERT INTO field_len VALUES (1, 'bar', CONVERT(VARBINARY(50), 'baz'))");
16+
17+
$res = odbc_exec($conn, 'SELECT * FROM field_len');
18+
try {
19+
odbc_field_len($res, 0);
20+
} catch (ValueError $error) {
21+
echo $error->getMessage() . "\n";
22+
}
23+
var_dump(odbc_field_len($res, 1));
24+
var_dump(odbc_field_len($res, 2));
25+
var_dump(odbc_field_len($res, 3));
26+
var_dump(odbc_field_len($res, 4));
27+
28+
odbc_close($conn);
29+
?>
30+
--CLEAN--
31+
<?php
32+
require 'config.inc';
33+
$conn = odbc_connect($dsn, $user, $pass);
34+
odbc_exec($conn, 'DROP TABLE field_len');
35+
?>
36+
--EXPECTF--
37+
odbc_field_len(): Argument #2 ($field) must be greater than 0
38+
int(10)
39+
int(2147483647)
40+
int(50)
41+
42+
Warning: odbc_field_len(): Field index larger than number of fields in %s on line %d
43+
bool(false)
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
odbc_field_name(): Getting the name of the field
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
14+
odbc_exec($conn, 'CREATE TABLE field_name (foo INT, bar INT, baz INT)');
15+
odbc_exec($conn, 'INSERT INTO field_name VALUES (1, 2, 3)');
16+
17+
$res = odbc_exec($conn, 'SELECT * FROM field_name');
18+
try {
19+
odbc_field_name($res, 0);
20+
} catch (ValueError $error) {
21+
echo $error->getMessage() . "\n";
22+
}
23+
var_dump(odbc_field_name($res, 1));
24+
var_dump(odbc_field_name($res, 2));
25+
var_dump(odbc_field_name($res, 3));
26+
var_dump(odbc_field_name($res, 4));
27+
28+
?>
29+
--CLEAN--
30+
<?php
31+
require 'config.inc';
32+
$conn = odbc_connect($dsn, $user, $pass);
33+
odbc_exec($conn, 'DROP TABLE field_name');
34+
?>
35+
--EXPECTF--
36+
odbc_field_name(): Argument #2 ($field) must be greater than 0
37+
string(3) "foo"
38+
string(3) "bar"
39+
string(3) "baz"
40+
41+
Warning: odbc_field_name(): Field index larger than number of fields in %s on line %d
42+
bool(false)

0 commit comments

Comments
 (0)