Bug: Live query chart always zero
[phpmyadmin/tyronm.git] / libraries / StorageEngine.class.php
blobe5c03b5bb7f348bc3cd43373c577829dde1eabeb
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Library for extracting information about the available storage engines
6 * @package phpMyAdmin
7 */
9 /**
10 * defines
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'
22 /**
23 * base Storage Engine Class
24 * @package phpMyAdmin
26 class PMA_StorageEngine
28 /**
29 * @var string engine name
31 var $engine = 'dummy';
33 /**
34 * @var string engine title/description
36 var $title = 'PMA Dummy Engine Class';
38 /**
39 * @var string engine lang description
41 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
43 /**
44 * @var integer engine supported by current server
46 var $support = PMA_ENGINE_SUPPORT_NO;
48 /**
49 * returns array of storage engines
51 * @static
52 * @staticvar array $storage_engines storage engines
53 * @access public
54 * @return array of storage engines
56 static public function getStorageEngines()
58 static $storage_engines = null;
60 if (null == $storage_engines) {
61 $storage_engines = PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
64 return $storage_engines;
67 /**
68 * returns HTML code for storage engine select box
70 * @static
71 * @param string $name The name of the select form element
72 * @param string $id The ID of the form field
73 * @param string $selected The selected engine
74 * @param boolean $offerUnavailableEngines
75 * Should unavailable storage engines be offered?
76 * @return string html selectbox
78 static public function getHtmlSelect($name = 'engine', $id = null,
79 $selected = null, $offerUnavailableEngines = false)
81 $selected = strtolower($selected);
82 $output = '<select name="' . $name . '"'
83 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
85 foreach (PMA_StorageEngine::getStorageEngines() as $key => $details) {
86 if (!$offerUnavailableEngines
87 && ($details['Support'] == 'NO' || $details['Support'] == 'DISABLED'
88 || $details['Engine'] == 'PERFORMANCE_SCHEMA')) {
89 continue;
92 $output .= ' <option value="' . htmlspecialchars($key). '"'
93 . (empty($details['Comment'])
94 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
95 . (strtolower($key) == $selected || (empty($selected) && $details['Support'] == 'DEFAULT')
96 ? ' selected="selected"' : '') . '>' . "\n"
97 . ' ' . htmlspecialchars($details['Engine']) . "\n"
98 . ' </option>' . "\n";
100 $output .= '</select>' . "\n";
101 return $output;
105 * public static final PMA_StorageEngine getEngine()
107 * Loads the corresponding engine plugin, if available.
109 * @param string $engine The engine ID
110 * @return object The engine plugin
112 static public function getEngine($engine)
114 $engine = str_replace('/', '', str_replace('.', '', $engine));
115 $engine_lowercase_filename = strtolower($engine);
116 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
117 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php') {
118 $class_name = 'PMA_StorageEngine_' . $engine;
119 $engine_object = new $class_name($engine);
120 } else {
121 $engine_object = new PMA_StorageEngine($engine);
123 return $engine_object;
127 * return true if given engine name is supported/valid, otherwise false
129 * @static
130 * @param string $engine name of engine
131 * @return boolean whether $engine is valid or not
133 static public function isValid($engine)
135 if ($engine == "PBMS") {
136 return true;
138 $storage_engines = PMA_StorageEngine::getStorageEngines();
139 return isset($storage_engines[$engine]);
143 * returns as HTML table of the engine's server variables
145 * @return string The table that was generated based on the retrieved information
147 function getHtmlVariables()
149 $odd_row = false;
150 $ret = '';
152 foreach ($this->getVariablesStatus() as $details) {
153 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
154 . ' <td>' . "\n";
155 if (!empty($details['desc'])) {
156 $ret .= ' ' . PMA_showHint($details['desc']) . "\n";
158 $ret .= ' </td>' . "\n"
159 . ' <th>' . htmlspecialchars($details['title']) . '</th>' . "\n"
160 . ' <td class="value">';
161 switch ($details['type']) {
162 case PMA_ENGINE_DETAILS_TYPE_SIZE:
163 $parsed_size = $this->resolveTypeSize($details['value']);
164 $ret .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
165 unset($parsed_size);
166 break;
167 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
168 $ret .= PMA_formatNumber($details['value']) . ' ';
169 break;
170 default:
171 $ret .= htmlspecialchars($details['value']) . ' ';
173 $ret .= '</td>' . "\n"
174 . '</tr>' . "\n";
175 $odd_row = !$odd_row;
178 if (! $ret) {
179 $ret = '<p>' . "\n"
180 . ' ' . __('There is no detailed status information available for this storage engine.') . "\n"
181 . '</p>' . "\n";
182 } else {
183 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
186 return $ret;
190 * returns the engine specific handling for
191 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
193 * This function should be overridden when
194 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
195 * handled differently for a particular engine.
197 * @return string the formatted value and its unit
199 function resolveTypeSize($value)
201 return PMA_formatByteDown($value);
205 * returns array with detailed info about engine specific server variables
207 * @return array with detailed info about specific engine server variables
209 function getVariablesStatus()
211 $variables = $this->getVariables();
212 $like = $this->getVariablesLikePattern();
214 if ($like) {
215 $like = " LIKE '" . $like . "' ";
216 } else {
217 $like = '';
220 $mysql_vars = array();
222 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
223 $res = PMA_DBI_query($sql_query);
224 while ($row = PMA_DBI_fetch_assoc($res)) {
225 if (isset($variables[$row['Variable_name']])) {
226 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
227 } elseif (! $like
228 && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0) {
229 continue;
231 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
233 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
234 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
237 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
238 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
241 PMA_DBI_free_result($res);
243 return $mysql_vars;
246 function engine_init() {}
249 * Constructor
251 * @param string $engine The engine ID
253 function __construct($engine)
255 $storage_engines = PMA_StorageEngine::getStorageEngines();
256 if (!empty($storage_engines[$engine])) {
257 $this->engine = $engine;
258 $this->title = $storage_engines[$engine]['Engine'];
259 $this->comment =
260 (isset($storage_engines[$engine]['Comment'])
261 ? $storage_engines[$engine]['Comment']
262 : '');
263 switch ($storage_engines[$engine]['Support']) {
264 case 'DEFAULT':
265 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
266 break;
267 case 'YES':
268 $this->support = PMA_ENGINE_SUPPORT_YES;
269 break;
270 case 'DISABLED':
271 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
272 break;
273 case 'NO':
274 default:
275 $this->support = PMA_ENGINE_SUPPORT_NO;
277 } else {
278 $this->engine_init();
283 * public String getTitle()
285 * Reveals the engine's title
286 * @return string The title
288 function getTitle()
290 return $this->title;
294 * public String getComment()
296 * Fetches the server's comment about this engine
297 * @return string The comment
299 function getComment()
301 return $this->comment;
305 * public String getSupportInformationMessage()
307 * @return string The localized message.
309 function getSupportInformationMessage()
311 switch ($this->support) {
312 case PMA_ENGINE_SUPPORT_DEFAULT:
313 $message = __('%s is the default storage engine on this MySQL server.');
314 break;
315 case PMA_ENGINE_SUPPORT_YES:
316 $message = __('%s is available on this MySQL server.');
317 break;
318 case PMA_ENGINE_SUPPORT_DISABLED:
319 $message = __('%s has been disabled for this MySQL server.');
320 break;
321 case PMA_ENGINE_SUPPORT_NO:
322 default:
323 $message = __('This MySQL server does not support the %s storage engine.');
325 return sprintf($message, htmlspecialchars($this->title));
329 * public string[][] getVariables()
331 * Generates a list of MySQL variables that provide information about this
332 * engine. This function should be overridden when extending this class
333 * for a particular engine.
335 * @abstract
336 * @return Array The list of variables.
338 function getVariables()
340 return array();
344 * returns string with filename for the MySQL helppage
345 * about this storage engne
347 * @return string mysql helppage filename
349 function getMysqlHelpPage()
351 return $this->engine . '-storage-engine';
355 * public string getVariablesLikePattern()
357 * @abstract
358 * @return string SQL query LIKE pattern
360 function getVariablesLikePattern()
362 return false;
366 * public String[] getInfoPages()
368 * Returns a list of available information pages with labels
370 * @abstract
371 * @return array The list
373 function getInfoPages()
375 return array();
379 * public String getPage()
381 * Generates the requested information page
383 * @abstract
384 * @param string $id The page ID
386 * @return string The page
387 * boolean or false on error.
389 function getPage($id)
391 return false;