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
;
56 * @param string $engine The engine ID
58 public function __construct($engine)
60 $storage_engines = PMA_StorageEngine
::getStorageEngines();
61 if (! empty($storage_engines[$engine])) {
62 $this->engine
= $engine;
63 $this->title
= $storage_engines[$engine]['Engine'];
64 $this->comment
= (isset($storage_engines[$engine]['Comment'])
65 ?
$storage_engines[$engine]['Comment']
67 switch ($storage_engines[$engine]['Support']) {
69 $this->support
= PMA_ENGINE_SUPPORT_DEFAULT
;
72 $this->support
= PMA_ENGINE_SUPPORT_YES
;
75 $this->support
= PMA_ENGINE_SUPPORT_DISABLED
;
79 $this->support
= PMA_ENGINE_SUPPORT_NO
;
85 * Returns array of storage engines
88 * @staticvar array $storage_engines storage engines
90 * @return string[] array of storage engines
92 static public function getStorageEngines()
94 static $storage_engines = null;
96 if (null == $storage_engines) {
99 p.plugin_name AS Engine,
101 WHEN p.plugin_name = @@storage_engine THEN 'DEFAULT'
102 WHEN p.is_active THEN 'YES'
103 ELSE 'DISABLED' END) AS Support,
104 m.module_description AS Comment
105 FROM data_dictionary.plugins p
106 JOIN data_dictionary.modules m USING (module_name)
107 WHERE p.plugin_type = 'StorageEngine'
108 AND p.plugin_name NOT IN ('FunctionEngine', 'schema')";
109 $storage_engines = $GLOBALS['dbi']->fetchResult($sql, 'Engine');
112 = $GLOBALS['dbi']->fetchResult('SHOW STORAGE ENGINES', 'Engine');
116 return $storage_engines;
120 * Returns HTML code for storage engine select box
122 * @param string $name The name of the select form element
123 * @param string $id The ID of the form field
124 * @param string $selected The selected engine
125 * @param boolean $offerUnavailableEngines Should unavailable storage
126 * engines be offered?
129 * @return string html selectbox
131 static public function getHtmlSelect(
132 $name = 'engine', $id = null,
133 $selected = null, $offerUnavailableEngines = false
135 $selected = /*overload*/mb_strtolower($selected);
136 $output = '<select name="' . $name . '"'
137 . (empty($id) ?
'' : ' id="' . $id . '"') . '>' . "\n";
139 foreach (PMA_StorageEngine
::getStorageEngines() as $key => $details) {
140 // Don't show PERFORMANCE_SCHEMA engine (MySQL 5.5)
141 // Don't show MyISAM for Drizzle (allowed only for temporary tables)
142 if (! $offerUnavailableEngines
143 && ($details['Support'] == 'NO'
144 ||
$details['Support'] == 'DISABLED'
145 ||
$details['Engine'] == 'PERFORMANCE_SCHEMA')
146 ||
(PMA_DRIZZLE
&& $details['Engine'] == 'MyISAM')
151 $output .= ' <option value="' . htmlspecialchars($key) . '"'
152 . (empty($details['Comment'])
153 ?
'' : ' title="' . htmlspecialchars($details['Comment']) . '"')
154 . (/*overload*/mb_strtolower($key) == $selected
155 ||
(empty($selected) && $details['Support'] == 'DEFAULT')
156 ?
' selected="selected"' : '')
158 . ' ' . htmlspecialchars($details['Engine']) . "\n"
159 . ' </option>' . "\n";
161 $output .= '</select>' . "\n";
166 * Loads the corresponding engine plugin, if available.
168 * @param string $engine The engine ID
170 * @return PMA_StorageEngine|bool The engine plugin or false if not found
173 static public function getEngine($engine)
175 $engine = str_replace('/', '', str_replace('.', '', $engine));
176 $filename = './libraries/engines/'
177 . /*overload*/mb_strtolower($engine) . '.lib.php';
178 if (file_exists($filename) && include_once $filename) {
179 switch(/*overload*/mb_strtolower($engine)) {
181 return new PMA_StorageEngine_Bdb($engine);
183 return new PMA_StorageEngine_Berkeleydb($engine);
185 return new PMA_StorageEngine_Binlog($engine);
187 return new PMA_StorageEngine_Innobase($engine);
189 return new PMA_StorageEngine_Innodb($engine);
191 return new PMA_StorageEngine_Memory($engine);
193 return new PMA_StorageEngine_Merge($engine);
195 return new PMA_StorageEngine_MrgMyisam($engine);
197 return new PMA_StorageEngine_Myisam($engine);
199 return new PMA_StorageEngine_Ndbcluster($engine);
201 return new PMA_StorageEngine_Pbxt($engine);
202 case 'performance_schema':
203 return new PMA_StorageEngine_PerformanceSchema($engine);
209 return new PMA_StorageEngine($engine);
213 * Returns true if given engine name is supported/valid, otherwise false
215 * @param string $engine name of engine
218 * @return boolean whether $engine is valid or not
220 static public function isValid($engine)
222 if ($engine == "PBMS") {
225 $storage_engines = PMA_StorageEngine
::getStorageEngines();
226 return isset($storage_engines[$engine]);
230 * Returns as HTML table of the engine's server variables
232 * @return string The table that was generated based on the retrieved
235 public function getHtmlVariables()
240 foreach ($this->getVariablesStatus() as $details) {
241 $ret .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
243 if (! empty($details['desc'])) {
245 . PMA_Util
::showHint($details['desc'])
248 $ret .= ' </td>' . "\n"
249 . ' <th>' . htmlspecialchars($details['title']) . '</th>'
251 . ' <td class="value">';
252 switch ($details['type']) {
253 case PMA_ENGINE_DETAILS_TYPE_SIZE
:
254 $parsed_size = $this->resolveTypeSize($details['value']);
255 $ret .= $parsed_size[0] . ' ' . $parsed_size[1];
258 case PMA_ENGINE_DETAILS_TYPE_NUMERIC
:
259 $ret .= PMA_Util
::formatNumber($details['value']) . ' ';
262 $ret .= htmlspecialchars($details['value']) . ' ';
264 $ret .= '</td>' . "\n"
266 $odd_row = ! $odd_row;
272 . __('There is no detailed status information available for this storage engine.')
276 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
283 * Returns the engine specific handling for
284 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
286 * This function should be overridden when
287 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
288 * handled differently for a particular engine.
290 * @param integer $value Value to format
292 * @return string the formatted value and its unit
294 public function resolveTypeSize($value)
296 return PMA_Util
::formatByteDown($value);
300 * Returns array with detailed info about engine specific server variables
302 * @return array array with detailed info about specific engine server variables
304 public function getVariablesStatus()
306 $variables = $this->getVariables();
307 $like = $this->getVariablesLikePattern();
310 $like = " LIKE '" . $like . "' ";
315 $mysql_vars = array();
317 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
318 $res = $GLOBALS['dbi']->query($sql_query);
319 while ($row = $GLOBALS['dbi']->fetchAssoc($res)) {
320 if (isset($variables[$row['Variable_name']])) {
321 $mysql_vars[$row['Variable_name']]
322 = $variables[$row['Variable_name']];
324 && /*overload*/mb_strpos(/*overload*/mb_strtolower($row['Variable_name']), /*overload*/mb_strtolower($this->engine
)) !== 0
328 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
330 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
331 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
334 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
335 $mysql_vars[$row['Variable_name']]['type']
336 = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
;
339 $GLOBALS['dbi']->freeResult($res);
345 * Reveals the engine's title
347 * @return string The title
349 public function getTitle()
355 * Fetches the server's comment about this engine
357 * @return string The comment
359 public function getComment()
361 return $this->comment
;
365 * Information message on whether this storage engine is supported
367 * @return string The localized message.
369 public function getSupportInformationMessage()
371 switch ($this->support
) {
372 case PMA_ENGINE_SUPPORT_DEFAULT
:
373 $message = __('%s is the default storage engine on this MySQL server.');
375 case PMA_ENGINE_SUPPORT_YES
:
376 $message = __('%s is available on this MySQL server.');
378 case PMA_ENGINE_SUPPORT_DISABLED
:
379 $message = __('%s has been disabled for this MySQL server.');
381 case PMA_ENGINE_SUPPORT_NO
:
383 $message = __('This MySQL server does not support the %s storage engine.');
385 return sprintf($message, htmlspecialchars($this->title
));
389 * Generates a list of MySQL variables that provide information about this
390 * engine. This function should be overridden when extending this class
391 * for a particular engine.
393 * @return array The list of variables.
395 public function getVariables()
401 * Returns string with filename for the MySQL helppage
402 * about this storage engine
404 * @return string MySQL help page filename
406 public function getMysqlHelpPage()
408 return $this->engine
. '-storage-engine';
412 * Returns the pattern to be used in the query for SQL variables
413 * related to the storage engine
415 * @return string SQL query LIKE pattern
417 public function getVariablesLikePattern()
423 * Returns a list of available information pages with labels
425 * @return string[] The list
427 public function getInfoPages()
433 * Generates the requested information page
435 * @param string $id page id
437 * @return string html output
439 public function getPage($id)
441 if (! array_key_exists($id, $this->getInfoPages())) {
445 $id = 'getPage' . $id;