Translation update done using Pootle.
[phpmyadmin.git] / libraries / StorageEngine.class.php
blobe41f7be93c4ea9f8c14ed7b2e8a6018d68f52acf
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Library for extracting information about the available storage engines
6 * @package PhpMyAdmin
7 */
9 /**
10 * defines
12 define('PMA_ENGINE_SUPPORT_NO', 0);
13 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
14 define('PMA_ENGINE_SUPPORT_YES', 2);
15 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
17 define('PMA_ENGINE_DETAILS_TYPE_PLAINTEXT', 0);
18 define('PMA_ENGINE_DETAILS_TYPE_SIZE', 1);
19 define('PMA_ENGINE_DETAILS_TYPE_NUMERIC', 2); //Has no effect yet...
20 define('PMA_ENGINE_DETAILS_TYPE_BOOLEAN', 3); // 'ON' or 'OFF'
22 /**
23 * base Storage Engine Class
24 * @package PhpMyAdmin
26 class PMA_StorageEngine
28 /**
29 * @var string engine name
31 var $engine = 'dummy';
33 /**
34 * @var string engine title/description
36 var $title = 'PMA Dummy Engine Class';
38 /**
39 * @var string engine lang description
41 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
43 /**
44 * @var integer engine supported by current server
46 var $support = PMA_ENGINE_SUPPORT_NO;
48 /**
49 * returns array of storage engines
51 * @static
52 * @staticvar array $storage_engines storage engines
53 * @access public
54 * @return array of storage engines
56 static public function getStorageEngines()
58 static $storage_engines = null;
60 if (null == $storage_engines) {
61 if (PMA_DRIZZLE) {
62 $sql = "SELECT
63 p.plugin_name AS Engine,
64 (CASE
65 WHEN p.plugin_name = @@storage_engine THEN 'DEFAULT'
66 WHEN p.is_active THEN 'YES'
67 ELSE 'DISABLED' END) AS Support,
68 m.module_description AS Comment
69 FROM data_dictionary.plugins p
70 JOIN data_dictionary.modules m USING (module_name)
71 WHERE p.plugin_type = 'StorageEngine'
72 AND p.plugin_name NOT IN ('FunctionEngine', 'schema')";
73 $storage_engines = PMA_DBI_fetch_result($sql, 'Engine');
74 } else {
75 $storage_engines = PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
79 return $storage_engines;
82 /**
83 * returns HTML code for storage engine select box
85 * @param string $name The name of the select form element
86 * @param string $id The ID of the form field
87 * @param string $selected The selected engine
88 * @param boolean $offerUnavailableEngines Should unavailable storage engines be offered?
90 * @static
91 * @return string html selectbox
93 static public function getHtmlSelect($name = 'engine', $id = null,
94 $selected = null, $offerUnavailableEngines = false)
96 $selected = strtolower($selected);
97 $output = '<select name="' . $name . '"'
98 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
100 foreach (PMA_StorageEngine::getStorageEngines() as $key => $details) {
101 // Don't show PERFORMANCE_SCHEMA engine (MySQL 5.5)
102 // Don't show MyISAM for Drizzle (allowed only for temporary tables)
103 if (! $offerUnavailableEngines
104 && ($details['Support'] == 'NO'
105 || $details['Support'] == 'DISABLED'
106 || $details['Engine'] == 'PERFORMANCE_SCHEMA')
107 || (PMA_DRIZZLE && $details['Engine'] == 'MyISAM')
109 continue;
112 $output .= ' <option value="' . htmlspecialchars($key). '"'
113 . (empty($details['Comment'])
114 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
115 . (strtolower($key) == $selected || (empty($selected) && $details['Support'] == 'DEFAULT')
116 ? ' selected="selected"' : '') . '>' . "\n"
117 . ' ' . htmlspecialchars($details['Engine']) . "\n"
118 . ' </option>' . "\n";
120 $output .= '</select>' . "\n";
121 return $output;
125 * public static final PMA_StorageEngine getEngine()
127 * Loads the corresponding engine plugin, if available.
129 * @param string $engine The engine ID
131 * @return object The engine plugin
133 static public function getEngine($engine)
135 $engine = str_replace('/', '', str_replace('.', '', $engine));
136 $engine_lowercase_filename = strtolower($engine);
137 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
138 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php'
140 $class_name = 'PMA_StorageEngine_' . $engine;
141 $engine_object = new $class_name($engine);
142 } else {
143 $engine_object = new PMA_StorageEngine($engine);
145 return $engine_object;
149 * return true if given engine name is supported/valid, otherwise false
151 * @param string $engine name of engine
153 * @static
154 * @return boolean whether $engine is valid or not
156 static public function isValid($engine)
158 if ($engine == "PBMS") {
159 return true;
161 $storage_engines = PMA_StorageEngine::getStorageEngines();
162 return isset($storage_engines[$engine]);
166 * returns as HTML table of the engine's server variables
168 * @return string The table that was generated based on the retrieved information
170 function getHtmlVariables()
172 $odd_row = false;
173 $ret = '';
175 foreach ($this->getVariablesStatus() as $details) {
176 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
177 . ' <td>' . "\n";
178 if (! empty($details['desc'])) {
179 $ret .= ' ' . PMA_showHint($details['desc']) . "\n";
181 $ret .= ' </td>' . "\n"
182 . ' <th>' . htmlspecialchars($details['title']) . '</th>' . "\n"
183 . ' <td class="value">';
184 switch ($details['type']) {
185 case PMA_ENGINE_DETAILS_TYPE_SIZE:
186 $parsed_size = $this->resolveTypeSize($details['value']);
187 $ret .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
188 unset($parsed_size);
189 break;
190 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
191 $ret .= PMA_formatNumber($details['value']) . ' ';
192 break;
193 default:
194 $ret .= htmlspecialchars($details['value']) . ' ';
196 $ret .= '</td>' . "\n"
197 . '</tr>' . "\n";
198 $odd_row = ! $odd_row;
201 if (! $ret) {
202 $ret = '<p>' . "\n"
203 . ' ' . __('There is no detailed status information available for this storage engine.') . "\n"
204 . '</p>' . "\n";
205 } else {
206 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
209 return $ret;
213 * returns the engine specific handling for
214 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
216 * This function should be overridden when
217 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
218 * handled differently for a particular engine.
220 * @return string the formatted value and its unit
222 function resolveTypeSize($value)
224 return PMA_formatByteDown($value);
228 * returns array with detailed info about engine specific server variables
230 * @return array with detailed info about specific engine server variables
232 function getVariablesStatus()
234 $variables = $this->getVariables();
235 $like = $this->getVariablesLikePattern();
237 if ($like) {
238 $like = " LIKE '" . $like . "' ";
239 } else {
240 $like = '';
243 $mysql_vars = array();
245 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
246 $res = PMA_DBI_query($sql_query);
247 while ($row = PMA_DBI_fetch_assoc($res)) {
248 if (isset($variables[$row['Variable_name']])) {
249 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
250 } elseif (! $like
251 && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0) {
252 continue;
254 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
256 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
257 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
260 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
261 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
264 PMA_DBI_free_result($res);
266 return $mysql_vars;
269 function engine_init() {}
272 * Constructor
274 * @param string $engine The engine ID
276 function __construct($engine)
278 $storage_engines = PMA_StorageEngine::getStorageEngines();
279 if (! empty($storage_engines[$engine])) {
280 $this->engine = $engine;
281 $this->title = $storage_engines[$engine]['Engine'];
282 $this->comment
283 = (isset($storage_engines[$engine]['Comment'])
284 ? $storage_engines[$engine]['Comment']
285 : '');
286 switch ($storage_engines[$engine]['Support']) {
287 case 'DEFAULT':
288 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
289 break;
290 case 'YES':
291 $this->support = PMA_ENGINE_SUPPORT_YES;
292 break;
293 case 'DISABLED':
294 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
295 break;
296 case 'NO':
297 default:
298 $this->support = PMA_ENGINE_SUPPORT_NO;
300 } else {
301 $this->engine_init();
306 * public String getTitle()
308 * Reveals the engine's title
310 * @return string The title
312 function getTitle()
314 return $this->title;
318 * public String getComment()
320 * Fetches the server's comment about this engine
322 * @return string The comment
324 function getComment()
326 return $this->comment;
330 * public String getSupportInformationMessage()
332 * @return string The localized message.
334 function getSupportInformationMessage()
336 switch ($this->support) {
337 case PMA_ENGINE_SUPPORT_DEFAULT:
338 $message = __('%s is the default storage engine on this MySQL server.');
339 break;
340 case PMA_ENGINE_SUPPORT_YES:
341 $message = __('%s is available on this MySQL server.');
342 break;
343 case PMA_ENGINE_SUPPORT_DISABLED:
344 $message = __('%s has been disabled for this MySQL server.');
345 break;
346 case PMA_ENGINE_SUPPORT_NO:
347 default:
348 $message = __('This MySQL server does not support the %s storage engine.');
350 return sprintf($message, htmlspecialchars($this->title));
354 * public string[][] getVariables()
356 * Generates a list of MySQL variables that provide information about this
357 * engine. This function should be overridden when extending this class
358 * for a particular engine.
360 * @abstract
361 * @return Array The list of variables.
363 function getVariables()
365 return array();
369 * returns string with filename for the MySQL helppage
370 * about this storage engne
372 * @return string mysql helppage filename
374 function getMysqlHelpPage()
376 return $this->engine . '-storage-engine';
380 * public string getVariablesLikePattern()
382 * @abstract
383 * @return string SQL query LIKE pattern
385 function getVariablesLikePattern()
387 return false;
391 * public String[] getInfoPages()
393 * Returns a list of available information pages with labels
395 * @abstract
396 * @return array The list
398 function getInfoPages()
400 return array();
404 * public String getPage()
406 * Generates the requested information page
408 * @param string $id The page ID
410 * @abstract
411 * @return string The page
412 * boolean or false on error.
414 function getPage($id)
416 return false;