Translated using Weblate (Slovak)
[phpmyadmin.git] / libraries / StorageEngine.class.php
blob1c49568bd16ad83f86ade92a340a53f344be8850
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 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * defines
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'
25 /**
26 * Base Storage Engine Class
28 * @package PhpMyAdmin
30 class PMA_StorageEngine
32 /**
33 * @var string engine name
35 var $engine = 'dummy';
37 /**
38 * @var string engine title/description
40 var $title = 'PMA Dummy Engine Class';
42 /**
43 * @var string engine lang description
45 var $comment
46 = 'If you read this text inside phpMyAdmin, something went wrong...';
48 /**
49 * @var integer engine supported by current server
51 var $support = PMA_ENGINE_SUPPORT_NO;
53 /**
54 * Constructor
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']
66 : '');
67 switch ($storage_engines[$engine]['Support']) {
68 case 'DEFAULT':
69 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
70 break;
71 case 'YES':
72 $this->support = PMA_ENGINE_SUPPORT_YES;
73 break;
74 case 'DISABLED':
75 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
76 break;
77 case 'NO':
78 default:
79 $this->support = PMA_ENGINE_SUPPORT_NO;
84 /**
85 * Returns array of storage engines
87 * @static
88 * @staticvar array $storage_engines storage engines
89 * @access public
90 * @return string[] array of storage engines
92 static public function getStorageEngines()
94 static $storage_engines = null;
96 if (null == $storage_engines) {
97 if (PMA_DRIZZLE) {
98 $sql = "SELECT
99 p.plugin_name AS Engine,
100 (CASE
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');
110 } else {
111 $storage_engines
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?
128 * @static
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')
148 continue;
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"' : '')
157 . '>' . "\n"
158 . ' ' . htmlspecialchars($details['Engine']) . "\n"
159 . ' </option>' . "\n";
161 $output .= '</select>' . "\n";
162 return $output;
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
171 * @static
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)) {
180 case 'bdb':
181 return new PMA_StorageEngine_Bdb($engine);
182 case 'berkeleydb':
183 return new PMA_StorageEngine_Berkeleydb($engine);
184 case 'binlog':
185 return new PMA_StorageEngine_Binlog($engine);
186 case 'innobase':
187 return new PMA_StorageEngine_Innobase($engine);
188 case 'innodb':
189 return new PMA_StorageEngine_Innodb($engine);
190 case 'memory':
191 return new PMA_StorageEngine_Memory($engine);
192 case 'merge':
193 return new PMA_StorageEngine_Merge($engine);
194 case 'mrg_myisam':
195 return new PMA_StorageEngine_MrgMyisam($engine);
196 case 'myisam':
197 return new PMA_StorageEngine_Myisam($engine);
198 case 'ndbcluster':
199 return new PMA_StorageEngine_Ndbcluster($engine);
200 case 'pbxt':
201 return new PMA_StorageEngine_Pbxt($engine);
202 case 'performance_schema':
203 return new PMA_StorageEngine_PerformanceSchema($engine);
206 return false;
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
217 * @static
218 * @return boolean whether $engine is valid or not
220 static public function isValid($engine)
222 if ($engine == "PBMS") {
223 return true;
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
233 * information
235 public function getHtmlVariables()
237 $odd_row = false;
238 $ret = '';
240 foreach ($this->getVariablesStatus() as $details) {
241 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
242 . ' <td>' . "\n";
243 if (! empty($details['desc'])) {
244 $ret .= ' '
245 . PMA_Util::showHint($details['desc'])
246 . "\n";
248 $ret .= ' </td>' . "\n"
249 . ' <th>' . htmlspecialchars($details['title']) . '</th>'
250 . "\n"
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] . '&nbsp;' . $parsed_size[1];
256 unset($parsed_size);
257 break;
258 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
259 $ret .= PMA_Util::formatNumber($details['value']) . ' ';
260 break;
261 default:
262 $ret .= htmlspecialchars($details['value']) . ' ';
264 $ret .= '</td>' . "\n"
265 . '</tr>' . "\n";
266 $odd_row = ! $odd_row;
269 if (! $ret) {
270 $ret = '<p>' . "\n"
271 . ' '
272 . __('There is no detailed status information available for this storage engine.')
273 . "\n"
274 . '</p>' . "\n";
275 } else {
276 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
279 return $ret;
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();
309 if ($like) {
310 $like = " LIKE '" . $like . "' ";
311 } else {
312 $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']];
323 } elseif (! $like
324 && /*overload*/mb_strpos(/*overload*/mb_strtolower($row['Variable_name']), /*overload*/mb_strtolower($this->engine)) !== 0
326 continue;
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);
341 return $mysql_vars;
345 * Reveals the engine's title
347 * @return string The title
349 public function getTitle()
351 return $this->title;
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.');
374 break;
375 case PMA_ENGINE_SUPPORT_YES:
376 $message = __('%s is available on this MySQL server.');
377 break;
378 case PMA_ENGINE_SUPPORT_DISABLED:
379 $message = __('%s has been disabled for this MySQL server.');
380 break;
381 case PMA_ENGINE_SUPPORT_NO:
382 default:
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()
397 return array();
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()
419 return '';
423 * Returns a list of available information pages with labels
425 * @return string[] The list
427 public function getInfoPages()
429 return array();
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())) {
442 return '';
445 $id = 'getPage' . $id;
447 return $this->$id();