added japanese language
[openemr.git] / phpmyadmin / libraries / StorageEngine.class.php
blob934fbe5259221469e86e27940019d2087153911d
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 = 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 . (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 * @static
171 * @return PMA_StorageEngine The engine plugin
173 static public function getEngine($engine)
175 $engine = str_replace('/', '', str_replace('.', '', $engine));
176 $filename = './libraries/engines/' . strtolower($engine) . '.lib.php';
177 if (file_exists($filename) && include_once $filename) {
178 switch(strtolower($engine)) {
179 case 'bdb':
180 return new PMA_StorageEngine_Bdb($engine);
181 case 'berkeleydb':
182 return new PMA_StorageEngine_Berkeleydb($engine);
183 case 'binlog':
184 return new PMA_StorageEngine_Binlog($engine);
185 case 'innobase':
186 return new PMA_StorageEngine_Innobase($engine);
187 case 'innodb':
188 return new PMA_StorageEngine_Innodb($engine);
189 case 'memory':
190 return new PMA_StorageEngine_Memory($engine);
191 case 'merge':
192 return new PMA_StorageEngine_Merge($engine);
193 case 'mrg_myisam':
194 return new PMA_StorageEngine_MrgMyisam($engine);
195 case 'myisam':
196 return new PMA_StorageEngine_Myisam($engine);
197 case 'ndbcluster':
198 return new PMA_StorageEngine_Ndbcluster($engine);
199 case 'pbxt':
200 return new PMA_StorageEngine_Pbxt($engine);
201 case 'performance_schema':
202 return new PMA_StorageEngine_PerformanceSchema($engine);
204 } else {
205 return new PMA_StorageEngine($engine);
210 * Returns true if given engine name is supported/valid, otherwise false
212 * @param string $engine name of engine
214 * @static
215 * @return boolean whether $engine is valid or not
217 static public function isValid($engine)
219 if ($engine == "PBMS") {
220 return true;
222 $storage_engines = PMA_StorageEngine::getStorageEngines();
223 return isset($storage_engines[$engine]);
227 * Returns as HTML table of the engine's server variables
229 * @return string The table that was generated based on the retrieved
230 * information
232 public function getHtmlVariables()
234 $odd_row = false;
235 $ret = '';
237 foreach ($this->getVariablesStatus() as $details) {
238 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
239 . ' <td>' . "\n";
240 if (! empty($details['desc'])) {
241 $ret .= ' '
242 . PMA_Util::showHint($details['desc'])
243 . "\n";
245 $ret .= ' </td>' . "\n"
246 . ' <th>' . htmlspecialchars($details['title']) . '</th>'
247 . "\n"
248 . ' <td class="value">';
249 switch ($details['type']) {
250 case PMA_ENGINE_DETAILS_TYPE_SIZE:
251 $parsed_size = $this->resolveTypeSize($details['value']);
252 $ret .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
253 unset($parsed_size);
254 break;
255 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
256 $ret .= PMA_Util::formatNumber($details['value']) . ' ';
257 break;
258 default:
259 $ret .= htmlspecialchars($details['value']) . ' ';
261 $ret .= '</td>' . "\n"
262 . '</tr>' . "\n";
263 $odd_row = ! $odd_row;
266 if (! $ret) {
267 $ret = '<p>' . "\n"
268 . ' '
269 . __('There is no detailed status information available for this storage engine.')
270 . "\n"
271 . '</p>' . "\n";
272 } else {
273 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
276 return $ret;
280 * Returns the engine specific handling for
281 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
283 * This function should be overridden when
284 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
285 * handled differently for a particular engine.
287 * @param integer $value Value to format
289 * @return string the formatted value and its unit
291 public function resolveTypeSize($value)
293 return PMA_Util::formatByteDown($value);
297 * Returns array with detailed info about engine specific server variables
299 * @return array array with detailed info about specific engine server variables
301 public function getVariablesStatus()
303 $variables = $this->getVariables();
304 $like = $this->getVariablesLikePattern();
306 if ($like) {
307 $like = " LIKE '" . $like . "' ";
308 } else {
309 $like = '';
312 $mysql_vars = array();
314 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
315 $res = $GLOBALS['dbi']->query($sql_query);
316 while ($row = $GLOBALS['dbi']->fetchAssoc($res)) {
317 if (isset($variables[$row['Variable_name']])) {
318 $mysql_vars[$row['Variable_name']]
319 = $variables[$row['Variable_name']];
320 } elseif (! $like
321 && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0
323 continue;
325 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
327 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
328 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
331 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
332 $mysql_vars[$row['Variable_name']]['type']
333 = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
336 $GLOBALS['dbi']->freeResult($res);
338 return $mysql_vars;
342 * Reveals the engine's title
344 * @return string The title
346 public function getTitle()
348 return $this->title;
352 * Fetches the server's comment about this engine
354 * @return string The comment
356 public function getComment()
358 return $this->comment;
362 * Information message on whether this storge engine is supported
364 * @return string The localized message.
366 public function getSupportInformationMessage()
368 switch ($this->support) {
369 case PMA_ENGINE_SUPPORT_DEFAULT:
370 $message = __('%s is the default storage engine on this MySQL server.');
371 break;
372 case PMA_ENGINE_SUPPORT_YES:
373 $message = __('%s is available on this MySQL server.');
374 break;
375 case PMA_ENGINE_SUPPORT_DISABLED:
376 $message = __('%s has been disabled for this MySQL server.');
377 break;
378 case PMA_ENGINE_SUPPORT_NO:
379 default:
380 $message = __('This MySQL server does not support the %s storage engine.');
382 return sprintf($message, htmlspecialchars($this->title));
386 * Generates a list of MySQL variables that provide information about this
387 * engine. This function should be overridden when extending this class
388 * for a particular engine.
390 * @return array The list of variables.
392 public function getVariables()
394 return array();
398 * Returns string with filename for the MySQL helppage
399 * about this storage engine
401 * @return string MySQL help page filename
403 public function getMysqlHelpPage()
405 return $this->engine . '-storage-engine';
409 * Returns the pattern to be used in the query for SQL variables
410 * related to the storage engine
412 * @return string SQL query LIKE pattern
414 public function getVariablesLikePattern()
416 return false;
420 * Returns a list of available information pages with labels
422 * @return string[] The list
424 public function getInfoPages()
426 return array();
430 * Generates the requested information page
432 * @param string $id The page ID
434 * @return string|boolean The page or false on error.
436 public function getPage($id)
438 return false;