Rev Author Line No. Line
250 kaklik 1 <?php
2 /* $Id: storage_engines.lib.php,v 2.8.2.1 2006/02/19 15:34:39 lem9 Exp $ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4  
5 /**
6 * Library for extracting information about the available storage engines
7 */
8  
9 $GLOBALS['mysql_storage_engines'] = array();
10  
11 if (PMA_MYSQL_INT_VERSION >= 40102) {
12 /**
13 * For MySQL >= 4.1.2, the job is easy...
14 */
15 $res = PMA_DBI_query('SHOW STORAGE ENGINES');
16 while ($row = PMA_DBI_fetch_assoc($res)) {
17 $GLOBALS['mysql_storage_engines'][strtolower($row['Engine'])] = $row;
18 }
19 PMA_DBI_free_result($res);
20 unset($res, $row);
21 } else {
22 /**
23 * Emulating SHOW STORAGE ENGINES...
24 */
25 $GLOBALS['mysql_storage_engines'] = array(
26 'myisam' => array(
27 'Engine' => 'MyISAM',
28 'Support' => 'DEFAULT'
29 ),
30 'merge' => array(
31 'Engine' => 'MERGE',
32 'Support' => 'YES'
33 ),
34 'heap' => array(
35 'Engine' => 'HEAP',
36 'Support' => 'YES'
37 ),
38 'memory' => array(
39 'Engine' => 'MEMORY',
40 'Support' => 'YES'
41 )
42 );
43 $known_engines = array(
44 'archive' => 'ARCHIVE',
45 'bdb' => 'BDB',
46 'csv' => 'CSV',
47 'innodb' => 'InnoDB',
48 'isam' => 'ISAM',
49 'gemini' => 'Gemini'
50 );
51 $res = PMA_DBI_query('SHOW VARIABLES LIKE \'have\\_%\';');
52 while ($row = PMA_DBI_fetch_row($res)) {
53 $current = substr($row[0], 5);
54 if (!empty($known_engines[$current])) {
55 $GLOBALS['mysql_storage_engines'][$current] = array(
56 'Engine' => $known_engines[$current],
57 'Support' => $row[1]
58 );
59 }
60 }
61 PMA_DBI_free_result($res);
62 unset($known_engines, $res, $row);
63 }
64  
65 /**
66 * Function for generating the storage engine selection
67 *
68 * @author rabus
69 * @uses $GLOBALS['mysql_storage_engines']
70 * @param string $name The name of the select form element
71 * @param string $id The ID of the form field
72 * @param boolean $offerUnavailableEngines
73 * Should unavailable storage engines be offered?
74 * @param string $selected The selected engine
75 * @param int $indent The indentation level
76 * @return string html selectbox
77 */
78 function PMA_generateEnginesDropdown($name = 'engine', $id = null,
79 $offerUnavailableEngines = false, $selected = null, $indent = 0)
80 {
81 $selected = strtolower($selected);
82 $spaces = str_repeat( ' ', $indent );
83 $output = $spaces . '<select name="' . $name . '"'
84 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
85  
86 foreach ($GLOBALS['mysql_storage_engines'] as $key => $details) {
87 if (!$offerUnavailableEngines
88 && ($details['Support'] == 'NO' || $details['Support'] == 'DISABLED')) {
89 continue;
90 }
91 $output .= $spaces . ' <option value="' . htmlspecialchars($key). '"'
92 . (empty($details['Comment'])
93 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
94 . ($key == $selected || (empty($selected) && $details['Support'] == 'DEFAULT')
95 ? ' selected="selected"' : '') . '>' . "\n"
96 . $spaces . ' ' . htmlspecialchars($details['Engine']) . "\n"
97 . $spaces . ' </option>' . "\n";
98 }
99 $output .= $spaces . '</select>' . "\n";
100 return $output;
101 }
102  
103 /**
104 * defines
105 */
106 define('PMA_ENGINE_SUPPORT_NO', 0);
107 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
108 define('PMA_ENGINE_SUPPORT_YES', 2);
109 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
110  
111 /**
112 * Abstract Storage Engine Class
113 */
114 class PMA_StorageEngine
115 {
116 /**
117 * @var string engine name
118 */
119 var $engine = 'dummy';
120  
121 /**
122 * @var string engine title/description
123 */
124 var $title = 'PMA Dummy Engine Class';
125  
126 /**
127 * @var string engine lang description
128 */
129 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
130  
131 /**
132 * @var integer engine supported by current server
133 */
134 var $support = PMA_ENGINE_SUPPORT_NO;
135  
136 /**
137 * public static final PMA_StorageEngine getEngine()
138 *
139 * Loads the corresponding engine plugin, if available.
140 *
141 * @uses str_replace()
142 * @uses file_exists()
143 * @uses PMA_StorageEngine
144 * @param string $engine The engine ID
145 * @return object The engine plugin
146 */
147 function getEngine($engine)
148 {
149 $engine = str_replace('/', '', str_replace('.', '', $engine));
150 if (file_exists('./libraries/engines/' . $engine . '.lib.php')
151 && include_once('./libraries/engines/' . $engine . '.lib.php')) {
152 $class_name = 'PMA_StorageEngine_' . $engine;
153 $engine_object = new $class_name($engine);
154 } else {
155 $engine_object = new PMA_StorageEngine($engine);
156 }
157 return $engine_object;
158 }
159  
160 /**
161 * Constructor
162 *
163 * @uses $GLOBALS['mysql_storage_engines']
164 * @uses PMA_ENGINE_SUPPORT_DEFAULT
165 * @uses PMA_ENGINE_SUPPORT_YES
166 * @uses PMA_ENGINE_SUPPORT_DISABLED
167 * @uses PMA_ENGINE_SUPPORT_NO
168 * @uses $this->engine
169 * @uses $this->title
170 * @uses $this->comment
171 * @uses $this->support
172 * @param string $engine The engine ID
173 */
174 function __construct($engine)
175 {
176 if (!empty($GLOBALS['mysql_storage_engines'][$engine])) {
177 $this->engine = $engine;
178 $this->title = $GLOBALS['mysql_storage_engines'][$engine]['Engine'];
179 $this->comment =
180 (isset($GLOBALS['mysql_storage_engines'][$engine]['Comment'])
181 ? $GLOBALS['mysql_storage_engines'][$engine]['Comment']
182 : '');
183 switch ($GLOBALS['mysql_storage_engines'][$engine]['Support']) {
184 case 'DEFAULT':
185 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
186 break;
187 case 'YES':
188 $this->support = PMA_ENGINE_SUPPORT_YES;
189 break;
190 case 'DISABLED':
191 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
192 break;
193 case 'NO':
194 default:
195 $this->support = PMA_ENGINE_SUPPORT_NO;
196 }
197 }
198 }
199  
200 /**
201 * old PHP 4 style constructor
202 * @deprecated
203 * @see PMA_StorageEngine::__construct()
204 * @uses PMA_StorageEngine::__construct()
205 * @param string $engine engine name
206 */
207 function PMA_StorageEngine($engine)
208 {
209 $this->__construct($engine);
210 }
211  
212 /**
213 * public String getTitle()
214 *
215 * Reveals the engine's title
216 * @uses $this->title
217 * @return string The title
218 */
219 function getTitle()
220 {
221 return $this->title;
222 }
223  
224 /**
225 * public String getComment()
226 *
227 * Fetches the server's comment about this engine
228 * @uses $this->comment
229 * @return string The comment
230 */
231 function getComment()
232 {
233 return $this->comment;
234 }
235  
236 /**
237 * public String getSupportInformationMessage()
238 *
239 * @uses $GLOBALS['strDefaultEngine']
240 * @uses $GLOBALS['strEngineAvailable']
241 * @uses $GLOBALS['strEngineDisabled']
242 * @uses $GLOBALS['strEngineUnsupported']
243 * @uses $GLOBALS['strEngineUnsupported']
244 * @uses PMA_ENGINE_SUPPORT_DEFAULT
245 * @uses PMA_ENGINE_SUPPORT_YES
246 * @uses PMA_ENGINE_SUPPORT_DISABLED
247 * @uses PMA_ENGINE_SUPPORT_NO
248 * @uses $this->support
249 * @uses $this->title
250 * @uses sprintf
251 * @return string The localized message.
252 */
253 function getSupportInformationMessage()
254 {
255 switch ($this->support) {
256 case PMA_ENGINE_SUPPORT_DEFAULT:
257 $message = $GLOBALS['strDefaultEngine'];
258 break;
259 case PMA_ENGINE_SUPPORT_YES:
260 $message = $GLOBALS['strEngineAvailable'];
261 break;
262 case PMA_ENGINE_SUPPORT_DISABLED:
263 $message = $GLOBALS['strEngineDisabled'];
264 break;
265 case PMA_ENGINE_SUPPORT_NO:
266 default:
267 $message = $GLOBALS['strEngineUnsupported'];
268 }
269 return sprintf($message, htmlspecialchars($this->title));
270 }
271  
272 /**
273 * public string[][] getVariables()
274 *
275 * Generates a list of MySQL variables that provide information about this
276 * engine. This function should be overridden when extending this class
277 * for a particular engine.
278 *
279 * @abstract
280 * @return Array The list of variables.
281 */
282 function getVariables()
283 {
284 return array();
285 }
286  
287 /**
288 * returns string with filename for the MySQL helppage
289 * about this storage engne
290 *
291 * @return string mysql helppage filename
292 */
293 function getMysqlHelpPage()
294 {
295 return $this->engine . '-storage-engine';
296 }
297  
298 /**
299 * public string getVariablesLikePattern()
300 *
301 * @abstract
302 * @return string SQL query LIKE pattern
303 */
304 function getVariablesLikePattern()
305 {
306 return false;
307 }
308  
309 /**
310 * public String[] getInfoPages()
311 *
312 * Returns a list of available information pages with labels
313 *
314 * @abstract
315 * @return array The list
316 */
317 function getInfoPages()
318 {
319 return array();
320 }
321  
322 /**
323 * public String getPage()
324 *
325 * Generates the requested information page
326 *
327 * @abstract
328 * @param string $id The page ID
329 *
330 * @return string The page
331 * boolean or false on error.
332 */
333 function getPage($id)
334 {
335 return false;
336 }
337 }
338  
339 ?>