2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Library for extracting information about the available storage engines
8 if (! defined('PHPMYADMIN')) {
15 define('PMA_ENGINE_SUPPORT_NO', 0);
16 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
17 define('PMA_ENGINE_SUPPORT_YES', 2);
18 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
20 define('PMA_ENGINE_DETAILS_TYPE_PLAINTEXT', 0);
21 define('PMA_ENGINE_DETAILS_TYPE_SIZE', 1);
22 define('PMA_ENGINE_DETAILS_TYPE_NUMERIC', 2); //Has no effect yet...
23 define('PMA_ENGINE_DETAILS_TYPE_BOOLEAN', 3); // 'ON' or 'OFF'
26 * Base Storage Engine Class
30 class PMA_StorageEngine
33 * @var string engine name
35 var $engine = 'dummy';
38 * @var string engine title/description
40 var $title = 'PMA Dummy Engine Class';
43 * @var string engine lang description
46 = 'If you read this text inside phpMyAdmin, something went wrong...';
49 * @var integer engine supported by current server
51 var $support = PMA_ENGINE_SUPPORT_NO
;
54 * returns array of storage engines
57 * @staticvar array $storage_engines storage engines
59 * @return array of storage engines
61 static public function getStorageEngines()
63 static $storage_engines = null;
65 if (null == $storage_engines) {
68 p.plugin_name AS Engine,
70 WHEN p.plugin_name = @@storage_engine THEN 'DEFAULT'
71 WHEN p.is_active THEN 'YES'
72 ELSE 'DISABLED' END) AS Support,
73 m.module_description AS Comment
74 FROM data_dictionary.plugins p
75 JOIN data_dictionary.modules m USING (module_name)
76 WHERE p.plugin_type = 'StorageEngine'
77 AND p.plugin_name NOT IN ('FunctionEngine', 'schema')";
78 $storage_engines = $GLOBALS['dbi']->fetchResult($sql, 'Engine');
81 = $GLOBALS['dbi']->fetchResult('SHOW STORAGE ENGINES', 'Engine');
85 return $storage_engines;
89 * returns HTML code for storage engine select box
91 * @param string $name The name of the select form element
92 * @param string $id The ID of the form field
93 * @param string $selected The selected engine
94 * @param boolean $offerUnavailableEngines Should unavailable storage
98 * @return string html selectbox
100 static public function getHtmlSelect(
101 $name = 'engine', $id = null,
102 $selected = null, $offerUnavailableEngines = false
104 $selected = strtolower($selected);
105 $output = '<select name="' . $name . '"'
106 . (empty($id) ?
'' : ' id="' . $id . '"') . '>' . "\n";
108 foreach (PMA_StorageEngine
::getStorageEngines() as $key => $details) {
109 // Don't show PERFORMANCE_SCHEMA engine (MySQL 5.5)
110 // Don't show MyISAM for Drizzle (allowed only for temporary tables)
111 if (! $offerUnavailableEngines
112 && ($details['Support'] == 'NO'
113 ||
$details['Support'] == 'DISABLED'
114 ||
$details['Engine'] == 'PERFORMANCE_SCHEMA')
115 ||
(PMA_DRIZZLE
&& $details['Engine'] == 'MyISAM')
120 $output .= ' <option value="' . htmlspecialchars($key). '"'
121 . (empty($details['Comment'])
122 ?
'' : ' title="' . htmlspecialchars($details['Comment']) . '"')
123 . (strtolower($key) == $selected
124 ||
(empty($selected) && $details['Support'] == 'DEFAULT')
125 ?
' selected="selected"' : '')
127 . ' ' . htmlspecialchars($details['Engine']) . "\n"
128 . ' </option>' . "\n";
130 $output .= '</select>' . "\n";
135 * public static final PMA_StorageEngine getEngine()
137 * Loads the corresponding engine plugin, if available.
139 * @param string $engine The engine ID
141 * @return object The engine plugin
143 static public function getEngine($engine)
145 $engine = str_replace('/', '', str_replace('.', '', $engine));
146 $filename = './libraries/engines/' . strtolower($engine) . '.lib.php';
147 if (file_exists($filename) && include_once $filename) {
148 $class_name = 'PMA_StorageEngine_' . $engine;
149 $engine_object = new $class_name($engine);
151 $engine_object = new PMA_StorageEngine($engine);
153 return $engine_object;
157 * return true if given engine name is supported/valid, otherwise false
159 * @param string $engine name of engine
162 * @return boolean whether $engine is valid or not
164 static public function isValid($engine)
166 if ($engine == "PBMS") {
169 $storage_engines = PMA_StorageEngine
::getStorageEngines();
170 return isset($storage_engines[$engine]);
174 * returns as HTML table of the engine's server variables
176 * @return string The table that was generated based on the retrieved
179 function getHtmlVariables()
184 foreach ($this->getVariablesStatus() as $details) {
185 $ret .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
187 if (! empty($details['desc'])) {
189 . PMA_Util
::showHint($details['desc'])
192 $ret .= ' </td>' . "\n"
193 . ' <th>' . htmlspecialchars($details['title']) . '</th>'
195 . ' <td class="value">';
196 switch ($details['type']) {
197 case PMA_ENGINE_DETAILS_TYPE_SIZE
:
198 $parsed_size = $this->resolveTypeSize($details['value']);
199 $ret .= $parsed_size[0] . ' ' . $parsed_size[1];
202 case PMA_ENGINE_DETAILS_TYPE_NUMERIC
:
203 $ret .= PMA_Util
::formatNumber($details['value']) . ' ';
206 $ret .= htmlspecialchars($details['value']) . ' ';
208 $ret .= '</td>' . "\n"
210 $odd_row = ! $odd_row;
216 . __('There is no detailed status information available for this storage engine.')
220 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
227 * Returns the engine specific handling for
228 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
230 * This function should be overridden when
231 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
232 * handled differently for a particular engine.
234 * @param integer $value Value to format
236 * @return string the formatted value and its unit
238 function resolveTypeSize($value)
240 return PMA_Util
::formatByteDown($value);
244 * returns array with detailed info about engine specific server variables
246 * @return array with detailed info about specific engine server variables
248 function getVariablesStatus()
250 $variables = $this->getVariables();
251 $like = $this->getVariablesLikePattern();
254 $like = " LIKE '" . $like . "' ";
259 $mysql_vars = array();
261 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
262 $res = $GLOBALS['dbi']->query($sql_query);
263 while ($row = $GLOBALS['dbi']->fetchAssoc($res)) {
264 if (isset($variables[$row['Variable_name']])) {
265 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
267 && strpos(strtolower($row['Variable_name']), strtolower($this->engine
)) !== 0
271 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
273 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
274 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
277 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
278 $mysql_vars[$row['Variable_name']]['type']
279 = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
;
282 $GLOBALS['dbi']->freeResult($res);
290 * @param string $engine The engine ID
292 function __construct($engine)
294 $storage_engines = PMA_StorageEngine
::getStorageEngines();
295 if (! empty($storage_engines[$engine])) {
296 $this->engine
= $engine;
297 $this->title
= $storage_engines[$engine]['Engine'];
299 = (isset($storage_engines[$engine]['Comment'])
300 ?
$storage_engines[$engine]['Comment']
302 switch ($storage_engines[$engine]['Support']) {
304 $this->support
= PMA_ENGINE_SUPPORT_DEFAULT
;
307 $this->support
= PMA_ENGINE_SUPPORT_YES
;
310 $this->support
= PMA_ENGINE_SUPPORT_DISABLED
;
314 $this->support
= PMA_ENGINE_SUPPORT_NO
;
320 * public String getTitle()
322 * Reveals the engine's title
324 * @return string The title
332 * public String getComment()
334 * Fetches the server's comment about this engine
336 * @return string The comment
338 function getComment()
340 return $this->comment
;
344 * public String getSupportInformationMessage()
346 * @return string The localized message.
348 function getSupportInformationMessage()
350 switch ($this->support
) {
351 case PMA_ENGINE_SUPPORT_DEFAULT
:
352 $message = __('%s is the default storage engine on this MySQL server.');
354 case PMA_ENGINE_SUPPORT_YES
:
355 $message = __('%s is available on this MySQL server.');
357 case PMA_ENGINE_SUPPORT_DISABLED
:
358 $message = __('%s has been disabled for this MySQL server.');
360 case PMA_ENGINE_SUPPORT_NO
:
362 $message = __('This MySQL server does not support the %s storage engine.');
364 return sprintf($message, htmlspecialchars($this->title
));
368 * public string[][] getVariables()
370 * Generates a list of MySQL variables that provide information about this
371 * engine. This function should be overridden when extending this class
372 * for a particular engine.
375 * @return Array The list of variables.
377 function getVariables()
383 * returns string with filename for the MySQL helppage
384 * about this storage engine
386 * @return string mysql helppage filename
388 function getMysqlHelpPage()
390 return $this->engine
. '-storage-engine';
394 * public string getVariablesLikePattern()
397 * @return string SQL query LIKE pattern
399 function getVariablesLikePattern()
405 * public String[] getInfoPages()
407 * Returns a list of available information pages with labels
410 * @return array The list
412 function getInfoPages()
418 * public String getPage()
420 * Generates the requested information page
422 * @param string $id The page ID
425 * @return string The page
426 * boolean or false on error.
428 function getPage($id)