Translation update done using Pootle.
[phpmyadmin/madhuracj.git] / libraries / StorageEngine.class.php
blob4f98a4a60fee1b600d272ec4d375671854680749
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 if (PMA_DRIZZLE) {
62 $sql = "SELECT
63 p.plugin_name AS Engine,
64 (CASE
65 WHEN p.plugin_name = @@storage_engine THEN 'DEFAULT'
66 WHEN p.is_active THEN 'YES'
67 ELSE 'DISABLED' END) AS Support,
68 m.module_description AS Comment
69 FROM data_dictionary.plugins p
70 JOIN data_dictionary.modules m USING (module_name)
71 WHERE p.plugin_type = 'StorageEngine'
72 AND p.plugin_name NOT IN ('FunctionEngine', 'schema')";
73 $storage_engines = PMA_DBI_fetch_result($sql, 'Engine');
74 } else {
75 $storage_engines = PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
79 return $storage_engines;
82 /**
83 * returns HTML code for storage engine select box
85 * @static
86 * @param string $name The name of the select form element
87 * @param string $id The ID of the form field
88 * @param string $selected The selected engine
89 * @param boolean $offerUnavailableEngines
90 * Should unavailable storage engines be offered?
91 * @return string html selectbox
93 static public function getHtmlSelect($name = 'engine', $id = null,
94 $selected = null, $offerUnavailableEngines = false)
96 $selected = strtolower($selected);
97 $output = '<select name="' . $name . '"'
98 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
100 foreach (PMA_StorageEngine::getStorageEngines() as $key => $details) {
101 // Don't show PERFORMANCE_SCHEMA engine (MySQL 5.5)
102 // Don't show MyISAM for Drizzle (allowed only for temporary tables)
103 if (!$offerUnavailableEngines
104 && ($details['Support'] == 'NO' || $details['Support'] == 'DISABLED'
105 || $details['Engine'] == 'PERFORMANCE_SCHEMA')
106 || (PMA_DRIZZLE && $details['Engine'] == 'MyISAM')) {
107 continue;
110 $output .= ' <option value="' . htmlspecialchars($key). '"'
111 . (empty($details['Comment'])
112 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
113 . (strtolower($key) == $selected || (empty($selected) && $details['Support'] == 'DEFAULT')
114 ? ' selected="selected"' : '') . '>' . "\n"
115 . ' ' . htmlspecialchars($details['Engine']) . "\n"
116 . ' </option>' . "\n";
118 $output .= '</select>' . "\n";
119 return $output;
123 * public static final PMA_StorageEngine getEngine()
125 * Loads the corresponding engine plugin, if available.
127 * @param string $engine The engine ID
128 * @return object The engine plugin
130 static public function getEngine($engine)
132 $engine = str_replace('/', '', str_replace('.', '', $engine));
133 $engine_lowercase_filename = strtolower($engine);
134 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
135 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php') {
136 $class_name = 'PMA_StorageEngine_' . $engine;
137 $engine_object = new $class_name($engine);
138 } else {
139 $engine_object = new PMA_StorageEngine($engine);
141 return $engine_object;
145 * return true if given engine name is supported/valid, otherwise false
147 * @static
148 * @param string $engine name of engine
149 * @return boolean whether $engine is valid or not
151 static public function isValid($engine)
153 if ($engine == "PBMS") {
154 return true;
156 $storage_engines = PMA_StorageEngine::getStorageEngines();
157 return isset($storage_engines[$engine]);
161 * returns as HTML table of the engine's server variables
163 * @return string The table that was generated based on the retrieved information
165 function getHtmlVariables()
167 $odd_row = false;
168 $ret = '';
170 foreach ($this->getVariablesStatus() as $details) {
171 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
172 . ' <td>' . "\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] . '&nbsp;' . $parsed_size[1];
183 unset($parsed_size);
184 break;
185 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
186 $ret .= PMA_formatNumber($details['value']) . ' ';
187 break;
188 default:
189 $ret .= htmlspecialchars($details['value']) . ' ';
191 $ret .= '</td>' . "\n"
192 . '</tr>' . "\n";
193 $odd_row = !$odd_row;
196 if (! $ret) {
197 $ret = '<p>' . "\n"
198 . ' ' . __('There is no detailed status information available for this storage engine.') . "\n"
199 . '</p>' . "\n";
200 } else {
201 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
204 return $ret;
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 * @return array with detailed info about specific engine server variables
227 function getVariablesStatus()
229 $variables = $this->getVariables();
230 $like = $this->getVariablesLikePattern();
232 if ($like) {
233 $like = " LIKE '" . $like . "' ";
234 } else {
235 $like = '';
238 $mysql_vars = array();
240 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
241 $res = PMA_DBI_query($sql_query);
242 while ($row = PMA_DBI_fetch_assoc($res)) {
243 if (isset($variables[$row['Variable_name']])) {
244 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
245 } elseif (! $like
246 && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0) {
247 continue;
249 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
251 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
252 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
255 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
256 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
259 PMA_DBI_free_result($res);
261 return $mysql_vars;
264 function engine_init() {}
267 * Constructor
269 * @param string $engine The engine ID
271 function __construct($engine)
273 $storage_engines = PMA_StorageEngine::getStorageEngines();
274 if (!empty($storage_engines[$engine])) {
275 $this->engine = $engine;
276 $this->title = $storage_engines[$engine]['Engine'];
277 $this->comment =
278 (isset($storage_engines[$engine]['Comment'])
279 ? $storage_engines[$engine]['Comment']
280 : '');
281 switch ($storage_engines[$engine]['Support']) {
282 case 'DEFAULT':
283 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
284 break;
285 case 'YES':
286 $this->support = PMA_ENGINE_SUPPORT_YES;
287 break;
288 case 'DISABLED':
289 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
290 break;
291 case 'NO':
292 default:
293 $this->support = PMA_ENGINE_SUPPORT_NO;
295 } else {
296 $this->engine_init();
301 * public String getTitle()
303 * Reveals the engine's title
304 * @return string The title
306 function getTitle()
308 return $this->title;
312 * public String getComment()
314 * Fetches the server's comment about this engine
315 * @return string The comment
317 function getComment()
319 return $this->comment;
323 * public String getSupportInformationMessage()
325 * @return string The localized message.
327 function getSupportInformationMessage()
329 switch ($this->support) {
330 case PMA_ENGINE_SUPPORT_DEFAULT:
331 $message = __('%s is the default storage engine on this MySQL server.');
332 break;
333 case PMA_ENGINE_SUPPORT_YES:
334 $message = __('%s is available on this MySQL server.');
335 break;
336 case PMA_ENGINE_SUPPORT_DISABLED:
337 $message = __('%s has been disabled for this MySQL server.');
338 break;
339 case PMA_ENGINE_SUPPORT_NO:
340 default:
341 $message = __('This MySQL server does not support the %s storage engine.');
343 return sprintf($message, htmlspecialchars($this->title));
347 * public string[][] getVariables()
349 * Generates a list of MySQL variables that provide information about this
350 * engine. This function should be overridden when extending this class
351 * for a particular engine.
353 * @abstract
354 * @return Array The list of variables.
356 function getVariables()
358 return array();
362 * returns string with filename for the MySQL helppage
363 * about this storage engne
365 * @return string mysql helppage filename
367 function getMysqlHelpPage()
369 return $this->engine . '-storage-engine';
373 * public string getVariablesLikePattern()
375 * @abstract
376 * @return string SQL query LIKE pattern
378 function getVariablesLikePattern()
380 return false;
384 * public String[] getInfoPages()
386 * Returns a list of available information pages with labels
388 * @abstract
389 * @return array The list
391 function getInfoPages()
393 return array();
397 * public String getPage()
399 * Generates the requested information page
401 * @abstract
402 * @param string $id The page ID
404 * @return string The page
405 * boolean or false on error.
407 function getPage($id)
409 return false;