Skip to content

Commit a31e27d

Browse files
author
Stanley Sufficool
committed
Add tests for recent fixes
1 parent de8022e commit a31e27d

File tree

7 files changed

+326
-0
lines changed

7 files changed

+326
-0
lines changed

ext/pdo_dblib/tests/bug_38955.phpt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
PDO_DBLIB driver does not support transactions
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
16+
17+
/*We see these rows */
18+
$db->query("CREATE table php_test(val int)");
19+
$db->beginTransaction();
20+
$db->query("INSERT INTO php_test(val) values(1)");
21+
$db->query("INSERT INTO php_test(val) values(2)");
22+
$db->query("INSERT INTO php_test(val) values(3)");
23+
$db->query("INSERT INTO php_test(val) values(4)");
24+
$db->commit();
25+
26+
/*We don't see these rows */
27+
$db->beginTransaction();
28+
$db->query("INSERT INTO php_test(val) values(5)");
29+
$db->query("INSERT INTO php_test(val) values(6)");
30+
$db->query("INSERT INTO php_test(val) values(7)");
31+
$db->query("INSERT INTO php_test(val) values(8)");
32+
$db->rollback();
33+
34+
$rs = $db->query("SELECT * FROM php_test");
35+
$rows = $rs->fetchAll(PDO::FETCH_ASSOC);
36+
var_dump($rows);
37+
38+
$db->query("DROP table php_test");
39+
?>
40+
--EXPECT--
41+
array(4) {
42+
[0]=>
43+
array(1) {
44+
["val"]=>
45+
string(1) "1"
46+
}
47+
[1]=>
48+
array(1) {
49+
["val"]=>
50+
string(1) "2"
51+
}
52+
[2]=>
53+
array(1) {
54+
["val"]=>
55+
string(1) "3"
56+
}
57+
[3]=>
58+
array(1) {
59+
["val"]=>
60+
string(1) "4"
61+
}
62+
}

ext/pdo_dblib/tests/bug_45876.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
PDO_DBLIB: Does not support get column meta
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
16+
17+
$stmt = $db->prepare("select ic1.* from information_schema.columns ic1");
18+
$stmt->execute();
19+
var_dump($stmt->getColumnMeta(0));
20+
$stmt = null;
21+
?>
22+
--EXPECT--
23+
array(8) {
24+
["max_length"]=>
25+
int(255)
26+
["precision"]=>
27+
int(0)
28+
["scale"]=>
29+
int(0)
30+
["column_source"]=>
31+
string(13) "table_catalog"
32+
["native_type"]=>
33+
string(4) "char"
34+
["name"]=>
35+
string(13) "table_catalog"
36+
["len"]=>
37+
int(255)
38+
["pdo_type"]=>
39+
int(2)
40+
}

ext/pdo_dblib/tests/bug_47588.phpt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
PDO_DBLIB: Quoted field names
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
16+
17+
$db->query('CREATE TABLE "Test Table" ("My Field" int, "Another Field" varchar(32) not null default \'test_string\')');
18+
$db->query('INSERT INTO "Test Table" ("My Field") values(1)');
19+
$db->query('INSERT INTO "Test Table" ("My Field") values(2)');
20+
$db->query('INSERT INTO "Test Table" ("My Field") values(3)');
21+
$rs = $db->query('SELECT * FROM "Test Table"');
22+
var_dump($rs->fetchAll(PDO::FETCH_ASSOC));
23+
$db->query('DROP TABLE "Test Table"');
24+
echo "Done.\n";
25+
?>
26+
--EXPECT--
27+
array(3) {
28+
[0]=>
29+
array(2) {
30+
["my field"]=>
31+
string(1) "1"
32+
["another field"]=>
33+
string(11) "test_string"
34+
}
35+
[1]=>
36+
array(2) {
37+
["my field"]=>
38+
string(1) "2"
39+
["another field"]=>
40+
string(11) "test_string"
41+
}
42+
[2]=>
43+
array(2) {
44+
["my field"]=>
45+
string(1) "3"
46+
["another field"]=>
47+
string(11) "test_string"
48+
}
49+
}
50+
Done.

ext/pdo_dblib/tests/bug_50755.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
PDO_DBLIB: Out of memory on large recordsets
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
16+
17+
/* This should be sufficient to overflow any buffers */
18+
$stmt = $db->prepare("select *
19+
from information_schema.columns ic1
20+
cross join information_schema.columns ic2
21+
cross join information_schema.columns ic3");
22+
23+
$x = $stmt->execute();
24+
$n = 0;
25+
while (($r = $stmt->fetch())) {
26+
$n++;
27+
}
28+
$stmt = null;
29+
30+
echo "OK\n";
31+
32+
?>
33+
--EXPECT--
34+
OK

ext/pdo_dblib/tests/common.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
DBLIB
3+
--SKIPIF--
4+
<?php # vim:ft=php
5+
if (!extension_loaded('pdo_dblib')) print 'skip';
6+
?>
7+
--REDIRECTTEST--
8+
# magic auto-configuration
9+
# Also update config.inc if you make changes here...
10+
11+
$config = array(
12+
'TESTS' => 'ext/pdo/tests'
13+
);
14+
15+
if (false !== getenv('PDO_DBLIB_TEST_DSN'))
16+
$config['ENV']['PDOTEST_DSN'] = getenv('PDO_DBLIB_TEST_DSN');
17+
else
18+
$config['ENV']['PDOTEST_DSN'] = 'dblib:host=localhost dbname=test';
19+
20+
if (false !== getenv('PDO_DBLIB_TEST_USER'))
21+
$config['ENV']['PDOTEST_USER'] = getenv('PDO_DBLIB_TEST_USER');
22+
23+
if (false !== getenv('PDO_DBLIB_TEST_PASS'))
24+
$config['ENV']['PDOTEST_PASS'] = getenv('PDO_DBLIB_TEST_PASS');
25+
26+
if (false !== getenv('PDO_DBLIB_TEST_ATTR'))
27+
$config['ENV']['PDOTEST_ATTR'] = getenv('PDO_DBLIB_TEST_ATTR');
28+
29+
return $config;

ext/pdo_dblib/tests/config.inc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
if (false !== getenv('PDO_DBLIB_TEST_DSN'))
4+
$config['ENV']['PDOTEST_DSN'] = getenv('PDO_DBLIB_TEST_DSN');
5+
else
6+
$config['ENV']['PDOTEST_DSN'] = 'dblib:host=localhost dbname=test';
7+
8+
if (false !== getenv('PDO_DBLIB_TEST_USER'))
9+
$config['ENV']['PDOTEST_USER'] = getenv('PDO_DBLIB_TEST_USER');
10+
11+
if (false !== getenv('PDO_DBLIB_TEST_PASS'))
12+
$config['ENV']['PDOTEST_PASS'] = getenv('PDO_DBLIB_TEST_PASS');
13+
14+
if (false !== getenv('PDO_DBLIB_TEST_ATTR'))
15+
$config['ENV']['PDOTEST_ATTR'] = getenv('PDO_DBLIB_TEST_ATTR');
16+
17+
foreach ($config['ENV'] as $k => $v) {
18+
putenv("$k=$v");
19+
}
20+
?>

ext/pdo_dblib/tests/pdo_dblib.phpt

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
--TEST--
2+
PDO_DBLIB: Core tests
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
16+
17+
test_transaction();
18+
test_quotedident();
19+
test_prepare();
20+
21+
function test_quotedident() {
22+
global $db;
23+
$db->query('CREATE TABLE "Test Table" ("My Field" int, "Another Field" varchar(32) not null default \'test_string\')');
24+
$db->query('INSERT INTO "Test Table" ("My Field") values(1)');
25+
$db->query('INSERT INTO "Test Table" ("My Field") values(2)');
26+
$db->query('INSERT INTO "Test Table" ("My Field") values(3)');
27+
$rs = $db->query('SELECT * FROM "Test Table"');
28+
var_dump($rs->fetchAll(PDO::FETCH_ASSOC));
29+
$db->query('DROP TABLE "Test Table"');
30+
}
31+
32+
function test_transaction() {
33+
global $db;
34+
echo "Transactions\n";
35+
36+
/*We see these rows */
37+
$db->query("CREATE table php_test(val int)");
38+
$db->beginTransaction();
39+
$db->query("INSERT INTO php_test(val) values(1)");
40+
$db->query("INSERT INTO php_test(val) values(2)");
41+
$db->query("INSERT INTO php_test(val) values(3)");
42+
$db->query("INSERT INTO php_test(val) values(4)");
43+
$db->commit();
44+
45+
/*We don't see these rows */
46+
$db->beginTransaction();
47+
$db->query("INSERT INTO php_test(val) values(5)");
48+
$db->query("INSERT INTO php_test(val) values(6)");
49+
$db->query("INSERT INTO php_test(val) values(7)");
50+
$db->query("INSERT INTO php_test(val) values(8)");
51+
$db->rollback();
52+
53+
$rs = $db->query("SELECT * FROM php_test");
54+
$rows = $rs->fetchAll(PDO::FETCH_ASSOC);
55+
var_dump($rows);
56+
57+
$db->query("DROP table php_test");
58+
59+
}
60+
61+
$db = null;
62+
63+
function test_prepare() {
64+
global $db;
65+
echo "Prepare:\n";
66+
$stmt = $db->prepare("select ic1.*
67+
from information_schema.columns ic1
68+
cross join information_schema.columns ic2
69+
cross join information_schema.columns ic3");
70+
71+
echo "Execute:\n";
72+
$x = $stmt->execute();
73+
74+
echo "Fetch\n";
75+
$n = 0;
76+
$mem = 0;
77+
while (($r = $stmt->fetch())) {
78+
if ($n ==0)
79+
$mem = memory_get_usage();
80+
if ($n % 1000 == 0) {
81+
echo($mem - memory_get_usage());
82+
}
83+
$n++;
84+
85+
}
86+
$stmt = null;
87+
}
88+
89+
echo "All done\n";
90+
?>
91+
--EXPECT--

0 commit comments

Comments
 (0)