Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / dbi / dummy.lib.php
blob66138bccffe237c208352b78c36f95ce54d77e91
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Fake database driver for testing purposes
6 * It has hardcoded results for given queries what makes easy to use it
7 * in testsuite. Feel free to include other queries which your test will
8 * need.
10 * @package PhpMyAdmin-DBI
11 * @subpackage Dummy
13 if (! defined('PHPMYADMIN')) {
14 exit;
17 /**
18 * Array of queries this "driver" supports
20 $GLOBALS['dummy_queries'] = array(
21 array('query' => 'SELECT 1', 'result' => array(array('1'))),
22 array(
23 'query' => 'SELECT CURRENT_USER();',
24 'result' => array(array('pma_test@localhost')),
26 array(
27 'query' => 'SELECT COUNT(*) FROM mysql.user',
28 'result' => false,
30 array(
31 'query' => 'SHOW MASTER LOGS',
32 'result' => false,
34 array(
35 'query' => 'SHOW STORAGE ENGINES',
36 'result' => array(
37 array('Engine' => 'dummy', 'Support' => 'YES', 'Comment' => 'dummy comment'),
38 array('Engine' => 'dummy2', 'Support' => 'NO', 'Comment' => 'dummy2 comment'),
41 array(
42 'query' => 'SHOW STATUS WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\' OR Variable_name = \'Innodb_page_size\';',
43 'result' => array(
44 array('Innodb_buffer_pool_pages_data', 0),
45 array('Innodb_buffer_pool_pages_dirty', 0),
46 array('Innodb_buffer_pool_pages_flushed', 0),
47 array('Innodb_buffer_pool_pages_free', 0),
48 array('Innodb_buffer_pool_pages_misc', 0),
49 array('Innodb_buffer_pool_pages_total', 4096),
50 array('Innodb_buffer_pool_read_ahead_rnd', 0),
51 array('Innodb_buffer_pool_read_ahead', 0),
52 array('Innodb_buffer_pool_read_ahead_evicted', 0),
53 array('Innodb_buffer_pool_read_requests', 64),
54 array('Innodb_buffer_pool_reads', 32),
55 array('Innodb_buffer_pool_wait_free', 0),
56 array('Innodb_buffer_pool_write_requests', 64),
57 array('Innodb_page_size', 16384),
60 array(
61 'query' => 'SHOW INNODB STATUS;',
62 'result' => false,
64 array(
65 'query' => 'SELECT @@innodb_version;',
66 'result' => array(
67 array('1.1.8'),
70 array(
71 'query' => 'SHOW GLOBAL VARIABLES LIKE \'innodb_file_per_table\';',
72 'result' => array(
73 array('innodb_file_per_table', 'OFF'),
76 array(
77 'query' => 'SHOW GLOBAL VARIABLES LIKE \'innodb_file_format\';',
78 'result' => array(
79 array('innodb_file_format', 'Antelope'),
82 array(
83 'query' => 'SHOW VARIABLES LIKE \'collation_server\'',
84 'result' => array(
85 array('collation_server', 'utf8_general_ci'),
88 array(
89 'query' => 'SHOW VARIABLES LIKE \'language\';',
90 'result' => array(),
92 array(
93 'query' => 'SHOW TABLES FROM `pma_test`;',
94 'result' => array(
95 array('table1'),
96 array('table2'),
99 array(
100 'query' => 'SHOW TABLES FROM `pmadb`',
101 'result' => array(
102 array('column_info'),
105 array(
106 'query' => 'SHOW COLUMNS FROM `pma_test`.`table1`',
107 'columns' => array(
108 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra'
110 'result' => array(
111 array('i', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment'),
112 array('o', 'int(11)', 'NO', 'MUL', 'NULL', ''),
115 array(
116 'query' => 'SHOW INDEXES FROM `pma_test`.`table1` WHERE (Non_unique = 0)',
117 'result' => array(),
119 array(
120 'query' => 'SHOW COLUMNS FROM `pma_test`.`table2`',
121 'columns' => array(
122 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra'
124 'result' => array(
125 array('i', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment'),
126 array('o', 'int(11)', 'NO', 'MUL', 'NULL', ''),
129 array(
130 'query' => 'SHOW INDEXES FROM `pma_test`.`table1`',
131 'result' => array(),
133 array(
134 'query' => 'SHOW INDEXES FROM `pma_test`.`table2`',
135 'result' => array(),
137 array(
138 'query' => 'SHOW COLUMNS FROM `pma`.`table1`',
139 'columns' => array(
140 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra', 'Privileges', 'Comment'
142 'result' => array(
143 array('i', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment', 'select,insert,update,references', ''),
144 array('o', 'varchar(100)', 'NO', 'MUL', 'NULL', '', 'select,insert,update,references', ''),
147 array(
148 'query' => 'SELECT * FROM information_schema.CHARACTER_SETS',
149 'columns' => array('CHARACTER_SET_NAME', 'DEFAULT_COLLATE_NAME', 'DESCRIPTION', 'MAXLEN'),
150 'result' => array(
151 array('utf8', 'utf8_general_ci', 'UTF-8 Unicode', 3),
154 array(
155 'query' => 'SELECT * FROM information_schema.COLLATIONS',
156 'columns' => array(
157 'COLLATION_NAME', 'CHARACTER_SET_NAME', 'ID', 'IS_DEFAULT', 'IS_COMPILED', 'SORTLEN'
159 'result' => array(
160 array('utf8_general_ci', 'utf8', 33, 'Yes', 'Yes', 1),
161 array('utf8_bin', 'utf8', 83, '', 'Yes', 1),
164 array(
165 'query' => 'SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=\'pma_test\' AND `TABLE_TYPE`=\'BASE TABLE\'',
166 'result' => array(),
168 array(
169 'query' => 'SELECT upper(plugin_name) f FROM data_dictionary.plugins WHERE plugin_name IN (\'MYSQL_PASSWORD\',\'ROT13\') AND plugin_type = \'Function\' AND is_active',
170 'columns' => array('f'),
171 'result' => array(array('ROT13')),
173 array(
174 'query' => 'SELECT `column_name`, `mimetype`, `transformation`, `transformation_options` FROM `pmadb`.`column_info` WHERE `db_name` = \'pma_test\' AND `table_name` = \'table1\' AND ( `mimetype` != \'\' OR `transformation` != \'\' OR `transformation_options` != \'\')',
175 'columns' => array('column_name', 'mimetype', 'transformation', 'transformation_options'),
176 'result' => array(
177 array('o', 'text/plain', 'sql'),
180 array(
181 'query' => 'SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = \'pma_test\' AND TABLE_NAME = \'table1\'',
182 'result' => array(),
184 array(
185 'query' => 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`, `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`, `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`, `AVG_ROW_LENGTH` AS `Avg_row_length`, `DATA_LENGTH` AS `Data_length`, `MAX_DATA_LENGTH` AS `Max_data_length`, `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`, `AUTO_INCREMENT` AS `Auto_increment`, `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`, `TABLE_COMMENT` AS `Comment` FROM `information_schema`.`TABLES` t WHERE BINARY `TABLE_SCHEMA` IN (\'pma_test\') AND t.`TABLE_NAME` = \'table1\' ORDER BY Name ASC',
186 'columns' => array('TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'TABLE_TYPE', 'ENGINE', 'VERSION', 'ROW_FORMAT', 'TABLE_ROWS', 'AVG_ROW_LENGTH', 'DATA_LENGTH', 'MAX_DATA_LENGTH', 'INDEX_LENGTH', 'DATA_FREE', 'AUTO_INCREMENT', 'CREATE_TIME', 'UPDATE_TIME', 'CHECK_TIME', 'TABLE_COLLATION', 'CHECKSUM', 'CREATE_OPTIONS', 'TABLE_COMMENT', 'Db', 'Name', 'TABLE_TYPE', 'Engine', 'Type', 'Version', 'Row_format', 'Rows', 'Avg_row_length', 'Data_length', 'Max_data_length', 'Index_length', 'Data_free', 'Auto_increment', 'Create_time', 'Update_time', 'Check_time', 'Collation', 'Checksum', 'Create_options', 'Comment'),
187 'result' => array(
188 array('def', 'smash', 'issues_issue', 'BASE TABLE', 'InnoDB', '10', 'Compact', '9136', '862', '7880704', '0', '1032192', '420478976', '155862', '2012-08-29 13:28:28', 'NULL', 'NULL', 'utf8_general_ci', 'NULL', '', '', 'smash', 'issues_issue', 'BASE TABLE', 'InnoDB', 'InnoDB', '10', 'Compact', '9136', '862', '7880704', '0', '1032192', '420478976', '155862', '2012-08-29 13:28:28', 'NULL', 'NULL', 'utf8_general_ci', 'NULL'),
191 array(
192 'query' => 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`, `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`, `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`, `AVG_ROW_LENGTH` AS `Avg_row_length`, `DATA_LENGTH` AS `Data_length`, `MAX_DATA_LENGTH` AS `Max_data_length`, `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`, `AUTO_INCREMENT` AS `Auto_increment`, `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`, `TABLE_COMMENT` AS `Comment` FROM `information_schema`.`TABLES` t WHERE `TABLE_SCHEMA` IN (\'pma_test\') AND t.`TABLE_NAME` = \'table1\' ORDER BY Name ASC',
193 'columns' => array('TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'TABLE_TYPE', 'ENGINE', 'VERSION', 'ROW_FORMAT', 'TABLE_ROWS', 'AVG_ROW_LENGTH', 'DATA_LENGTH', 'MAX_DATA_LENGTH', 'INDEX_LENGTH', 'DATA_FREE', 'AUTO_INCREMENT', 'CREATE_TIME', 'UPDATE_TIME', 'CHECK_TIME', 'TABLE_COLLATION', 'CHECKSUM', 'CREATE_OPTIONS', 'TABLE_COMMENT', 'Db', 'Name', 'TABLE_TYPE', 'Engine', 'Type', 'Version', 'Row_format', 'Rows', 'Avg_row_length', 'Data_length', 'Max_data_length', 'Index_length', 'Data_free', 'Auto_increment', 'Create_time', 'Update_time', 'Check_time', 'Collation', 'Checksum', 'Create_options', 'Comment'),
194 'result' => array(
195 array('def', 'smash', 'issues_issue', 'BASE TABLE', 'InnoDB', '10', 'Compact', '9136', '862', '7880704', '0', '1032192', '420478976', '155862', '2012-08-29 13:28:28', 'NULL', 'NULL', 'utf8_general_ci', 'NULL', '', '', 'smash', 'issues_issue', 'BASE TABLE', 'InnoDB', 'InnoDB', '10', 'Compact', '9136', '862', '7880704', '0', '1032192', '420478976', '155862', '2012-08-29 13:28:28', 'NULL', 'NULL', 'utf8_general_ci', 'NULL'),
198 array(
199 'query' => 'SELECT COUNT(*) FROM `pma_test`.`table1`',
200 'result' => array(array(0)),
202 array(
203 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`USER_PRIVILEGES` WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\' AND PRIVILEGE_TYPE=\'TRIGGER\'',
204 'result' => array(),
206 array(
207 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES` WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\' AND PRIVILEGE_TYPE=\'TRIGGER\' AND TABLE_SCHEMA=\'pma\\\\_test\'',
209 'result' => array(),
211 array(
212 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`TABLE_PRIVILEGES` WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\' AND PRIVILEGE_TYPE=\'TRIGGER\' AND TABLE_SCHEMA=\'pma\\\\_test\' AND TABLE_NAME=\'table1\'',
213 'result' => array(),
215 array(
216 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`USER_PRIVILEGES` WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\' AND PRIVILEGE_TYPE=\'EVENT\'',
217 'result' => array(),
219 array(
220 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES` WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\' AND PRIVILEGE_TYPE=\'EVENT\' AND TABLE_SCHEMA=\'pma\\\\_test\'',
222 'result' => array(),
224 array(
225 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`TABLE_PRIVILEGES` WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\' AND PRIVILEGE_TYPE=\'EVENT\' AND TABLE_SCHEMA=\'pma\\\\_test\' AND TABLE_NAME=\'table1\'',
226 'result' => array(),
228 array(
229 'query' => 'RENAME TABLE `pma_test`.`table1` TO `pma_test`.`table3`;',
230 'result' => array(),
232 array(
233 'query' => 'SELECT TRIGGER_SCHEMA, TRIGGER_NAME, EVENT_MANIPULATION, EVENT_OBJECT_TABLE, ACTION_TIMING, ACTION_STATEMENT, EVENT_OBJECT_SCHEMA, EVENT_OBJECT_TABLE, DEFINER FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA= \'pma_test\' AND EVENT_OBJECT_TABLE = \'table1\';',
234 'result' => array(),
236 array(
237 'query' => 'SHOW TABLES FROM `pma`;',
238 'result' => array(),
240 array(
241 'query' => "SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES` WHERE GRANTEE='''pma_test''@''localhost''' AND PRIVILEGE_TYPE='EVENT' AND TABLE_SCHEMA='pma'",
242 'result' => array(),
244 array(
245 'query' => "SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES` WHERE GRANTEE='''pma_test''@''localhost''' AND PRIVILEGE_TYPE='TRIGGER' AND TABLE_SCHEMA='pma'",
246 'result' => array(),
251 * Current database.
253 $GLOBALS['dummy_db'] = '';
255 /* Some basic setup for dummy driver */
256 $GLOBALS['userlink'] = 1;
257 $GLOBALS['controllink'] = 2;
258 $GLOBALS['cfg']['DBG']['sql'] = false;
259 if (! defined('PMA_DRIZZLE')) {
260 define('PMA_DRIZZLE', 0);
265 * Run the multi query and output the results
267 * @param mysqli $link mysqli object
268 * @param string $query multi query statement to execute
270 * @return boolean false always false since mysql extention not support
271 * for multi query executions
273 function PMA_DBI_real_multi_query($link, $query)
275 return false;
279 * connects to the database server
281 * @param string $user mysql user name
282 * @param string $password mysql user password
283 * @param bool $is_controluser whether this is a control user connection
284 * @param array $server host/port/socket/persistent
285 * @param bool $auxiliary_connection (when true, don't go back to login if
286 * connection fails)
288 * @return mixed false on error or a mysqli object on success
290 function PMA_DBI_connect(
291 $user, $password, $is_controluser = false, $server = null,
292 $auxiliary_connection = false
294 return true;
298 * selects given database
300 * @param string $dbname name of db to select
301 * @param resource $link mysql link resource
303 * @return bool
305 function PMA_DBI_select_db($dbname, $link = null)
307 $GLOBALS['dummy_db'] = $dbname;
308 return true;
312 * runs a query and returns the result
314 * @param string $query query to run
315 * @param resource $link mysql link resource
316 * @param int $options query options
318 * @return mixed
320 function PMA_DBI_real_query($query, $link = null, $options = 0)
322 $query = trim(preg_replace('/ */', ' ', str_replace("\n", ' ', $query)));
323 for ($i = 0; $i < count($GLOBALS['dummy_queries']); $i++) {
324 if ($GLOBALS['dummy_queries'][$i]['query'] == $query) {
325 $GLOBALS['dummy_queries'][$i]['pos'] = 0;
326 if (is_array($GLOBALS['dummy_queries'][$i]['result'])) {
327 return $i;
328 } else {
329 return false;
333 echo "Not supported query: $query\n";
334 return false;
338 * returns result data from $result
340 * @param resource $result result MySQL result
342 * @return array
344 function PMA_DBI_fetch_any($result)
346 $query_data = $GLOBALS['dummy_queries'][$result];
347 if ($query_data['pos'] >= count($query_data['result'])) {
348 return false;
350 $ret = $query_data['result'][$query_data['pos']];
351 $GLOBALS['dummy_queries'][$result]['pos'] += 1;
352 return $ret;
356 * returns array of rows with associative and numeric keys from $result
358 * @param resource $result result MySQL result
360 * @return array
362 function PMA_DBI_fetch_array($result)
364 $data = PMA_DBI_fetch_any($result);
365 if (is_array($data) && isset($GLOBALS['dummy_queries'][$result]['columns'])) {
366 foreach ($data as $key => $val) {
367 $data[$GLOBALS['dummy_queries'][$result]['columns'][$key]] = $val;
369 return $data;
371 return $data;
375 * returns array of rows with associative keys from $result
377 * @param resource $result MySQL result
379 * @return array
381 function PMA_DBI_fetch_assoc($result)
383 $data = PMA_DBI_fetch_any($result);
384 if (is_array($data) && isset($GLOBALS['dummy_queries'][$result]['columns'])) {
385 $ret = array();
386 foreach ($data as $key => $val) {
387 $ret[$GLOBALS['dummy_queries'][$result]['columns'][$key]] = $val;
389 return $ret;
391 return $data;
395 * returns array of rows with numeric keys from $result
397 * @param resource $result MySQL result
399 * @return array
401 function PMA_DBI_fetch_row($result)
403 $data = PMA_DBI_fetch_any($result);
404 return $data;
408 * Adjusts the result pointer to an arbitrary row in the result
410 * @param resource $result database result
411 * @param integer $offset offset to seek
413 * @return bool true on success, false on failure
415 function PMA_DBI_data_seek($result, $offset)
417 if ($offset > count($GLOBALS['dummy_queries'][$result]['result'])) {
418 return false;
420 $GLOBALS['dummy_queries'][$result]['pos'] = $offset;
421 return true;
425 * Frees memory associated with the result
427 * @param resource $result database result
429 * @return void
431 function PMA_DBI_free_result($result)
433 return;
437 * Check if there are any more query results from a multi query
439 * @return bool false
441 function PMA_DBI_more_results()
443 return false;
447 * Prepare next result from multi_query
449 * @return boo false
451 function PMA_DBI_next_result()
453 return false;
457 * returns the number of rows returned by last query
459 * @param resource $result MySQL result
461 * @return string|int
463 function PMA_DBI_num_rows($result)
465 if (!is_bool($result)) {
466 return count($GLOBALS['dummy_queries'][$result]['result']);
467 } else {
468 return 0;
473 * returns the number of rows affected by last query
475 * @param resource $link the mysql object
476 * @param bool $get_from_cache whether to retrieve from cache
478 * @return string|int
480 function PMA_DBI_affected_rows($link = null, $get_from_cache = true)
482 return 0;
486 * return number of fields in given $result
488 * @param resource $result MySQL result
490 * @return int field count
492 function PMA_DBI_num_fields($result)
494 if (isset($GLOBALS['dummy_queries'][$result]['columns'])) {
495 return count($GLOBALS['dummy_queries'][$result]['columns']);
496 } else {
497 return 0;
502 * returns last error message or false if no errors occured
504 * @param resource $link mysql link
506 * @return string|bool $error or false
508 function PMA_DBI_getError($link = null)
510 return false;