2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Library for extracting information about the available storage engines
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'
23 * base Storage Engine Class
26 class PMA_StorageEngine
29 * @var string engine name
31 var $engine = 'dummy';
34 * @var string engine title/description
36 var $title = 'PMA Dummy Engine Class';
39 * @var string engine lang description
41 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
44 * @var integer engine supported by current server
46 var $support = PMA_ENGINE_SUPPORT_NO
;
49 * returns array of storage engines
52 * @staticvar array $storage_engines storage engines
54 * @return array of storage engines
56 static public function getStorageEngines()
58 static $storage_engines = null;
60 if (null == $storage_engines) {
63 p.plugin_name AS Engine,
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');
75 $storage_engines = PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
79 return $storage_engines;
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?
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')
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";
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);
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
154 * @return boolean whether $engine is valid or not
156 static public function isValid($engine)
158 if ($engine == "PBMS") {
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()
175 foreach ($this->getVariablesStatus() as $details) {
176 $ret .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\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] . ' ' . $parsed_size[1];
190 case PMA_ENGINE_DETAILS_TYPE_NUMERIC
:
191 $ret .= PMA_formatNumber($details['value']) . ' ';
194 $ret .= htmlspecialchars($details['value']) . ' ';
196 $ret .= '</td>' . "\n"
198 $odd_row = ! $odd_row;
203 . ' ' . __('There is no detailed status information available for this storage engine.') . "\n"
206 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
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();
238 $like = " LIKE '" . $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']];
251 && strpos(strtolower($row['Variable_name']), strtolower($this->engine
)) !== 0) {
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);
269 function engine_init() {}
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'];
283 = (isset($storage_engines[$engine]['Comment'])
284 ?
$storage_engines[$engine]['Comment']
286 switch ($storage_engines[$engine]['Support']) {
288 $this->support
= PMA_ENGINE_SUPPORT_DEFAULT
;
291 $this->support
= PMA_ENGINE_SUPPORT_YES
;
294 $this->support
= PMA_ENGINE_SUPPORT_DISABLED
;
298 $this->support
= PMA_ENGINE_SUPPORT_NO
;
301 $this->engine_init();
306 * public String getTitle()
308 * Reveals the engine's title
310 * @return string The 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.');
340 case PMA_ENGINE_SUPPORT_YES
:
341 $message = __('%s is available on this MySQL server.');
343 case PMA_ENGINE_SUPPORT_DISABLED
:
344 $message = __('%s has been disabled for this MySQL server.');
346 case PMA_ENGINE_SUPPORT_NO
:
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.
361 * @return Array The list of variables.
363 function getVariables()
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()
383 * @return string SQL query LIKE pattern
385 function getVariablesLikePattern()
391 * public String[] getInfoPages()
393 * Returns a list of available information pages with labels
396 * @return array The list
398 function getInfoPages()
404 * public String getPage()
406 * Generates the requested information page
408 * @param string $id The page ID
411 * @return string The page
412 * boolean or false on error.
414 function getPage($id)