1--TEST--
2PDO::ATTR_CASE
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8$db = MySQLPDOTest::factory();
9?>
10--FILE--
11<?php
12	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13	$db = MySQLPDOTest::factory();
14	MySQLPDOTest::createTestTable($db);
15
16	$default =  $db->getAttribute(PDO::ATTR_CASE);
17	$known = array(
18		PDO::CASE_LOWER => 'PDO::CASE_LOWER',
19		PDO::CASE_UPPER => 'PDO::CASE_UPPER',
20		PDO::CASE_NATURAL => 'PDO::CASE_NATURAL'
21	);
22	if (!isset($known[$default]))
23		printf("[001] getAttribute(PDO::ATTR_CASE) returns unknown value '%s'\n",
24			var_export($default, true));
25	else
26		var_dump($known[$default]);
27
28	// lets see what the default is...
29	if (!is_object($stmt = $db->query("SELECT id, id AS 'ID_UPPER', label FROM test ORDER BY id ASC LIMIT 2")))
30		printf("[002] %s - %s\n",
31			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
32
33	var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
34
35	if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER))
36		printf("[003] Cannot set PDO::ATTR_CASE = PDO::CASE_LOWER, %s - %s\n",
37			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
38
39	if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_LOWER)
40		printf("[004] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n",
41			var_export($tmp, true));
42
43	if (true === $db->exec('ALTER TABLE test ADD MiXeD CHAR(1)'))
44		printf("[005] Cannot add column %s - %s\n",
45			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
46
47	if (false === $db->exec('ALTER TABLE test ADD MYUPPER CHAR(1)'))
48		printf("[006] Cannot add column %s - %s\n",
49			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
50
51	if (!is_object($stmt = $db->query("SELECT id, id AS 'ID_UPPER', label, MiXeD, MYUPPER FROM test ORDER BY id ASC LIMIT 2")))
52		printf("[007] %s - %s\n",
53			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
54
55	var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
56
57	if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER))
58		printf("[008] Cannot set PDO::ATTR_CASE = PDO::CASE_UPPER %s - %s\n",
59			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
60
61	if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_UPPER)
62		printf("[009] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n",
63			var_export($tmp, true));
64
65	if (!is_object($stmt = $db->query("SELECT id, label, MiXeD, MYUPPER, MYUPPER AS 'lower' FROM test ORDER BY id ASC LIMIT 1")))
66		printf("[010] %s - %s\n",
67			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
68
69	var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
70
71	if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL))
72		printf("[011] Cannot set PDO::ATTR_CASE = PDO::CASE_NATURAL %s - %s\n",
73			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
74
75	if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_NATURAL)
76		printf("[012] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n",
77			var_export($tmp, true));
78
79	if (!is_object($stmt = $db->query("SELECT id, label, MiXeD, MYUPPER, id AS 'ID' FROM test ORDER BY id ASC LIMIT 1")))
80		printf("[013] %s - %s\n",
81			var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
82
83	var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
84
85	print "done!";
86?>
87--CLEAN--
88<?php
89require dirname(__FILE__) . '/mysql_pdo_test.inc';
90MySQLPDOTest::dropTestTable();
91?>
92--EXPECTF--
93%unicode|string%(15) "PDO::CASE_LOWER"
94array(2) {
95  [0]=>
96  array(6) {
97    [%u|b%"id"]=>
98    %unicode|string%(1) "1"
99    [0]=>
100    %unicode|string%(1) "1"
101    [%u|b%"id_upper"]=>
102    %unicode|string%(1) "1"
103    [1]=>
104    %unicode|string%(1) "1"
105    [%u|b%"label"]=>
106    %unicode|string%(1) "a"
107    [2]=>
108    %unicode|string%(1) "a"
109  }
110  [1]=>
111  array(6) {
112    [%u|b%"id"]=>
113    %unicode|string%(1) "2"
114    [0]=>
115    %unicode|string%(1) "2"
116    [%u|b%"id_upper"]=>
117    %unicode|string%(1) "2"
118    [1]=>
119    %unicode|string%(1) "2"
120    [%u|b%"label"]=>
121    %unicode|string%(1) "b"
122    [2]=>
123    %unicode|string%(1) "b"
124  }
125}
126array(2) {
127  [0]=>
128  array(10) {
129    [%u|b%"id"]=>
130    %unicode|string%(1) "1"
131    [0]=>
132    %unicode|string%(1) "1"
133    [%u|b%"id_upper"]=>
134    %unicode|string%(1) "1"
135    [1]=>
136    %unicode|string%(1) "1"
137    [%u|b%"label"]=>
138    %unicode|string%(1) "a"
139    [2]=>
140    %unicode|string%(1) "a"
141    [%u|b%"mixed"]=>
142    NULL
143    [3]=>
144    NULL
145    [%u|b%"myupper"]=>
146    NULL
147    [4]=>
148    NULL
149  }
150  [1]=>
151  array(10) {
152    [%u|b%"id"]=>
153    %unicode|string%(1) "2"
154    [0]=>
155    %unicode|string%(1) "2"
156    [%u|b%"id_upper"]=>
157    %unicode|string%(1) "2"
158    [1]=>
159    %unicode|string%(1) "2"
160    [%u|b%"label"]=>
161    %unicode|string%(1) "b"
162    [2]=>
163    %unicode|string%(1) "b"
164    [%u|b%"mixed"]=>
165    NULL
166    [3]=>
167    NULL
168    [%u|b%"myupper"]=>
169    NULL
170    [4]=>
171    NULL
172  }
173}
174array(1) {
175  [0]=>
176  array(10) {
177    [%u|b%"ID"]=>
178    %unicode|string%(1) "1"
179    [0]=>
180    %unicode|string%(1) "1"
181    [%u|b%"LABEL"]=>
182    %unicode|string%(1) "a"
183    [1]=>
184    %unicode|string%(1) "a"
185    [%u|b%"MIXED"]=>
186    NULL
187    [2]=>
188    NULL
189    [%u|b%"MYUPPER"]=>
190    NULL
191    [3]=>
192    NULL
193    [%u|b%"LOWER"]=>
194    NULL
195    [4]=>
196    NULL
197  }
198}
199array(1) {
200  [0]=>
201  array(10) {
202    [%u|b%"id"]=>
203    %unicode|string%(1) "1"
204    [0]=>
205    %unicode|string%(1) "1"
206    [%u|b%"label"]=>
207    %unicode|string%(1) "a"
208    [1]=>
209    %unicode|string%(1) "a"
210    [%u|b%"MiXeD"]=>
211    NULL
212    [2]=>
213    NULL
214    [%u|b%"MYUPPER"]=>
215    NULL
216    [3]=>
217    NULL
218    [%u|b%"ID"]=>
219    %unicode|string%(1) "1"
220    [4]=>
221    %unicode|string%(1) "1"
222  }
223}
224done!