2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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
10 * @package PhpMyAdmin-DBI
13 declare(strict_types
=1);
15 namespace PhpMyAdmin\Tests\Stubs
;
17 use PhpMyAdmin\Dbi\DbiExtension
;
20 * Fake database driver for testing purposes
22 * It has hardcoded results for given queries what makes easy to use it
23 * in testsuite. Feel free to include other queries which your test will
26 * @package PhpMyAdmin-DBI
29 class DbiDummy
implements DbiExtension
34 private $_queries = [];
39 public const OFFSET_GLOBAL
= 1000;
42 * DbiDummy constructor.
44 public function __construct()
50 * connects to the database server
52 * @param string $user mysql user name
53 * @param string $password mysql user password
54 * @param array $server host/port/socket/persistent
56 * @return mixed false on error or a mysqli object on success
58 public function connect(
67 * selects given database
69 * @param string $dbname name of db to select
70 * @param resource $link mysql link resource
74 public function selectDb($dbname, $link)
76 $GLOBALS['dummy_db'] = $dbname;
82 * runs a query and returns the result
84 * @param string $query query to run
85 * @param resource $link mysql link resource
86 * @param int $options query options
90 public function realQuery($query, $link = null, $options = 0)
92 $query = trim(preg_replace('/ */', ' ', str_replace("\n", ' ', $query)));
93 for ($i = 0, $nb = count($this->_queries
); $i < $nb; $i++
) {
94 if ($this->_queries
[$i]['query'] != $query) {
98 $this->_queries
[$i]['pos'] = 0;
99 if (! is_array($this->_queries
[$i]['result'])) {
105 for ($i = 0, $nb = count($GLOBALS['dummy_queries']); $i < $nb; $i++
) {
106 if ($GLOBALS['dummy_queries'][$i]['query'] != $query) {
110 $GLOBALS['dummy_queries'][$i]['pos'] = 0;
111 if (! is_array($GLOBALS['dummy_queries'][$i]['result'])) {
115 return $i + self
::OFFSET_GLOBAL
;
117 echo "Not supported query: $query\n";
123 * Run the multi query and output the results
125 * @param resource $link connection object
126 * @param string $query multi query statement to execute
130 public function realMultiQuery($link, $query)
136 * returns result data from $result
138 * @param object $result MySQL result
142 public function fetchAny($result)
144 $query_data = &$this->getQueryData($result);
145 if ($query_data['pos'] >= count((array) $query_data['result'])) {
148 $ret = $query_data['result'][$query_data['pos']];
149 $query_data['pos'] +
= 1;
155 * returns array of rows with associative and numeric keys from $result
157 * @param object $result result MySQL result
161 public function fetchArray($result)
163 $query_data = &$this->getQueryData($result);
164 $data = $this->fetchAny($result);
165 if (! is_array($data)
166 ||
! isset($query_data['columns'])
171 foreach ($data as $key => $val) {
172 $data[$query_data['columns'][$key]] = $val;
179 * returns array of rows with associative keys from $result
181 * @param object $result MySQL result
185 public function fetchAssoc($result)
187 $data = $this->fetchAny($result);
188 $query_data = &$this->getQueryData($result);
189 if (! is_array($data) ||
! isset($query_data['columns'])) {
194 foreach ($data as $key => $val) {
195 $ret[$query_data['columns'][$key]] = $val;
202 * returns array of rows with numeric keys from $result
204 * @param object $result MySQL result
208 public function fetchRow($result)
210 return $this->fetchAny($result);
214 * Adjusts the result pointer to an arbitrary row in the result
216 * @param object $result database result
217 * @param integer $offset offset to seek
219 * @return bool true on success, false on failure
221 public function dataSeek($result, $offset)
223 $query_data = &$this->getQueryData($result);
224 if ($offset > count($query_data['result'])) {
227 $query_data['pos'] = $offset;
233 * Frees memory associated with the result
235 * @param object $result database result
239 public function freeResult($result)
245 * Check if there are any more query results from a multi query
247 * @param resource $link the connection object
251 public function moreResults($link)
257 * Prepare next result from multi_query
259 * @param resource $link the connection object
261 * @return boolean false
263 public function nextResult($link)
269 * Store the result returned from multi query
271 * @param resource $link the connection object
273 * @return mixed false when empty results / result set when not empty
275 public function storeResult($link)
281 * Returns a string representing the type of connection used
283 * @param resource $link mysql link
285 * @return string type of connection used
287 public function getHostInfo($link)
293 * Returns the version of the MySQL protocol used
295 * @param resource $link mysql link
297 * @return integer version of the MySQL protocol used
299 public function getProtoInfo($link)
305 * returns a string that represents the client library version
307 * @param resource $link connection link
309 * @return string MySQL client library version
311 public function getClientInfo($link)
317 * returns last error message or false if no errors occurred
319 * @param resource $link connection link
321 * @return string|bool error or false
323 public function getError($link)
329 * returns the number of rows returned by last query
331 * @param object $result MySQL result
335 public function numRows($result)
337 if (is_bool($result)) {
341 $query_data = &$this->getQueryData($result);
343 return count($query_data['result']);
347 * returns the number of rows affected by last query
349 * @param resource $link the mysql object
350 * @param bool $get_from_cache whether to retrieve from cache
354 public function affectedRows($link = null, $get_from_cache = true)
360 * returns metainfo for fields in $result
362 * @param object $result result set identifier
364 * @return array meta info for fields in $result
366 public function getFieldsMeta($result)
372 * return number of fields in given $result
374 * @param object $result MySQL result
376 * @return int field count
378 public function numFields($result)
380 $query_data = &$this->getQueryData($result);
381 if (! isset($query_data['columns'])) {
385 return count($query_data['columns']);
389 * returns the length of the given field $i in $result
391 * @param object $result result set identifier
392 * @param int $i field
394 * @return int length of field
396 public function fieldLen($result, $i)
402 * returns name of $i. field in $result
404 * @param object $result result set identifier
405 * @param int $i field
407 * @return string name of $i. field in $result
409 public function fieldName($result, $i)
415 * returns concatenated string of human readable field flags
417 * @param object $result result set identifier
418 * @param int $i field
420 * @return string field flags
422 public function fieldFlags($result, $i)
428 * returns properly escaped string for use in MySQL queries
430 * @param mixed $link database link
431 * @param string $str string to be escaped
433 * @return string a MySQL escaped string
435 public function escapeString($link, $str)
437 return addslashes($str);
441 * Adds query result for testing
443 * @param string $query SQL
444 * @param array $result Expected result
448 public function setResult($query, $result)
450 $this->_queries
[] = [
457 * Return query data for ID
459 * @param object $result result set identifier
463 private function &getQueryData($result)
465 if ($result >= self
::OFFSET_GLOBAL
) {
466 return $GLOBALS['dummy_queries'][$result - self
::OFFSET_GLOBAL
];
468 return $this->_queries
[$result];
475 private function init(): void
478 * Array of queries this "driver" supports
480 $GLOBALS['dummy_queries'] = [
482 'query' => 'SELECT 1',
486 'query' => 'SELECT CURRENT_USER();',
487 'result' => [['pma_test@localhost']],
490 'query' => "SHOW VARIABLES LIKE 'lower_case_table_names'",
493 'lower_case_table_names',
499 'query' => 'SELECT 1 FROM mysql.user LIMIT 1',
503 'query' => "SELECT 1 FROM `INFORMATION_SCHEMA`.`USER_PRIVILEGES`"
504 . " WHERE `PRIVILEGE_TYPE` = 'CREATE USER'"
505 . " AND '''pma_test''@''localhost''' LIKE `GRANTEE` LIMIT 1",
509 'query' => "SELECT 1 FROM (SELECT `GRANTEE`, `IS_GRANTABLE`"
510 . " FROM `INFORMATION_SCHEMA`.`COLUMN_PRIVILEGES`"
511 . " UNION SELECT `GRANTEE`, `IS_GRANTABLE`"
512 . " FROM `INFORMATION_SCHEMA`.`TABLE_PRIVILEGES`"
513 . " UNION SELECT `GRANTEE`, `IS_GRANTABLE`"
514 . " FROM `INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES`"
515 . " UNION SELECT `GRANTEE`, `IS_GRANTABLE`"
516 . " FROM `INFORMATION_SCHEMA`.`USER_PRIVILEGES`) t"
517 . " WHERE `IS_GRANTABLE` = 'YES'"
518 . " AND '''pma_test''@''localhost''' LIKE `GRANTEE` LIMIT 1",
522 'query' => 'SHOW MASTER LOGS',
526 'query' => 'SHOW STORAGE ENGINES',
531 'Comment' => 'dummy comment',
534 'Engine' => 'dummy2',
536 'Comment' => 'dummy2 comment',
539 'Engine' => 'FEDERATED',
541 'Comment' => 'Federated MySQL storage engine',
546 'Comment' => 'Pbxt storage engine',
551 'query' => 'SHOW STATUS WHERE Variable_name'
552 . ' LIKE \'Innodb\\_buffer\\_pool\\_%\''
553 . ' OR Variable_name = \'Innodb_page_size\';',
556 'Innodb_buffer_pool_pages_data',
560 'Innodb_buffer_pool_pages_dirty',
564 'Innodb_buffer_pool_pages_flushed',
568 'Innodb_buffer_pool_pages_free',
572 'Innodb_buffer_pool_pages_misc',
576 'Innodb_buffer_pool_pages_total',
580 'Innodb_buffer_pool_read_ahead_rnd',
584 'Innodb_buffer_pool_read_ahead',
588 'Innodb_buffer_pool_read_ahead_evicted',
592 'Innodb_buffer_pool_read_requests',
596 'Innodb_buffer_pool_reads',
600 'Innodb_buffer_pool_wait_free',
604 'Innodb_buffer_pool_write_requests',
614 'query' => 'SHOW ENGINE INNODB STATUS;',
618 'query' => 'SELECT @@innodb_version;',
624 'query' => 'SELECT @@disabled_storage_engines',
630 'query' => 'SHOW GLOBAL VARIABLES LIKE \'innodb_file_per_table\';',
633 'innodb_file_per_table',
639 'query' => 'SHOW GLOBAL VARIABLES LIKE \'innodb_file_format\';',
642 'innodb_file_format',
648 'query' => 'SELECT @@collation_server',
654 'query' => 'SELECT @@lc_messages;',
658 'query' => 'SHOW SESSION VARIABLES LIKE \'FOREIGN_KEY_CHECKS\';',
661 'foreign_key_checks',
667 'query' => 'SHOW TABLES FROM `pma_test`;',
674 'query' => 'SHOW TABLES FROM `pmadb`',
680 'query' => 'SHOW COLUMNS FROM `pma_test`.`table1`',
709 'query' => 'SHOW INDEXES FROM `pma_test`.`table1` WHERE (Non_unique = 0)',
713 'query' => 'SHOW COLUMNS FROM `pma_test`.`table2`',
742 'query' => 'SHOW INDEXES FROM `pma_test`.`table1`',
746 'query' => 'SHOW INDEXES FROM `pma_test`.`table2`',
750 'query' => 'SHOW COLUMNS FROM `pma`.`table1`',
769 'select,insert,update,references',
779 'select,insert,update,references',
785 'query' => 'SELECT `CHARACTER_SET_NAME` AS `Charset`,'
786 . ' `DEFAULT_COLLATE_NAME` AS `Default collation`,'
787 . ' `DESCRIPTION` AS `Description`,'
788 . ' `MAXLEN` AS `Maxlen`'
789 . ' FROM `information_schema`.`CHARACTER_SETS`',
806 'cp1252 West European',
812 'query' => 'SELECT `COLLATION_NAME` AS `Collation`,'
813 . ' `CHARACTER_SET_NAME` AS `Charset`,'
815 . ' `IS_DEFAULT` AS `Default`,'
816 . ' `IS_COMPILED` AS `Compiled`,'
817 . ' `SORTLEN` AS `Sortlen`'
818 . ' FROM `information_schema`.`COLLATIONS`',
855 'query' => 'SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES`'
856 . ' WHERE `TABLE_SCHEMA`=\'pma_test\' AND `TABLE_TYPE` IN (\'BASE TABLE\', \'SYSTEM VERSIONED\')',
860 'query' => 'SELECT `column_name`, `mimetype`, `transformation`,'
861 . ' `transformation_options`, `input_transformation`,'
862 . ' `input_transformation_options`'
863 . ' FROM `pmadb`.`column_info`'
864 . ' WHERE `db_name` = \'pma_test\' AND `table_name` = \'table1\''
865 . ' AND ( `mimetype` != \'\' OR `transformation` != \'\''
866 . ' OR `transformation_options` != \'\''
867 . ' OR `input_transformation` != \'\''
868 . ' OR `input_transformation_options` != \'\')',
873 'transformation_options',
874 'input_transformation',
875 'input_transformation_options',
897 'query' => 'SELECT TABLE_NAME FROM information_schema.VIEWS'
898 . ' WHERE TABLE_SCHEMA = \'pma_test\' AND TABLE_NAME = \'table1\'',
902 'query' => 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`,'
903 . ' `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`,'
904 . ' `ENGINE` AS `Type`, `VERSION` AS `Version`,'
905 . ' `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`,'
906 . ' `AVG_ROW_LENGTH` AS `Avg_row_length`,'
907 . ' `DATA_LENGTH` AS `Data_length`,'
908 . ' `MAX_DATA_LENGTH` AS `Max_data_length`,'
909 . ' `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`,'
910 . ' `AUTO_INCREMENT` AS `Auto_increment`,'
911 . ' `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`,'
912 . ' `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`,'
913 . ' `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`,'
914 . ' `TABLE_COMMENT` AS `Comment`'
915 . ' FROM `information_schema`.`TABLES` t'
916 . ' WHERE `TABLE_SCHEMA` IN (\'pma_test\')'
917 . ' AND t.`TABLE_NAME` = \'table1\' ORDER BY Name ASC',
978 '2012-08-29 13:28:28',
999 '2012-08-29 13:28:28',
1008 'query' => 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`,'
1009 . ' `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`,'
1010 . ' `ENGINE` AS `Type`, `VERSION` AS `Version`,'
1011 . ' `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`,'
1012 . ' `AVG_ROW_LENGTH` AS `Avg_row_length`,'
1013 . ' `DATA_LENGTH` AS `Data_length`,'
1014 . ' `MAX_DATA_LENGTH` AS `Max_data_length`,'
1015 . ' `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`,'
1016 . ' `AUTO_INCREMENT` AS `Auto_increment`,'
1017 . ' `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`,'
1018 . ' `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`,'
1019 . ' `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`,'
1020 . ' `TABLE_COMMENT` AS `Comment`'
1021 . ' FROM `information_schema`.`TABLES` t'
1022 . ' WHERE `TABLE_SCHEMA` IN (\'pma_test\')'
1023 . ' AND t.`TABLE_NAME` = \'table1\' ORDER BY Name ASC',
1084 '2012-08-29 13:28:28',
1105 '2012-08-29 13:28:28',
1114 'query' => 'SELECT COUNT(*) FROM `pma_test`.`table1`',
1118 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
1119 . '`USER_PRIVILEGES`'
1120 . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
1121 . ' AND PRIVILEGE_TYPE=\'TRIGGER\'',
1125 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
1126 . '`SCHEMA_PRIVILEGES`'
1127 . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
1128 . ' AND PRIVILEGE_TYPE=\'TRIGGER\' AND \'pma_test\''
1129 . ' LIKE `TABLE_SCHEMA`',
1133 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
1134 . '`TABLE_PRIVILEGES`'
1135 . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
1136 . ' AND PRIVILEGE_TYPE=\'TRIGGER\' AND \'pma_test\''
1137 . ' LIKE `TABLE_SCHEMA` AND TABLE_NAME=\'table1\'',
1141 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
1142 . '`USER_PRIVILEGES`'
1143 . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
1144 . ' AND PRIVILEGE_TYPE=\'EVENT\'',
1148 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
1149 . '`SCHEMA_PRIVILEGES`'
1150 . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
1151 . ' AND PRIVILEGE_TYPE=\'EVENT\' AND \'pma_test\''
1152 . ' LIKE `TABLE_SCHEMA`',
1156 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
1157 . '`TABLE_PRIVILEGES`'
1158 . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
1159 . ' AND PRIVILEGE_TYPE=\'EVENT\''
1160 . ' AND TABLE_SCHEMA=\'pma\\\\_test\' AND TABLE_NAME=\'table1\'',
1164 'query' => 'RENAME TABLE `pma_test`.`table1` TO `pma_test`.`table3`;',
1168 'query' => 'SELECT TRIGGER_SCHEMA, TRIGGER_NAME, EVENT_MANIPULATION,'
1169 . ' EVENT_OBJECT_TABLE, ACTION_TIMING, ACTION_STATEMENT, '
1170 . 'EVENT_OBJECT_SCHEMA, EVENT_OBJECT_TABLE, DEFINER'
1171 . ' FROM information_schema.TRIGGERS'
1172 . ' WHERE EVENT_OBJECT_SCHEMA= \'pma_test\''
1173 . ' AND EVENT_OBJECT_TABLE = \'table1\';',
1177 'query' => 'SHOW TABLES FROM `pma`;',
1181 'query' => "SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`."
1182 . "`SCHEMA_PRIVILEGES` WHERE GRANTEE='''pma_test''@''localhost'''"
1183 . " AND PRIVILEGE_TYPE='EVENT' AND TABLE_SCHEMA='pma'",
1187 'query' => "SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`."
1188 . "`SCHEMA_PRIVILEGES` WHERE GRANTEE='''pma_test''@''localhost'''"
1189 . " AND PRIVILEGE_TYPE='TRIGGER' AND TABLE_SCHEMA='pma'",
1193 'query' => 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA'
1194 . ' WHERE SCHEMA_NAME = \'pma_test\' LIMIT 1',
1195 'columns' => ['DEFAULT_COLLATION_NAME'],
1197 ['utf8_general_ci'],
1201 'query' => 'SELECT @@collation_database',
1202 'columns' => ['@@collation_database'],
1208 'query' => "SHOW TABLES FROM `phpmyadmin`",
1212 'query' => "SELECT tracking_active FROM `pmadb`.`tracking`" .
1213 " WHERE db_name = 'pma_test_db'" .
1214 " AND table_name = 'pma_test_table'" .
1215 " ORDER BY version DESC LIMIT 1",
1216 'columns' => ['tracking_active'],
1222 'query' => "SELECT tracking_active FROM `pmadb`.`tracking`" .
1223 " WHERE db_name = 'pma_test_db'" .
1224 " AND table_name = 'pma_test_table2'" .
1225 " ORDER BY version DESC LIMIT 1",
1229 'query' => "SHOW SLAVE STATUS",
1232 'Slave_IO_State' => 'running',
1233 'Master_Host' => 'locahost',
1234 'Master_User' => 'Master_User',
1235 'Master_Port' => '1002',
1236 'Connect_Retry' => 'Connect_Retry',
1237 'Master_Log_File' => 'Master_Log_File',
1238 'Read_Master_Log_Pos' => 'Read_Master_Log_Pos',
1239 'Relay_Log_File' => 'Relay_Log_File',
1240 'Relay_Log_Pos' => 'Relay_Log_Pos',
1241 'Relay_Master_Log_File' => 'Relay_Master_Log_File',
1242 'Slave_IO_Running' => 'NO',
1243 'Slave_SQL_Running' => 'NO',
1244 'Replicate_Do_DB' => 'Replicate_Do_DB',
1245 'Replicate_Ignore_DB' => 'Replicate_Ignore_DB',
1246 'Replicate_Do_Table' => 'Replicate_Do_Table',
1247 'Replicate_Ignore_Table' => 'Replicate_Ignore_Table',
1248 'Replicate_Wild_Do_Table' => 'Replicate_Wild_Do_Table',
1249 'Replicate_Wild_Ignore_Table' => 'Replicate_Wild_Ignore_Table',
1250 'Last_Errno' => 'Last_Errno',
1251 'Last_Error' => 'Last_Error',
1252 'Skip_Counter' => 'Skip_Counter',
1253 'Exec_Master_Log_Pos' => 'Exec_Master_Log_Pos',
1254 'Relay_Log_Space' => 'Relay_Log_Space',
1255 'Until_Condition' => 'Until_Condition',
1256 'Until_Log_File' => 'Until_Log_File',
1257 'Until_Log_Pos' => 'Until_Log_Pos',
1258 'Master_SSL_Allowed' => 'Master_SSL_Allowed',
1259 'Master_SSL_CA_File' => 'Master_SSL_CA_File',
1260 'Master_SSL_CA_Path' => 'Master_SSL_CA_Path',
1261 'Master_SSL_Cert' => 'Master_SSL_Cert',
1262 'Master_SSL_Cipher' => 'Master_SSL_Cipher',
1263 'Master_SSL_Key' => 'Master_SSL_Key',
1264 'Seconds_Behind_Master' => 'Seconds_Behind_Master',
1269 'query' => "SHOW MASTER STATUS",
1272 "File" => "master-bin.000030",
1273 "Position" => "107",
1274 "Binlog_Do_DB" => "Binlog_Do_DB",
1275 "Binlog_Ignore_DB" => "Binlog_Ignore_DB",
1280 'query' => "SHOW GRANTS",
1284 'query' => "SELECT `SCHEMA_NAME` FROM `INFORMATION_SCHEMA`.`SCHEMATA`, "
1285 . "(SELECT DB_first_level FROM ( SELECT DISTINCT "
1286 . "SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) DB_first_level "
1287 . "FROM INFORMATION_SCHEMA.SCHEMATA WHERE TRUE ) t ORDER BY "
1288 . "DB_first_level ASC LIMIT 0, 100) t2 WHERE TRUE AND 1 = LOCATE("
1289 . "CONCAT(DB_first_level, '_'), CONCAT(SCHEMA_NAME, '_')) "
1290 . "ORDER BY SCHEMA_NAME ASC",
1296 'query' => "SELECT COUNT(*) FROM ( SELECT DISTINCT SUBSTRING_INDEX("
1297 . "SCHEMA_NAME, '_', 1) DB_first_level "
1298 . "FROM INFORMATION_SCHEMA.SCHEMATA WHERE TRUE ) t",
1304 'query' => "SELECT `PARTITION_METHOD` "
1305 . "FROM `information_schema`.`PARTITIONS` "
1306 . "WHERE `TABLE_SCHEMA` = 'db' AND `TABLE_NAME` = 'table' LIMIT 1",
1310 'query' => 'SHOW PLUGINS',
1313 'Name' => 'partition',
1314 'Status' => 'ACTIVE',
1315 'Type' => 'STORAGE ENGINE',
1322 'query' => 'SELECT * FROM information_schema.PLUGINS ORDER BY PLUGIN_TYPE, PLUGIN_NAME',
1325 'PLUGIN_NAME' => 'BLACKHOLE',
1326 'PLUGIN_VERSION' => '1.0',
1327 'PLUGIN_STATUS' => 'ACTIVE',
1328 'PLUGIN_TYPE' => 'STORAGE ENGINE',
1329 'PLUGIN_TYPE_VERSION' => '100316.0',
1330 'PLUGIN_LIBRARY' => 'ha_blackhole.so',
1331 'PLUGIN_LIBRARY_VERSION' => '1.13',
1332 'PLUGIN_AUTHOR' => 'MySQL AB',
1333 'PLUGIN_DESCRIPTION' => '/dev/null storage engine (anything you write to it disappears)',
1334 'PLUGIN_LICENSE' => 'GPL',
1335 'LOAD_OPTION' => 'ON',
1336 'PLUGIN_MATURITY' => 'Stable',
1337 'PLUGIN_AUTH_VERSION' => '1.0',
1342 'query' => "SHOW FULL TABLES FROM `default` WHERE `Table_type`IN('BASE TABLE', 'SYSTEM VERSIONED')",
1355 'query' => "SHOW FULL TABLES FROM `default` "
1356 . "WHERE `Table_type`NOT IN('BASE TABLE', 'SYSTEM VERSIONED')",
1360 'query' => "SHOW FUNCTION STATUS WHERE `Db`='default'",
1361 'result' => [["Name" => "testFunction"]],
1364 'query' => "SHOW PROCEDURE STATUS WHERE `Db`='default'",
1368 'query' => "SHOW EVENTS FROM `default`",
1372 'query' => "FLUSH PRIVILEGES",
1376 'query' => "SELECT * FROM `mysql`.`db` LIMIT 1",
1380 'query' => "SELECT * FROM `mysql`.`columns_priv` LIMIT 1",
1384 'query' => "SELECT * FROM `mysql`.`tables_priv` LIMIT 1",
1388 'query' => "SELECT * FROM `mysql`.`procs_priv` LIMIT 1",
1392 'query' => 'DELETE FROM `mysql`.`db` WHERE `host` = "" '
1393 . 'AND `Db` = "" AND `User` = ""',
1397 'query' => 'DELETE FROM `mysql`.`columns_priv` WHERE '
1398 . '`host` = "" AND `Db` = "" AND `User` = ""',
1402 'query' => 'DELETE FROM `mysql`.`tables_priv` WHERE '
1403 . '`host` = "" AND `Db` = "" AND `User` = "" AND Table_name = ""',
1407 'query' => 'DELETE FROM `mysql`.`procs_priv` WHERE '
1408 . '`host` = "" AND `Db` = "" AND `User` = "" AND `Routine_name` = "" '
1409 . 'AND `Routine_type` = ""',
1413 'query' => 'SELECT `plugin` FROM `mysql`.`user` WHERE '
1414 . '`User` = "pma_username" AND `Host` = "pma_hostname" LIMIT 1',
1418 'query' => 'SELECT @@default_authentication_plugin',
1420 ['@@default_authentication_plugin' => 'mysql_native_password'],
1424 'query' => "SELECT TABLE_NAME FROM information_schema.VIEWS WHERE "
1425 . "TABLE_SCHEMA = 'db' AND TABLE_NAME = 'table'",
1429 'query' => "SELECT *, `TABLE_SCHEMA` AS `Db`, "
1430 . "`TABLE_NAME` AS `Name`, `TABLE_TYPE` AS `TABLE_TYPE`, "
1431 . "`ENGINE` AS `Engine`, `ENGINE` AS `Type`, "
1432 . "`VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`, "
1433 . "`TABLE_ROWS` AS `Rows`, `AVG_ROW_LENGTH` AS `Avg_row_length`, "
1434 . "`DATA_LENGTH` AS `Data_length`, "
1435 . "`MAX_DATA_LENGTH` AS `Max_data_length`, "
1436 . "`INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`, "
1437 . "`AUTO_INCREMENT` AS `Auto_increment`, "
1438 . "`CREATE_TIME` AS `Create_time`, "
1439 . "`UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`, "
1440 . "`TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`, "
1441 . "`CREATE_OPTIONS` AS `Create_options`, "
1442 . "`TABLE_COMMENT` AS `Comment` "
1443 . "FROM `information_schema`.`TABLES` t "
1444 . "WHERE `TABLE_SCHEMA` IN ('db') "
1445 . "AND t.`TABLE_NAME` = 'table' ORDER BY Name ASC",
1449 'query' => "SHOW TABLE STATUS FROM `db` WHERE `Name` LIKE 'table%'",
1453 'query' => "SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`,"
1454 . " `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`,"
1455 . " `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`,"
1456 . " `TABLE_ROWS` AS `Rows`, `AVG_ROW_LENGTH` AS `Avg_row_length`,"
1457 . " `DATA_LENGTH` AS `Data_length`, `MAX_DATA_LENGTH` AS `Max_data_length`,"
1458 . " `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`,"
1459 . " `AUTO_INCREMENT` AS `Auto_increment`, `CREATE_TIME` AS `Create_time`,"
1460 . " `UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`,"
1461 . " `TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`,"
1462 . " `CREATE_OPTIONS` AS `Create_options`, `TABLE_COMMENT` AS `Comment`"
1463 . " FROM `information_schema`.`TABLES` t WHERE `TABLE_SCHEMA` IN ('table1')"
1464 . " AND t.`TABLE_NAME` = 'pma_test' ORDER BY Name ASC",
1521 '281474976710655',// MyISAM
1525 '2014-06-24 17:30:00',
1526 '2018-06-25 18:35:12',
1527 '2015-04-24 19:30:59',
1528 'utf8mb4_general_ci',
1530 'row_format=REDUNDANT',
1531 'Test comment for "table1" in \'pma_test\'',
1539 '281474976710655',// MyISAM
1543 '2014-06-24 17:30:00',
1544 '2018-06-25 18:35:12',
1545 '2015-04-24 19:30:59',
1546 'utf8mb4_general_ci',
1548 'row_format=REDUNDANT',
1549 'Test comment for "table1" in \'pma_test\'',
1554 'query' => "SHOW TABLE STATUS FROM `table1` WHERE `Name` LIKE 'pma\_test%'",
1586 '281474976710655',// MyISAM
1590 '2014-06-24 17:30:00',
1591 '2018-06-25 18:35:12',
1592 '2015-04-24 19:30:59',
1593 'utf8mb4_general_ci',
1595 'row_format=REDUNDANT',
1596 'Test comment for "table1" in \'pma_test\'',
1601 'query' => "SELECT *, CAST(BIN_NAME AS CHAR CHARACTER SET utf8) AS SCHEMA_NAME FROM (SELECT BINARY s.SCHEMA_NAME AS BIN_NAME, s.DEFAULT_COLLATION_NAME FROM `information_schema`.SCHEMATA s WHERE `SCHEMA_NAME` LIKE 'pma_test' GROUP BY BINARY s.SCHEMA_NAME, s.DEFAULT_COLLATION_NAME ORDER BY BINARY `SCHEMA_NAME` ASC) a",
1604 'BIN_NAME' => 'pma_test',
1605 'DEFAULT_COLLATION_NAME' => 'utf8mb4_general_ci',
1606 'SCHEMA_NAME' => 'pma_test',
1611 'query' => "SELECT *, CAST(BIN_NAME AS CHAR CHARACTER SET utf8) AS SCHEMA_NAME FROM (SELECT BINARY s.SCHEMA_NAME AS BIN_NAME, s.DEFAULT_COLLATION_NAME FROM `information_schema`.SCHEMATA s GROUP BY BINARY s.SCHEMA_NAME, s.DEFAULT_COLLATION_NAME ORDER BY BINARY `SCHEMA_NAME` ASC) a",
1614 'DEFAULT_COLLATION_NAME',
1625 'latin1_swedish_ci',
1632 'query' => "SELECT *, CAST(BIN_NAME AS CHAR CHARACTER SET utf8) AS SCHEMA_NAME FROM (SELECT BINARY s.SCHEMA_NAME AS BIN_NAME, s.DEFAULT_COLLATION_NAME, COUNT(t.TABLE_SCHEMA) AS SCHEMA_TABLES, SUM(t.TABLE_ROWS) AS SCHEMA_TABLE_ROWS, SUM(t.DATA_LENGTH) AS SCHEMA_DATA_LENGTH, SUM(t.MAX_DATA_LENGTH) AS SCHEMA_MAX_DATA_LENGTH, SUM(t.INDEX_LENGTH) AS SCHEMA_INDEX_LENGTH, SUM(t.DATA_LENGTH + t.INDEX_LENGTH) AS SCHEMA_LENGTH, SUM(IF(t.ENGINE <> 'InnoDB', t.DATA_FREE, 0)) AS SCHEMA_DATA_FREE FROM `information_schema`.SCHEMATA s LEFT JOIN `information_schema`.TABLES t ON BINARY t.TABLE_SCHEMA = BINARY s.SCHEMA_NAME GROUP BY BINARY s.SCHEMA_NAME, s.DEFAULT_COLLATION_NAME ORDER BY `SCHEMA_TABLES` DESC) a",
1635 'DEFAULT_COLLATION_NAME',
1637 'SCHEMA_TABLE_ROWS',
1638 'SCHEMA_DATA_LENGTH',
1639 'SCHEMA_INDEX_LENGTH',
1658 'latin1_swedish_ci',
1670 'query' => "SELECT @@have_partitioning;",
1674 'query' => "SELECT @@lower_case_table_names",
1678 'query' => "SELECT `PLUGIN_NAME`, `PLUGIN_DESCRIPTION` "
1679 . "FROM `information_schema`.`PLUGINS` "
1680 . "WHERE `PLUGIN_TYPE` = 'AUTHENTICATION';",
1684 'query' => "SHOW TABLES FROM `db`;",
1688 'query' => "SELECT `PRIVILEGE_TYPE` FROM "
1689 . "`INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES` "
1690 . "WHERE GRANTEE='''pma_test''@''localhost''' "
1691 . "AND PRIVILEGE_TYPE='EVENT' AND 'db' LIKE `TABLE_SCHEMA`",
1695 'query' => "SELECT `PRIVILEGE_TYPE` FROM "
1696 . "`INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES` "
1697 . "WHERE GRANTEE='''pma_test''@''localhost''' "
1698 . "AND PRIVILEGE_TYPE='TRIGGER' AND 'db' LIKE `TABLE_SCHEMA`",
1702 'query' => "SELECT (COUNT(DB_first_level) DIV 100) * 100 from "
1703 . "( SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) "
1704 . "DB_first_level FROM INFORMATION_SCHEMA.SCHEMATA "
1705 . "WHERE `SCHEMA_NAME` < 'db' ) t",
1709 'query' => "SELECT (COUNT(DB_first_level) DIV 100) * 100 from "
1710 . "( SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) "
1711 . "DB_first_level FROM INFORMATION_SCHEMA.SCHEMATA "
1712 . "WHERE `SCHEMA_NAME` < 'pma_test' ) t",
1716 'query' => "SELECT `SCHEMA_NAME` FROM "
1717 . "`INFORMATION_SCHEMA`.`SCHEMATA`, "
1718 . "(SELECT DB_first_level FROM ( SELECT DISTINCT "
1719 . "SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) DB_first_level FROM "
1720 . "INFORMATION_SCHEMA.SCHEMATA WHERE TRUE ) t "
1721 . "ORDER BY DB_first_level ASC LIMIT , 100) t2 WHERE TRUE AND "
1722 . "1 = LOCATE(CONCAT(DB_first_level, '_'), "
1723 . "CONCAT(SCHEMA_NAME, '_')) ORDER BY SCHEMA_NAME ASC",
1727 'query' => 'SELECT @@ndb_version_string',
1728 'result' => [['ndb-7.4.10']],
1731 'query' => "SELECT *, `COLUMN_NAME` AS `Field`, `COLUMN_TYPE` AS `Type`, `COLLATION_NAME` AS `Collation`, `IS_NULLABLE` AS `Null`, `COLUMN_KEY` AS `Key`, `COLUMN_DEFAULT` AS `Default`, `EXTRA` AS `Extra`, `PRIVILEGES` AS `Privileges`, `COLUMN_COMMENT` AS `Comment` FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` = 'information_schema' AND `TABLE_NAME` = 'PMA'",
1735 'query' => "SELECT TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM information_schema.key_column_usage WHERE referenced_table_name IS NOT NULL AND TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('table1','table2') AND REFERENCED_TABLE_NAME IN ('table1','table2');",
1738 'TABLE_NAME' => 'table2',
1739 'COLUMN_NAME' => 'idtable2',
1740 'REFERENCED_TABLE_NAME' => 'table1',
1741 'REFERENCED_COLUMN_NAME' => 'idtable1',
1746 'query' => "SELECT `item_name`, `item_type` FROM `pmadb`.`navigationhiding` WHERE `username`='user' AND `db_name`='db' AND `table_name`=''",
1749 'item_name' => 'tableName',
1750 'item_type' => 'table',
1753 'item_name' => 'viewName',
1754 'item_type' => 'view',
1763 $GLOBALS['dummy_db'] = '';
1765 /* Some basic setup for dummy driver */
1766 $GLOBALS['cfg']['DBG']['sql'] = false;