Patch #2984893 - InnoDB storage page emits warning
[phpmyadmin/last10db.git] / libraries / mysql_charsets.lib.php
blobb0274d2233f10fadaa7efe94bb51af842e6d2c2c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
16 if (! PMA_cacheExists('mysql_charsets_count', true)) {
17 $res = PMA_DBI_query('SHOW CHARACTER SET;');
19 $mysql_charsets = array();
20 while ($row = PMA_DBI_fetch_assoc($res)) {
21 $mysql_charsets[] = $row['Charset'];
22 // never used
23 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
24 $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
26 PMA_DBI_free_result($res);
28 $mysql_charsets_count = count($mysql_charsets);
29 sort($mysql_charsets, SORT_STRING);
31 $mysql_collations = array_flip($mysql_charsets);
32 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
34 $res = PMA_DBI_query('SHOW COLLATION;');
35 while ($row = PMA_DBI_fetch_assoc($res)) {
36 if (!is_array($mysql_collations[$row['Charset']])) {
37 $mysql_collations[$row['Charset']] = array($row['Collation']);
38 } else {
39 $mysql_collations[$row['Charset']][] = $row['Collation'];
41 $mysql_collations_flat[] = $row['Collation'];
42 if ((isset($row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) {
43 $mysql_default_collations[$row['Charset']] = $row['Collation'];
45 //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes';
46 $mysql_collations_available[$row['Collation']] = TRUE;
47 $mysql_charsets_available[$row['Charset']] =
48 !empty($mysql_charsets_available[$row['Charset']])
49 || !empty($mysql_collations_available[$row['Collation']]);
51 PMA_DBI_free_result($res);
52 unset($res, $row);
54 $mysql_collations_count = count($mysql_collations_flat);
55 sort($mysql_collations_flat, SORT_STRING);
56 foreach ($mysql_collations AS $key => $value) {
57 sort($mysql_collations[$key], SORT_STRING);
58 reset($mysql_collations[$key]);
60 unset($key, $value);
62 PMA_cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
63 PMA_cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], true);
64 PMA_cacheSet('mysql_charsets_count', $GLOBALS['mysql_charsets_count'], true);
65 PMA_cacheSet('mysql_charsets_available', $GLOBALS['mysql_charsets_available'], true);
66 PMA_cacheSet('mysql_collations', $GLOBALS['mysql_collations'], true);
67 PMA_cacheSet('mysql_default_collations', $GLOBALS['mysql_default_collations'], true);
68 PMA_cacheSet('mysql_collations_flat', $GLOBALS['mysql_collations_flat'], true);
69 PMA_cacheSet('mysql_collations_count', $GLOBALS['mysql_collations_count'], true);
70 PMA_cacheSet('mysql_collations_available', $GLOBALS['mysql_collations_available'], true);
71 } else {
72 $GLOBALS['mysql_charsets'] = PMA_cacheGet('mysql_charsets', true);
73 $GLOBALS['mysql_charsets_descriptions'] = PMA_cacheGet('mysql_charsets_descriptions', true);
74 $GLOBALS['mysql_charsets_count'] = PMA_cacheGet('mysql_charsets_count', true);
75 $GLOBALS['mysql_charsets_available'] = PMA_cacheGet('mysql_charsets_available', true);
76 $GLOBALS['mysql_collations'] = PMA_cacheGet('mysql_collations', true);
77 $GLOBALS['mysql_default_collations'] = PMA_cacheGet('mysql_default_collations', true);
78 $GLOBALS['mysql_collations_flat'] = PMA_cacheGet('mysql_collations_flat', true);
79 $GLOBALS['mysql_collations_count'] = PMA_cacheGet('mysql_collations_count', true);
80 $GLOBALS['mysql_collations_available'] = PMA_cacheGet('mysql_collations_available', true);
83 define('PMA_CSDROPDOWN_COLLATION', 0);
84 define('PMA_CSDROPDOWN_CHARSET', 1);
86 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION,
87 $name = null, $id = null, $default = null, $label = TRUE, $indent = 0,
88 $submitOnChange = FALSE, $displayUnavailable = FALSE)
90 global $mysql_charsets, $mysql_charsets_descriptions,
91 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
93 if (empty($name)) {
94 if ($type == PMA_CSDROPDOWN_COLLATION) {
95 $name = 'collation';
96 } else {
97 $name = 'character_set';
101 $return_str = '<select xml:lang="en" dir="ltr" name="'
102 . htmlspecialchars($name) . '"'
103 . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"')
104 . ($submitOnChange ? ' onchange="this.form.submit();"' : '') . '>' . "\n";
105 if ($label) {
106 $return_str .= '<option value="">'
107 . ($type == PMA_CSDROPDOWN_COLLATION ? $GLOBALS['strCollation'] : $GLOBALS['strCharset'])
108 . '</option>' . "\n";
110 $return_str .= '<option value=""></option>' . "\n";
111 foreach ($mysql_charsets as $current_charset) {
112 if (!$mysql_charsets_available[$current_charset]) {
113 continue;
115 $current_cs_descr =
116 empty($mysql_charsets_descriptions[$current_charset])
117 ? $current_charset
118 : $mysql_charsets_descriptions[$current_charset];
120 if ($type == PMA_CSDROPDOWN_COLLATION) {
121 $return_str .= '<optgroup label="' . $current_charset
122 . '" title="' . $current_cs_descr . '">' . "\n";
123 foreach ($mysql_collations[$current_charset] as $current_collation) {
124 if (!$mysql_collations_available[$current_collation]) {
125 continue;
127 $return_str .= '<option value="' . $current_collation
128 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
129 . ($default == $current_collation ? ' selected="selected"' : '') . '>'
130 . $current_collation . '</option>' . "\n";
132 $return_str .= '</optgroup>' . "\n";
133 } else {
134 $return_str .= '<option value="' . $current_charset
135 . '" title="' . $current_cs_descr . '"'
136 . ($default == $current_charset ? ' selected="selected"' : '') . '>'
137 . $current_charset . '</option>' . "\n";
140 $return_str .= '</select>' . "\n";
142 return $return_str;
145 function PMA_generateCharsetQueryPart($collation) {
146 list($charset) = explode('_', $collation);
147 return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation);
151 * returns collation of given db
153 * @uses PMA_DBI_fetch_value()
154 * @uses PMA_DBI_select_db()
155 * @uses PMA_sqlAddSlashes()
156 * @uses $GLOBALS['db']
157 * @param string $db name of db
158 * @return string collation of $db
160 function PMA_getDbCollation($db) {
161 if ($db == 'information_schema') {
162 // We don't have to check the collation of the virtual
163 // information_schema database: We know it!
164 return 'utf8_general_ci';
167 return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
171 * returns default server collation from show variables
173 * @uses PMA_DBI_fetch_value()
174 * @return string $server_collation
176 function PMA_getServerCollation() {
177 return PMA_DBI_fetch_value(
178 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
182 * returns description for given collation
184 * @uses is_array()
185 * @uses explode()
186 * @uses count()
187 * @uses $GLOBALS['str[Languages|Sorting]']
189 * @param string $collation MySQL collation string
190 * @return string collation description
192 function PMA_getCollationDescr($collation) {
193 static $collation_cache;
195 if (!is_array($collation_cache)) {
196 $collation_cache = array();
197 } elseif (isset($collation_cache[$collation])) {
198 return $collation_cache[$collation];
201 if ($collation == 'binary') {
202 return $GLOBALS['strBinary'];
204 $parts = explode('_', $collation);
205 if (count($parts) == 1) {
206 $parts[1] = 'general';
207 } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
208 $parts[2] = $parts[1];
209 $parts[1] = 'general';
211 $descr = '';
212 switch ($parts[1]) {
213 case 'bulgarian':
214 $descr = $GLOBALS['strBulgarian'];
215 break;
216 case 'chinese':
217 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
218 $descr = $GLOBALS['strSimplifiedChinese'];
219 } elseif ($parts[0] == 'big5') {
220 $descr = $GLOBALS['strTraditionalChinese'];
222 break;
223 case 'ci':
224 $descr = $GLOBALS['strCaseInsensitive'];
225 break;
226 case 'cs':
227 $descr = $GLOBALS['strCaseSensitive'];
228 break;
229 case 'croatian':
230 $descr = $GLOBALS['strCroatian'];
231 break;
232 case 'czech':
233 $descr = $GLOBALS['strCzech'];
234 break;
235 case 'danish':
236 $descr = $GLOBALS['strDanish'];
237 break;
238 case 'english':
239 $descr = $GLOBALS['strEnglish'];
240 break;
241 case 'esperanto':
242 $descr = $GLOBALS['strEsperanto'];
243 break;
244 case 'estonian':
245 $descr = $GLOBALS['strEstonian'];
246 break;
247 case 'german1':
248 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')';
249 break;
250 case 'german2':
251 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')';
252 break;
253 case 'hungarian':
254 $descr = $GLOBALS['strHungarian'];
255 break;
256 case 'icelandic':
257 $descr = $GLOBALS['strIcelandic'];
258 break;
259 case 'japanese':
260 $descr = $GLOBALS['strJapanese'];
261 break;
262 case 'latvian':
263 $descr = $GLOBALS['strLatvian'];
264 break;
265 case 'lithuanian':
266 $descr = $GLOBALS['strLithuanian'];
267 break;
268 case 'korean':
269 $descr = $GLOBALS['strKorean'];
270 break;
271 case 'persian':
272 $descr = $GLOBALS['strPersian'];
273 break;
274 case 'polish':
275 $descr = $GLOBALS['strPolish'];
276 break;
277 case 'roman':
278 $descr = $GLOBALS['strWestEuropean'];
279 break;
280 case 'romanian':
281 $descr = $GLOBALS['strRomanian'];
282 break;
283 case 'slovak':
284 $descr = $GLOBALS['strSlovak'];
285 break;
286 case 'slovenian':
287 $descr = $GLOBALS['strSlovenian'];
288 break;
289 case 'spanish':
290 $descr = $GLOBALS['strSpanish'];
291 break;
292 case 'spanish2':
293 $descr = $GLOBALS['strTraditionalSpanish'];
294 break;
295 case 'swedish':
296 $descr = $GLOBALS['strSwedish'];
297 break;
298 case 'thai':
299 $descr = $GLOBALS['strThai'];
300 break;
301 case 'turkish':
302 $descr = $GLOBALS['strTurkish'];
303 break;
304 case 'ukrainian':
305 $descr = $GLOBALS['strUkrainian'];
306 break;
307 case 'unicode':
308 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
309 break;
310 case 'bin':
311 $is_bin = TRUE;
312 case 'general':
313 switch ($parts[0]) {
314 // Unicode charsets
315 case 'ucs2':
316 case 'utf8':
317 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
318 break;
319 // West European charsets
320 case 'ascii':
321 case 'cp850':
322 case 'dec8':
323 case 'hp8':
324 case 'latin1':
325 case 'macroman':
326 $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
327 break;
328 // Central European charsets
329 case 'cp1250':
330 case 'cp852':
331 case 'latin2':
332 case 'macce':
333 $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
334 break;
335 // Russian charsets
336 case 'cp866':
337 case 'koi8r':
338 $descr = $GLOBALS['strRussian'];
339 break;
340 // Simplified Chinese charsets
341 case 'gb2312':
342 case 'gbk':
343 $descr = $GLOBALS['strSimplifiedChinese'];
344 break;
345 // Japanese charsets
346 case 'sjis':
347 case 'ujis':
348 case 'cp932':
349 case 'eucjpms':
350 $descr = $GLOBALS['strJapanese'];
351 break;
352 // Baltic charsets
353 case 'cp1257':
354 case 'latin7':
355 $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
356 break;
357 // Other
358 case 'armscii8':
359 case 'armscii':
360 $descr = $GLOBALS['strArmenian'];
361 break;
362 case 'big5':
363 $descr = $GLOBALS['strTraditionalChinese'];
364 break;
365 case 'cp1251':
366 $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
367 break;
368 case 'cp1256':
369 $descr = $GLOBALS['strArabic'];
370 break;
371 case 'euckr':
372 $descr = $GLOBALS['strKorean'];
373 break;
374 case 'hebrew':
375 $descr = $GLOBALS['strHebrew'];
376 break;
377 case 'geostd8':
378 $descr = $GLOBALS['strGeorgian'];
379 break;
380 case 'greek':
381 $descr = $GLOBALS['strGreek'];
382 break;
383 case 'keybcs2':
384 $descr = $GLOBALS['strCzechSlovak'];
385 break;
386 case 'koi8u':
387 $descr = $GLOBALS['strUkrainian'];
388 break;
389 case 'latin5':
390 $descr = $GLOBALS['strTurkish'];
391 break;
392 case 'swe7':
393 $descr = $GLOBALS['strSwedish'];
394 break;
395 case 'tis620':
396 $descr = $GLOBALS['strThai'];
397 break;
398 default:
399 $descr = $GLOBALS['strUnknown'];
400 break;
402 if (!empty($is_bin)) {
403 $descr .= ', ' . $GLOBALS['strBinary'];
405 break;
406 default: $descr = $GLOBALS['strUnknown'];
408 if (!empty($parts[2])) {
409 if ($parts[2] == 'ci') {
410 $descr .= ', ' . $GLOBALS['strCaseInsensitive'];
411 } elseif ($parts[2] == 'cs') {
412 $descr .= ', ' . $GLOBALS['strCaseSensitive'];
416 $collation_cache[$collation] = $descr;
417 return $descr;