Skip to content

Commit 79efa22

Browse files
committed
ext/pdo: Shared unit test for PDO::ATTR_FETCH_TABLE_NAMES
In addition to the MySQL specific one.
1 parent 7fb0e48 commit 79efa22

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
PDO Common: PDO::ATTR_FETCH_TABLE_NAMES
3+
--EXTENSIONS--
4+
pdo
5+
--SKIPIF--
6+
<?php
7+
$dir = getenv('REDIR_TEST_DIR');
8+
if (false == $dir) die('skip no driver');
9+
if (!strncasecmp(getenv('PDOTEST_DSN'), 'dblib', strlen('dblib'))) die('skip SQL Server does not return this information normally');
10+
// SQL Server and Db2i drivers don't seem to return this info
11+
if (!strncasecmp(getenv('PDOTEST_DSN'), 'odbc', strlen('odbc'))) die('skip SQL Server does not return this information normally');
12+
require_once $dir . 'pdo_test.inc';
13+
PDOTest::skip();
14+
?>
15+
--FILE--
16+
<?php
17+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
18+
$db = PDOTest::factory();
19+
20+
$table = 'pdo_attr_fetch_table_names';
21+
$db->exec("CREATE TABLE {$table} (id INT, label CHAR(1), PRIMARY KEY(id))");
22+
$db->exec("INSERT INTO {$table} (id, label) VALUES (1, 'a')");
23+
24+
$db->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, true);
25+
var_dump($db->getAttribute(PDO::ATTR_FETCH_TABLE_NAMES));
26+
$stmt = $db->query("SELECT label FROM {$table}");
27+
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)[0]);
28+
$stmt->closeCursor();
29+
30+
$db->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, false);
31+
var_dump($db->getAttribute(PDO::ATTR_FETCH_TABLE_NAMES));
32+
$stmt = $db->query("SELECT label FROM {$table}");
33+
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)[0]);
34+
$stmt->closeCursor();
35+
36+
print "done!";
37+
?>
38+
--CLEAN--
39+
<?php
40+
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
41+
$db = PDOTest::factory();
42+
$db->query('DROP TABLE IF EXISTS pdo_attr_fetch_table_names');
43+
?>
44+
--EXPECT--
45+
bool(true)
46+
array(1) {
47+
["pdo_attr_fetch_table_names.label"]=>
48+
string(1) "a"
49+
}
50+
bool(false)
51+
array(1) {
52+
["label"]=>
53+
string(1) "a"
54+
}
55+
done!

0 commit comments

Comments
 (0)