1--TEST--
2PDO::ATTR_ORACLE_NULLS
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13    $db = MySQLPDOTest::factory();
14    MySQLPDOTest::createTestTable($db);
15
16    try {
17        $db->setAttribute(PDO::ATTR_ORACLE_NULLS, []);
18    } catch (\TypeError $e) {
19        echo $e->getMessage(), \PHP_EOL;
20    }
21    try {
22        $db->setAttribute(PDO::ATTR_ORACLE_NULLS, new stdClass());
23    } catch (\TypeError $e) {
24        echo $e->getMessage(), \PHP_EOL;
25    }
26    try {
27        $db->setAttribute(PDO::ATTR_ORACLE_NULLS, 'pdo');
28    } catch (\TypeError $e) {
29        echo $e->getMessage(), \PHP_EOL;
30    }
31
32    $db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
33    $stmt = $db->query("SELECT NULL AS z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, '" . chr(0) . " e' AS e");
34    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
35
36    $db->setAttribute(PDO::ATTR_ORACLE_NULLS, 0);
37    $stmt = $db->query("SELECT NULL AS z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, '" . chr(0) . " e' AS e");
38    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
39
40    $db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
41    $stmt = $db->query('SELECT VERSION() as _version');
42    $row = $stmt->fetch(PDO::FETCH_ASSOC);
43    if ((int)strtok($row['_version'], '.') >= 5)
44        $have_procedures = true;
45    else
46        $have_procedures = false;
47
48    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
49    $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
50
51    if ($have_procedures && (false !== $db->exec('DROP PROCEDURE IF EXISTS p')) &&
52        (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;"))) {
53        // requires MySQL 5+
54        $stmt = $db->prepare('CALL p()');
55        $stmt->execute();
56        do {
57            var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
58        } while ($stmt->nextRowset());
59
60        $stmt->execute();
61        do {
62            var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
63        } while ($stmt->nextRowset());
64
65    }
66
67    if ($have_procedures)
68        @$db->exec('DROP PROCEDURE IF EXISTS p');
69
70    print "done!";
71?>
72--EXPECTF--
73Attribute value must be of type int for selected attribute, array given
74Attribute value must be of type int for selected attribute, stdClass given
75Attribute value must be of type int for selected attribute, string given
76array(1) {
77  [0]=>
78  array(6) {
79    ["z"]=>
80    NULL
81    ["a"]=>
82    NULL
83    ["b"]=>
84    string(1) " "
85    ["c"]=>
86    NULL
87    ["d"]=>
88    string(2) " d"
89    ["e"]=>
90    string(3) "%se"
91  }
92}
93array(1) {
94  [0]=>
95  array(6) {
96    ["z"]=>
97    NULL
98    ["a"]=>
99    string(0) ""
100    ["b"]=>
101    string(1) " "
102    ["c"]=>
103    string(0) ""
104    ["d"]=>
105    string(2) " d"
106    ["e"]=>
107    string(3) "%se"
108  }
109}
110array(1) {
111  [0]=>
112  array(6) {
113    ["z"]=>
114    NULL
115    ["a"]=>
116    NULL
117    ["b"]=>
118    string(1) " "
119    ["c"]=>
120    NULL
121    ["d"]=>
122    string(2) " d"
123    ["e"]=>
124    string(2) " e"
125  }
126}
127array(0) {
128}
129array(1) {
130  [0]=>
131  array(6) {
132    ["z"]=>
133    NULL
134    ["a"]=>
135    NULL
136    ["b"]=>
137    string(1) " "
138    ["c"]=>
139    NULL
140    ["d"]=>
141    string(2) " d"
142    ["e"]=>
143    string(2) " e"
144  }
145}
146array(0) {
147}
148done!
149