1--TEST--
2PDO::ATTR_ORACLE_NULLS
3--SKIPIF--
4<?php
5require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8?>
9--FILE--
10<?php
11	require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
12	$db = MySQLPDOTest::factory();
13	MySQLPDOTest::createTestTable($db);
14
15	$tmp = array();
16	if (false !== @$db->setAttribute(PDO::ATTR_ORACLE_NULLS, $tmp))
17		printf("[001] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...\n");
18
19	$tmp = new stdClass();
20	if (false !== @$db->setAttribute(PDO::ATTR_ORACLE_NULLS, $tmp));
21		printf("[002] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...\n");
22
23	if (false !== @$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 'pdo'))
24		printf("[003] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...\n");
25
26	$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
27	$stmt = $db->query("SELECT NULL AS z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, '" . chr(0) . " e' AS e");
28	var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
29
30	$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 0);
31	$stmt = $db->query("SELECT NULL AS z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, '" . chr(0) . " e' AS e");
32	var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
33
34	$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
35	$stmt = $db->query('SELECT VERSION() as _version');
36	$row = $stmt->fetch(PDO::FETCH_ASSOC);
37	if ((int)substr($row['_version'], 0, 1) >= 5)
38		$have_procedures = true;
39	else
40		$have_procedures = false;
41
42	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
43	$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
44
45	if ($have_procedures && (false !== $db->exec('DROP PROCEDURE IF EXISTS p')) &&
46		(false !== $db->exec("CREATE PROCEDURE p() BEGIN SELECT NULL as z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, ' e' AS e; END;"))) {
47		// requires MySQL 5+
48		$stmt = $db->prepare('CALL p()');
49		$stmt->execute();
50		$expected = array(
51			array(
52				"z" => NULL,
53				"a" => NULL,
54				"b" => " ",
55				"c" => NULL,
56				"d" => " d",
57				"e" => " e",
58			),
59		);
60		do {
61			$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
62			if ($tmp != $expected) {
63				printf("[004] Expecting %s got %s\n",
64					var_export($expected, true), var_export($tmp, true));
65			}
66		} while ($stmt->nextRowset());
67
68		$stmt->execute();
69		do {
70			$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
71			if ($tmp != $expected) {
72				printf("[005] Expecting %s got %s\n",
73					var_export($expected, true), var_export($tmp, true));
74			}
75		} while ($stmt->nextRowset());
76
77	}
78
79	if ($have_procedures)
80		@$db->exec('DROP PROCEDURE IF EXISTS p');
81
82	print "done!";
83?>
84--EXPECTF--
85[002] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...
86[003] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...
87array(1) {
88  [0]=>
89  array(6) {
90    ["z"]=>
91    NULL
92    ["a"]=>
93    NULL
94    ["b"]=>
95    string(1) " "
96    ["c"]=>
97    NULL
98    ["d"]=>
99    string(2) " d"
100    ["e"]=>
101    string(3) "%se"
102  }
103}
104array(1) {
105  [0]=>
106  array(6) {
107    ["z"]=>
108    NULL
109    ["a"]=>
110    string(0) ""
111    ["b"]=>
112    string(1) " "
113    ["c"]=>
114    string(0) ""
115    ["d"]=>
116    string(2) " d"
117    ["e"]=>
118    string(3) "%se"
119  }
120}
121done!
122