2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Library for extracting information about the available storage engines
8 namespace PMA\libraries
;
13 use PMA\libraries\engines\Bdb
;
14 use PMA\libraries\engines\Berkeleydb
;
15 use PMA\libraries\engines\Binlog
;
16 use PMA\libraries\engines\Innobase
;
17 use PMA\libraries\engines\Innodb
;
18 use PMA\libraries\engines\Memory
;
19 use PMA\libraries\engines\Merge
;
20 use PMA\libraries\engines\Mrg_Myisam
;
21 use PMA\libraries\engines\Myisam
;
22 use PMA\libraries\engines\Ndbcluster
;
23 use PMA\libraries\engines\Pbxt
;
24 use PMA\libraries\engines\Performance_Schema
;
26 define('PMA_ENGINE_SUPPORT_NO', 0);
27 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
28 define('PMA_ENGINE_SUPPORT_YES', 2);
29 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
31 define('PMA_ENGINE_DETAILS_TYPE_PLAINTEXT', 0);
32 define('PMA_ENGINE_DETAILS_TYPE_SIZE', 1);
33 define('PMA_ENGINE_DETAILS_TYPE_NUMERIC', 2); //Has no effect yet...
34 define('PMA_ENGINE_DETAILS_TYPE_BOOLEAN', 3); // 'ON' or 'OFF'
37 * Base Storage Engine Class
44 * @var string engine name
46 var $engine = 'dummy';
49 * @var string engine title/description
51 var $title = 'PMA Dummy Engine Class';
54 * @var string engine lang description
57 = 'If you read this text inside phpMyAdmin, something went wrong...';
60 * @var integer engine supported by current server
62 var $support = PMA_ENGINE_SUPPORT_NO
;
67 * @param string $engine The engine ID
69 public function __construct($engine)
71 $storage_engines = StorageEngine
::getStorageEngines();
72 if (! empty($storage_engines[$engine])) {
73 $this->engine
= $engine;
74 $this->title
= $storage_engines[$engine]['Engine'];
75 $this->comment
= (isset($storage_engines[$engine]['Comment'])
76 ?
$storage_engines[$engine]['Comment']
78 switch ($storage_engines[$engine]['Support']) {
80 $this->support
= PMA_ENGINE_SUPPORT_DEFAULT
;
83 $this->support
= PMA_ENGINE_SUPPORT_YES
;
86 $this->support
= PMA_ENGINE_SUPPORT_DISABLED
;
90 $this->support
= PMA_ENGINE_SUPPORT_NO
;
96 * Returns array of storage engines
99 * @staticvar array $storage_engines storage engines
101 * @return string[] array of storage engines
103 static public function getStorageEngines()
105 static $storage_engines = null;
107 if (null == $storage_engines) {
109 = $GLOBALS['dbi']->fetchResult('SHOW STORAGE ENGINES', 'Engine');
110 if (PMA_MYSQL_INT_VERSION
>= 50708) {
111 $disabled = Util
::cacheGet(
112 'disabled_storage_engines',
114 return $GLOBALS['dbi']->fetchValue(
115 'SELECT @@disabled_storage_engines'
119 foreach (explode(",", $disabled) as $engine) {
120 if (isset($storage_engines[$engine])) {
121 $storage_engines[$engine]['Support'] = 'DISABLED';
127 return $storage_engines;
131 * Returns HTML code for storage engine select box
133 * @param string $name The name of the select form element
134 * @param string $id The ID of the form field
135 * @param string $selected The selected engine
136 * @param boolean $offerUnavailableEngines Should unavailable storage
137 * engines be offered?
138 * @param boolean $addEmpty Whether to provide empty option
141 * @return string html selectbox
143 static public function getHtmlSelect(
144 $name = 'engine', $id = null,
145 $selected = null, $offerUnavailableEngines = false,
148 $selected = mb_strtolower($selected);
149 $output = '<select name="' . $name . '"'
150 . (empty($id) ?
'' : ' id="' . $id . '"') . '>' . "\n";
153 $output .= '<option value=""></option>';
156 foreach (StorageEngine
::getStorageEngines() as $key => $details) {
157 // Don't show PERFORMANCE_SCHEMA engine (MySQL 5.5)
158 if (! $offerUnavailableEngines
159 && ($details['Support'] == 'NO'
160 ||
$details['Support'] == 'DISABLED'
161 ||
$details['Engine'] == 'PERFORMANCE_SCHEMA')
166 $output .= ' <option value="' . htmlspecialchars($key) . '"'
167 . (empty($details['Comment'])
168 ?
'' : ' title="' . htmlspecialchars($details['Comment']) . '"')
169 . (mb_strtolower($key) == $selected
170 ||
(empty($selected) && $details['Support'] == 'DEFAULT' && ! $addEmpty)
171 ?
' selected="selected"' : '')
173 . ' ' . htmlspecialchars($details['Engine']) . "\n"
174 . ' </option>' . "\n";
176 $output .= '</select>' . "\n";
181 * Loads the corresponding engine plugin, if available.
183 * @param string $engine The engine ID
185 * @return StorageEngine The engine plugin
188 static public function getEngine($engine)
190 switch(strtolower($engine)) {
192 return new Bdb($engine);
194 return new Berkeleydb($engine);
196 return new Binlog($engine);
198 return new Innobase($engine);
200 return new Innodb($engine);
202 return new Memory($engine);
204 return new Merge($engine);
206 return new Mrg_Myisam($engine);
208 return new Myisam($engine);
210 return new Ndbcluster($engine);
212 return new Pbxt($engine);
213 case 'performance_schema':
214 return new Performance_Schema($engine);
216 return new StorageEngine($engine);
221 * Returns true if given engine name is supported/valid, otherwise false
223 * @param string $engine name of engine
226 * @return boolean whether $engine is valid or not
228 static public function isValid($engine)
230 if ($engine == "PBMS") {
233 $storage_engines = StorageEngine
::getStorageEngines();
234 return isset($storage_engines[$engine]);
238 * Returns as HTML table of the engine's server variables
240 * @return string The table that was generated based on the retrieved
243 public function getHtmlVariables()
247 foreach ($this->getVariablesStatus() as $details) {
248 $ret .= '<tr>' . "\n"
250 if (! empty($details['desc'])) {
252 . Util
::showHint($details['desc'])
255 $ret .= ' </td>' . "\n"
256 . ' <th>' . htmlspecialchars($details['title']) . '</th>'
258 . ' <td class="value">';
259 switch ($details['type']) {
260 case PMA_ENGINE_DETAILS_TYPE_SIZE
:
261 $parsed_size = $this->resolveTypeSize($details['value']);
262 $ret .= $parsed_size[0] . ' ' . $parsed_size[1];
265 case PMA_ENGINE_DETAILS_TYPE_NUMERIC
:
266 $ret .= Util
::formatNumber($details['value']) . ' ';
269 $ret .= htmlspecialchars($details['value']) . ' ';
271 $ret .= '</td>' . "\n"
279 'There is no detailed status information available for this '
285 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
292 * Returns the engine specific handling for
293 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
295 * This function should be overridden when
296 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
297 * handled differently for a particular engine.
299 * @param integer $value Value to format
301 * @return string the formatted value and its unit
303 public function resolveTypeSize($value)
305 return Util
::formatByteDown($value);
309 * Returns array with detailed info about engine specific server variables
311 * @return array array with detailed info about specific engine server variables
313 public function getVariablesStatus()
315 $variables = $this->getVariables();
316 $like = $this->getVariablesLikePattern();
319 $like = " LIKE '" . $like . "' ";
324 $mysql_vars = array();
326 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
327 $res = $GLOBALS['dbi']->query($sql_query);
328 while ($row = $GLOBALS['dbi']->fetchAssoc($res)) {
329 if (isset($variables[$row['Variable_name']])) {
330 $mysql_vars[$row['Variable_name']]
331 = $variables[$row['Variable_name']];
333 && mb_strpos(mb_strtolower($row['Variable_name']), mb_strtolower($this->engine
)) !== 0
337 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
339 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
340 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
343 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
344 $mysql_vars[$row['Variable_name']]['type']
345 = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
;
348 $GLOBALS['dbi']->freeResult($res);
354 * Reveals the engine's title
356 * @return string The title
358 public function getTitle()
364 * Fetches the server's comment about this engine
366 * @return string The comment
368 public function getComment()
370 return $this->comment
;
374 * Information message on whether this storage engine is supported
376 * @return string The localized message.
378 public function getSupportInformationMessage()
380 switch ($this->support
) {
381 case PMA_ENGINE_SUPPORT_DEFAULT
:
382 $message = __('%s is the default storage engine on this MySQL server.');
384 case PMA_ENGINE_SUPPORT_YES
:
385 $message = __('%s is available on this MySQL server.');
387 case PMA_ENGINE_SUPPORT_DISABLED
:
388 $message = __('%s has been disabled for this MySQL server.');
390 case PMA_ENGINE_SUPPORT_NO
:
393 'This MySQL server does not support the %s storage engine.'
396 return sprintf($message, htmlspecialchars($this->title
));
400 * Generates a list of MySQL variables that provide information about this
401 * engine. This function should be overridden when extending this class
402 * for a particular engine.
404 * @return array The list of variables.
406 public function getVariables()
412 * Returns string with filename for the MySQL helppage
413 * about this storage engine
415 * @return string MySQL help page filename
417 public function getMysqlHelpPage()
419 return $this->engine
. '-storage-engine';
423 * Returns the pattern to be used in the query for SQL variables
424 * related to the storage engine
426 * @return string SQL query LIKE pattern
428 public function getVariablesLikePattern()
434 * Returns a list of available information pages with labels
436 * @return string[] The list
438 public function getInfoPages()
444 * Generates the requested information page
446 * @param string $id page id
448 * @return string html output
450 public function getPage($id)
452 if (! array_key_exists($id, $this->getInfoPages())) {
456 $id = 'getPage' . $id;