2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Library for extracting information about the available storage engines
13 define('PMA_ENGINE_SUPPORT_NO', 0);
14 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
15 define('PMA_ENGINE_SUPPORT_YES', 2);
16 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
18 define('PMA_ENGINE_DETAILS_TYPE_PLAINTEXT', 0);
19 define('PMA_ENGINE_DETAILS_TYPE_SIZE', 1);
20 define('PMA_ENGINE_DETAILS_TYPE_NUMERIC', 2); //Has no effect yet...
21 define('PMA_ENGINE_DETAILS_TYPE_BOOLEAN', 3); // 'ON' or 'OFF'
24 * base Storage Engine Class
27 class PMA_StorageEngine
30 * @var string engine name
32 var $engine = 'dummy';
35 * @var string engine title/description
37 var $title = 'PMA Dummy Engine Class';
40 * @var string engine lang description
42 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
45 * @var integer engine supported by current server
47 var $support = PMA_ENGINE_SUPPORT_NO
;
50 * returns array of storage engines
53 * @staticvar array $storage_engines storage engines
55 * @uses PMA_DBI_fetch_result()
56 * @return array of storage engines
58 static public function getStorageEngines()
60 static $storage_engines = null;
62 if (null !== $storage_engines) {
63 return $storage_engines;
66 return PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
70 * returns HTML code for storage engine select box
73 * @uses PMA_StorageEngine::getStorageEngines()
75 * @uses htmlspecialchars()
76 * @param string $name The name of the select form element
77 * @param string $id The ID of the form field
78 * @param string $selected The selected engine
79 * @param boolean $offerUnavailableEngines
80 * Should unavailable storage engines be offered?
81 * @return string html selectbox
83 static public function getHtmlSelect($name = 'engine', $id = null,
84 $selected = null, $offerUnavailableEngines = false)
86 $selected = strtolower($selected);
87 $output = '<select name="' . $name . '"'
88 . (empty($id) ?
'' : ' id="' . $id . '"') . '>' . "\n";
90 foreach (PMA_StorageEngine
::getStorageEngines() as $key => $details) {
91 if (!$offerUnavailableEngines
92 && ($details['Support'] == 'NO' ||
$details['Support'] == 'DISABLED')) {
95 // currently (MySQL 5.1.26) there is no way we can be informed
96 // that PBMS does not support normal table creation so
97 // we use an exception here
98 if ('PBMS' == $details['Engine']) {
101 $output .= ' <option value="' . htmlspecialchars($key). '"'
102 . (empty($details['Comment'])
103 ?
'' : ' title="' . htmlspecialchars($details['Comment']) . '"')
104 . (strtolower($key) == $selected ||
(empty($selected) && $details['Support'] == 'DEFAULT')
105 ?
' selected="selected"' : '') . '>' . "\n"
106 . ' ' . htmlspecialchars($details['Engine']) . "\n"
107 . ' </option>' . "\n";
109 $output .= '</select>' . "\n";
114 * public static final PMA_StorageEngine getEngine()
116 * Loads the corresponding engine plugin, if available.
118 * @uses str_replace()
119 * @uses file_exists()
120 * @uses PMA_StorageEngine
121 * @param string $engine The engine ID
122 * @return object The engine plugin
124 static public function getEngine($engine)
126 $engine = str_replace('/', '', str_replace('.', '', $engine));
127 $engine_lowercase_filename = strtolower($engine);
128 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
129 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php') {
130 $class_name = 'PMA_StorageEngine_' . $engine;
131 $engine_object = new $class_name($engine);
133 $engine_object = new PMA_StorageEngine($engine);
135 return $engine_object;
139 * return true if given engine name is supported/valid, otherwise false
142 * @uses PMA_StorageEngine::getStorageEngines()
143 * @param string $engine name of engine
144 * @return boolean whether $engine is valid or not
146 static public function isValid($engine)
148 $storage_engines = PMA_StorageEngine
::getStorageEngines();
149 return isset($storage_engines[$engine]);
153 * returns as HTML table of the engine's server variables
155 * @uses PMA_ENGINE_DETAILS_TYPE_SIZE
156 * @uses PMA_ENGINE_DETAILS_TYPE_NUMERIC
157 * @uses PMA_StorageEngine::getVariablesStatus()
158 * @uses __('There is no detailed status information available for this storage engine.')
159 * @uses PMA_showHint()
160 * @uses PMA_formatByteDown()
161 * @uses PMA_formatNumber()
162 * @uses htmlspecialchars()
163 * @return string The table that was generated based on the retrieved information
165 function getHtmlVariables()
170 foreach ($this->getVariablesStatus() as $details) {
171 $ret .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
173 if (!empty($details['desc'])) {
174 $ret .= ' ' . PMA_showHint($details['desc']) . "\n";
176 $ret .= ' </td>' . "\n"
177 . ' <th>' . htmlspecialchars($details['title']) . '</th>' . "\n"
178 . ' <td class="value">';
179 switch ($details['type']) {
180 case PMA_ENGINE_DETAILS_TYPE_SIZE
:
181 $parsed_size = $this->resolveTypeSize($details['value']);
182 $ret .= $parsed_size[0] . ' ' . $parsed_size[1];
185 case PMA_ENGINE_DETAILS_TYPE_NUMERIC
:
186 $ret .= PMA_formatNumber($details['value']) . ' ';
189 $ret .= htmlspecialchars($details['value']) . ' ';
191 $ret .= '</td>' . "\n"
193 $odd_row = !$odd_row;
198 . ' ' . __('There is no detailed status information available for this storage engine.') . "\n"
201 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
208 * returns the engine specific handling for
209 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
211 * This function should be overridden when
212 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
213 * handled differently for a particular engine.
215 * @return string the formatted value and its unit
217 function resolveTypeSize($value)
219 return PMA_formatByteDown($value);
223 * returns array with detailed info about engine specific server variables
225 * @uses PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
226 * @uses PMA_StorageEngine::getVariables()
227 * @uses PMA_StorageEngine::getVariablesLikePattern()
228 * @uses PMA_DBI_query()
229 * @uses PMA_DBI_fetch_assoc()
230 * @uses PMA_DBI_free_result()
231 * @return array with detailed info about specific engine server variables
233 function getVariablesStatus()
235 $variables = $this->getVariables();
236 $like = $this->getVariablesLikePattern();
239 $like = " LIKE '" . $like . "' ";
244 $mysql_vars = array();
246 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
247 $res = PMA_DBI_query($sql_query);
248 while ($row = PMA_DBI_fetch_assoc($res)) {
249 if (isset($variables[$row['Variable_name']])) {
250 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
252 && strpos(strtolower($row['Variable_name']), strtolower($this->engine
)) !== 0) {
255 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
257 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
258 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
261 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
262 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
;
265 PMA_DBI_free_result($res);
273 * @uses PMA_StorageEngine::getStorageEngines()
274 * @uses PMA_ENGINE_SUPPORT_DEFAULT
275 * @uses PMA_ENGINE_SUPPORT_YES
276 * @uses PMA_ENGINE_SUPPORT_DISABLED
277 * @uses PMA_ENGINE_SUPPORT_NO
278 * @uses $this->engine
280 * @uses $this->comment
281 * @uses $this->support
282 * @param string $engine The engine ID
284 function __construct($engine)
286 $storage_engines = PMA_StorageEngine
::getStorageEngines();
287 if (!empty($storage_engines[$engine])) {
288 $this->engine
= $engine;
289 $this->title
= $storage_engines[$engine]['Engine'];
291 (isset($storage_engines[$engine]['Comment'])
292 ?
$storage_engines[$engine]['Comment']
294 switch ($storage_engines[$engine]['Support']) {
296 $this->support
= PMA_ENGINE_SUPPORT_DEFAULT
;
299 $this->support
= PMA_ENGINE_SUPPORT_YES
;
302 $this->support
= PMA_ENGINE_SUPPORT_DISABLED
;
306 $this->support
= PMA_ENGINE_SUPPORT_NO
;
312 * public String getTitle()
314 * Reveals the engine's title
316 * @return string The title
324 * public String getComment()
326 * Fetches the server's comment about this engine
327 * @uses $this->comment
328 * @return string The comment
330 function getComment()
332 return $this->comment
;
336 * public String getSupportInformationMessage()
338 * @uses __('%s is the default storage engine on this MySQL server.')
339 * @uses __('%s is available on this MySQL server.')
340 * @uses __('%s has been disabled for this MySQL server.')
341 * @uses __('This MySQL server does not support the %s storage engine.')
342 * @uses __('This MySQL server does not support the %s storage engine.')
343 * @uses PMA_ENGINE_SUPPORT_DEFAULT
344 * @uses PMA_ENGINE_SUPPORT_YES
345 * @uses PMA_ENGINE_SUPPORT_DISABLED
346 * @uses PMA_ENGINE_SUPPORT_NO
347 * @uses $this->support
350 * @return string The localized message.
352 function getSupportInformationMessage()
354 switch ($this->support
) {
355 case PMA_ENGINE_SUPPORT_DEFAULT
:
356 $message = __('%s is the default storage engine on this MySQL server.');
358 case PMA_ENGINE_SUPPORT_YES
:
359 $message = __('%s is available on this MySQL server.');
361 case PMA_ENGINE_SUPPORT_DISABLED
:
362 $message = __('%s has been disabled for this MySQL server.');
364 case PMA_ENGINE_SUPPORT_NO
:
366 $message = __('This MySQL server does not support the %s storage engine.');
368 return sprintf($message, htmlspecialchars($this->title
));
372 * public string[][] getVariables()
374 * Generates a list of MySQL variables that provide information about this
375 * engine. This function should be overridden when extending this class
376 * for a particular engine.
379 * @return Array The list of variables.
381 function getVariables()
387 * returns string with filename for the MySQL helppage
388 * about this storage engne
390 * @return string mysql helppage filename
392 function getMysqlHelpPage()
394 return $this->engine
. '-storage-engine';
398 * public string getVariablesLikePattern()
401 * @return string SQL query LIKE pattern
403 function getVariablesLikePattern()
409 * public String[] getInfoPages()
411 * Returns a list of available information pages with labels
414 * @return array The list
416 function getInfoPages()
422 * public String getPage()
424 * Generates the requested information page
427 * @param string $id The page ID
429 * @return string The page
430 * boolean or false on error.
432 function getPage($id)