3.3.0-rc2
[phpmyadmin/madhuracj.git] / libraries / StorageEngine.class.php
blobc9b0c9e14acdfd012f4ccfb49d4f346798998f01
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Library for extracting information about the available storage engines
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
11 * defines
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'
23 /**
24 * base Storage Engine Class
25 * @package phpMyAdmin
27 class PMA_StorageEngine
29 /**
30 * @var string engine name
32 var $engine = 'dummy';
34 /**
35 * @var string engine title/description
37 var $title = 'PMA Dummy Engine Class';
39 /**
40 * @var string engine lang description
42 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
44 /**
45 * @var integer engine supported by current server
47 var $support = PMA_ENGINE_SUPPORT_NO;
49 /**
50 * returns array of storage engines
52 * @static
53 * @staticvar array $storage_engines storage engines
54 * @access public
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');
69 /**
70 * returns HTML code for storage engine select box
72 * @author rabus
73 * @static
74 * @uses PMA_StorageEngine::getStorageEngines()
75 * @uses strtolower()
76 * @uses htmlspecialchars()
77 * @param string $name The name of the select form element
78 * @param string $id The ID of the form field
79 * @param string $selected The selected engine
80 * @param boolean $offerUnavailableEngines
81 * Should unavailable storage engines be offered?
82 * @return string html selectbox
84 static public function getHtmlSelect($name = 'engine', $id = null,
85 $selected = null, $offerUnavailableEngines = false)
87 $selected = strtolower($selected);
88 $output = '<select name="' . $name . '"'
89 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
91 foreach (PMA_StorageEngine::getStorageEngines() as $key => $details) {
92 if (!$offerUnavailableEngines
93 && ($details['Support'] == 'NO' || $details['Support'] == 'DISABLED')) {
94 continue;
96 // currently (MySQL 5.1.26) there is no way we can be informed
97 // that PBMS does not support normal table creation so
98 // we use an exception here
99 if ('PBMS' == $details['Engine']) {
100 continue;
102 $output .= ' <option value="' . htmlspecialchars($key). '"'
103 . (empty($details['Comment'])
104 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
105 . (strtolower($key) == $selected || (empty($selected) && $details['Support'] == 'DEFAULT')
106 ? ' selected="selected"' : '') . '>' . "\n"
107 . ' ' . htmlspecialchars($details['Engine']) . "\n"
108 . ' </option>' . "\n";
110 $output .= '</select>' . "\n";
111 return $output;
115 * public static final PMA_StorageEngine getEngine()
117 * Loads the corresponding engine plugin, if available.
119 * @uses str_replace()
120 * @uses file_exists()
121 * @uses PMA_StorageEngine
122 * @param string $engine The engine ID
123 * @return object The engine plugin
125 static public function getEngine($engine)
127 $engine = str_replace('/', '', str_replace('.', '', $engine));
128 $engine_lowercase_filename = strtolower($engine);
129 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
130 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php') {
131 $class_name = 'PMA_StorageEngine_' . $engine;
132 $engine_object = new $class_name($engine);
133 } else {
134 $engine_object = new PMA_StorageEngine($engine);
136 return $engine_object;
140 * return true if given engine name is supported/valid, otherwise false
142 * @static
143 * @uses PMA_StorageEngine::getStorageEngines()
144 * @param string $engine name of engine
145 * @return boolean whether $engine is valid or not
147 static public function isValid($engine)
149 $storage_engines = PMA_StorageEngine::getStorageEngines();
150 return isset($storage_engines[$engine]);
154 * returns as HTML table of the engine's server variables
156 * @uses PMA_ENGINE_DETAILS_TYPE_SIZE
157 * @uses PMA_ENGINE_DETAILS_TYPE_NUMERIC
158 * @uses PMA_StorageEngine::getVariablesStatus()
159 * @uses $GLOBALS['strNoDetailsForEngine']
160 * @uses PMA_showHint()
161 * @uses PMA_formatByteDown()
162 * @uses PMA_formatNumber()
163 * @uses htmlspecialchars()
164 * @return string The table that was generated based on the retrieved information
166 function getHtmlVariables()
168 $odd_row = false;
169 $ret = '';
171 foreach ($this->getVariablesStatus() as $details) {
172 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
173 . ' <td>' . "\n";
174 if (!empty($details['desc'])) {
175 $ret .= ' ' . PMA_showHint($details['desc']) . "\n";
177 $ret .= ' </td>' . "\n"
178 . ' <th>' . htmlspecialchars($details['title']) . '</th>' . "\n"
179 . ' <td class="value">';
180 switch ($details['type']) {
181 case PMA_ENGINE_DETAILS_TYPE_SIZE:
182 $parsed_size = PMA_formatByteDown($details['value']);
183 $ret .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
184 unset($parsed_size);
185 break;
186 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
187 $ret .= PMA_formatNumber($details['value']) . ' ';
188 break;
189 default:
190 $ret .= htmlspecialchars($details['value']) . ' ';
192 $ret .= '</td>' . "\n"
193 . '</tr>' . "\n";
194 $odd_row = !$odd_row;
197 if (! $ret) {
198 $ret = '<p>' . "\n"
199 . ' ' . $GLOBALS['strNoDetailsForEngine'] . "\n"
200 . '</p>' . "\n";
201 } else {
202 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
205 return $ret;
209 * returns array with detailed info about engine specific server variables
211 * @uses PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
212 * @uses PMA_StorageEngine::getVariables()
213 * @uses PMA_StorageEngine::getVariablesLikePattern()
214 * @uses PMA_DBI_query()
215 * @uses PMA_DBI_fetch_assoc()
216 * @uses PMA_DBI_free_result()
217 * @return array with detailed info about specific engine server variables
219 function getVariablesStatus()
221 $variables = $this->getVariables();
222 $like = $this->getVariablesLikePattern();
224 if ($like) {
225 $like = " LIKE '" . $like . "' ";
226 } else {
227 $like = '';
230 $mysql_vars = array();
232 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
233 $res = PMA_DBI_query($sql_query);
234 while ($row = PMA_DBI_fetch_assoc($res)) {
235 if (isset($variables[$row['Variable_name']])) {
236 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
237 } elseif (! $like
238 && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0) {
239 continue;
241 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
243 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
244 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
247 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
248 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
251 PMA_DBI_free_result($res);
253 return $mysql_vars;
257 * Constructor
259 * @uses PMA_StorageEngine::getStorageEngines()
260 * @uses PMA_ENGINE_SUPPORT_DEFAULT
261 * @uses PMA_ENGINE_SUPPORT_YES
262 * @uses PMA_ENGINE_SUPPORT_DISABLED
263 * @uses PMA_ENGINE_SUPPORT_NO
264 * @uses $this->engine
265 * @uses $this->title
266 * @uses $this->comment
267 * @uses $this->support
268 * @param string $engine The engine ID
270 function __construct($engine)
272 $storage_engines = PMA_StorageEngine::getStorageEngines();
273 if (!empty($storage_engines[$engine])) {
274 $this->engine = $engine;
275 $this->title = $storage_engines[$engine]['Engine'];
276 $this->comment =
277 (isset($storage_engines[$engine]['Comment'])
278 ? $storage_engines[$engine]['Comment']
279 : '');
280 switch ($storage_engines[$engine]['Support']) {
281 case 'DEFAULT':
282 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
283 break;
284 case 'YES':
285 $this->support = PMA_ENGINE_SUPPORT_YES;
286 break;
287 case 'DISABLED':
288 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
289 break;
290 case 'NO':
291 default:
292 $this->support = PMA_ENGINE_SUPPORT_NO;
298 * public String getTitle()
300 * Reveals the engine's title
301 * @uses $this->title
302 * @return string The title
304 function getTitle()
306 return $this->title;
310 * public String getComment()
312 * Fetches the server's comment about this engine
313 * @uses $this->comment
314 * @return string The comment
316 function getComment()
318 return $this->comment;
322 * public String getSupportInformationMessage()
324 * @uses $GLOBALS['strDefaultEngine']
325 * @uses $GLOBALS['strEngineAvailable']
326 * @uses $GLOBALS['strEngineDisabled']
327 * @uses $GLOBALS['strEngineUnsupported']
328 * @uses $GLOBALS['strEngineUnsupported']
329 * @uses PMA_ENGINE_SUPPORT_DEFAULT
330 * @uses PMA_ENGINE_SUPPORT_YES
331 * @uses PMA_ENGINE_SUPPORT_DISABLED
332 * @uses PMA_ENGINE_SUPPORT_NO
333 * @uses $this->support
334 * @uses $this->title
335 * @uses sprintf
336 * @return string The localized message.
338 function getSupportInformationMessage()
340 switch ($this->support) {
341 case PMA_ENGINE_SUPPORT_DEFAULT:
342 $message = $GLOBALS['strDefaultEngine'];
343 break;
344 case PMA_ENGINE_SUPPORT_YES:
345 $message = $GLOBALS['strEngineAvailable'];
346 break;
347 case PMA_ENGINE_SUPPORT_DISABLED:
348 $message = $GLOBALS['strEngineDisabled'];
349 break;
350 case PMA_ENGINE_SUPPORT_NO:
351 default:
352 $message = $GLOBALS['strEngineUnsupported'];
354 return sprintf($message, htmlspecialchars($this->title));
358 * public string[][] getVariables()
360 * Generates a list of MySQL variables that provide information about this
361 * engine. This function should be overridden when extending this class
362 * for a particular engine.
364 * @abstract
365 * @return Array The list of variables.
367 function getVariables()
369 return array();
373 * returns string with filename for the MySQL helppage
374 * about this storage engne
376 * @return string mysql helppage filename
378 function getMysqlHelpPage()
380 return $this->engine . '-storage-engine';
384 * public string getVariablesLikePattern()
386 * @abstract
387 * @return string SQL query LIKE pattern
389 function getVariablesLikePattern()
391 return false;
395 * public String[] getInfoPages()
397 * Returns a list of available information pages with labels
399 * @abstract
400 * @return array The list
402 function getInfoPages()
404 return array();
408 * public String getPage()
410 * Generates the requested information page
412 * @abstract
413 * @param string $id The page ID
415 * @return string The page
416 * boolean or false on error.
418 function getPage($id)
420 return false;