1--TEST-- 2PDO::ATTR_CASE 3--SKIPIF-- 4<?php 5require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc'); 6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 7MySQLPDOTest::skip(); 8$db = MySQLPDOTest::factory(); 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 $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 __DIR__ . '/mysql_pdo_test.inc'; 90MySQLPDOTest::dropTestTable(); 91?> 92--EXPECT-- 93string(15) "PDO::CASE_LOWER" 94array(2) { 95 [0]=> 96 array(6) { 97 ["id"]=> 98 string(1) "1" 99 [0]=> 100 string(1) "1" 101 ["id_upper"]=> 102 string(1) "1" 103 [1]=> 104 string(1) "1" 105 ["label"]=> 106 string(1) "a" 107 [2]=> 108 string(1) "a" 109 } 110 [1]=> 111 array(6) { 112 ["id"]=> 113 string(1) "2" 114 [0]=> 115 string(1) "2" 116 ["id_upper"]=> 117 string(1) "2" 118 [1]=> 119 string(1) "2" 120 ["label"]=> 121 string(1) "b" 122 [2]=> 123 string(1) "b" 124 } 125} 126array(2) { 127 [0]=> 128 array(10) { 129 ["id"]=> 130 string(1) "1" 131 [0]=> 132 string(1) "1" 133 ["id_upper"]=> 134 string(1) "1" 135 [1]=> 136 string(1) "1" 137 ["label"]=> 138 string(1) "a" 139 [2]=> 140 string(1) "a" 141 ["mixed"]=> 142 NULL 143 [3]=> 144 NULL 145 ["myupper"]=> 146 NULL 147 [4]=> 148 NULL 149 } 150 [1]=> 151 array(10) { 152 ["id"]=> 153 string(1) "2" 154 [0]=> 155 string(1) "2" 156 ["id_upper"]=> 157 string(1) "2" 158 [1]=> 159 string(1) "2" 160 ["label"]=> 161 string(1) "b" 162 [2]=> 163 string(1) "b" 164 ["mixed"]=> 165 NULL 166 [3]=> 167 NULL 168 ["myupper"]=> 169 NULL 170 [4]=> 171 NULL 172 } 173} 174array(1) { 175 [0]=> 176 array(10) { 177 ["ID"]=> 178 string(1) "1" 179 [0]=> 180 string(1) "1" 181 ["LABEL"]=> 182 string(1) "a" 183 [1]=> 184 string(1) "a" 185 ["MIXED"]=> 186 NULL 187 [2]=> 188 NULL 189 ["MYUPPER"]=> 190 NULL 191 [3]=> 192 NULL 193 ["LOWER"]=> 194 NULL 195 [4]=> 196 NULL 197 } 198} 199array(1) { 200 [0]=> 201 array(10) { 202 ["id"]=> 203 string(1) "1" 204 [0]=> 205 string(1) "1" 206 ["label"]=> 207 string(1) "a" 208 [1]=> 209 string(1) "a" 210 ["MiXeD"]=> 211 NULL 212 [2]=> 213 NULL 214 ["MYUPPER"]=> 215 NULL 216 [3]=> 217 NULL 218 ["ID"]=> 219 string(1) "1" 220 [4]=> 221 string(1) "1" 222 } 223} 224done! 225