DBIDummy.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Fake database driver for testing purposes
  5. *
  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.
  9. *
  10. * @package PhpMyAdmin-DBI
  11. * @subpackage Dummy
  12. */
  13. if (! defined('PHPMYADMIN')) {
  14. exit;
  15. }
  16. require_once './libraries/dbi/DBIExtension.int.php';
  17. /**
  18. * Array of queries this "driver" supports
  19. */
  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')),
  25. ),
  26. array(
  27. 'query' => 'SELECT COUNT(*) FROM mysql.user',
  28. 'result' => false,
  29. ),
  30. array(
  31. 'query' => 'SHOW MASTER LOGS',
  32. 'result' => false,
  33. ),
  34. array(
  35. 'query' => 'SHOW STORAGE ENGINES',
  36. 'result' => array(
  37. array(
  38. 'Engine' => 'dummy',
  39. 'Support' => 'YES',
  40. 'Comment' => 'dummy comment'
  41. ),
  42. array(
  43. 'Engine' => 'dummy2',
  44. 'Support' => 'NO',
  45. 'Comment' => 'dummy2 comment'
  46. ),
  47. array(
  48. 'Engine' => 'FEDERATED',
  49. 'Support' => 'NO',
  50. 'Comment' => 'Federated MySQL storage engine'
  51. ),
  52. )
  53. ),
  54. array(
  55. 'query' => 'SHOW STATUS WHERE Variable_name'
  56. . ' LIKE \'Innodb\\_buffer\\_pool\\_%\''
  57. . ' OR Variable_name = \'Innodb_page_size\';',
  58. 'result' => array(
  59. array('Innodb_buffer_pool_pages_data', 0),
  60. array('Innodb_buffer_pool_pages_dirty', 0),
  61. array('Innodb_buffer_pool_pages_flushed', 0),
  62. array('Innodb_buffer_pool_pages_free', 0),
  63. array('Innodb_buffer_pool_pages_misc', 0),
  64. array('Innodb_buffer_pool_pages_total', 4096),
  65. array('Innodb_buffer_pool_read_ahead_rnd', 0),
  66. array('Innodb_buffer_pool_read_ahead', 0),
  67. array('Innodb_buffer_pool_read_ahead_evicted', 0),
  68. array('Innodb_buffer_pool_read_requests', 64),
  69. array('Innodb_buffer_pool_reads', 32),
  70. array('Innodb_buffer_pool_wait_free', 0),
  71. array('Innodb_buffer_pool_write_requests', 64),
  72. array('Innodb_page_size', 16384),
  73. )
  74. ),
  75. array(
  76. 'query' => 'SHOW INNODB STATUS;',
  77. 'result' => false,
  78. ),
  79. array(
  80. 'query' => 'SELECT @@innodb_version;',
  81. 'result' => array(
  82. array('1.1.8'),
  83. )
  84. ),
  85. array(
  86. 'query' => 'SHOW GLOBAL VARIABLES LIKE \'innodb_file_per_table\';',
  87. 'result' => array(
  88. array('innodb_file_per_table', 'OFF'),
  89. )
  90. ),
  91. array(
  92. 'query' => 'SHOW GLOBAL VARIABLES LIKE \'innodb_file_format\';',
  93. 'result' => array(
  94. array('innodb_file_format', 'Antelope'),
  95. )
  96. ),
  97. array(
  98. 'query' => 'SHOW VARIABLES LIKE \'collation_server\'',
  99. 'result' => array(
  100. array('collation_server', 'utf8_general_ci'),
  101. )
  102. ),
  103. array(
  104. 'query' => 'SHOW VARIABLES LIKE \'language\';',
  105. 'result' => array(),
  106. ),
  107. array(
  108. 'query' => 'SHOW TABLES FROM `pma_test`;',
  109. 'result' => array(
  110. array('table1'),
  111. array('table2'),
  112. )
  113. ),
  114. array(
  115. 'query' => 'SHOW TABLES FROM `pmadb`',
  116. 'result' => array(
  117. array('column_info'),
  118. )
  119. ),
  120. array(
  121. 'query' => 'SHOW COLUMNS FROM `pma_test`.`table1`',
  122. 'columns' => array(
  123. 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra'
  124. ),
  125. 'result' => array(
  126. array('i', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment'),
  127. array('o', 'int(11)', 'NO', 'MUL', 'NULL', ''),
  128. )
  129. ),
  130. array(
  131. 'query' => 'SHOW INDEXES FROM `pma_test`.`table1` WHERE (Non_unique = 0)',
  132. 'result' => array(),
  133. ),
  134. array(
  135. 'query' => 'SHOW COLUMNS FROM `pma_test`.`table2`',
  136. 'columns' => array(
  137. 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra'
  138. ),
  139. 'result' => array(
  140. array('i', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment'),
  141. array('o', 'int(11)', 'NO', 'MUL', 'NULL', ''),
  142. )
  143. ),
  144. array(
  145. 'query' => 'SHOW INDEXES FROM `pma_test`.`table1`',
  146. 'result' => array(),
  147. ),
  148. array(
  149. 'query' => 'SHOW INDEXES FROM `pma_test`.`table2`',
  150. 'result' => array(),
  151. ),
  152. array(
  153. 'query' => 'SHOW COLUMNS FROM `pma`.`table1`',
  154. 'columns' => array(
  155. 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra',
  156. 'Privileges', 'Comment'
  157. ),
  158. 'result' => array(
  159. array(
  160. 'i', 'int(11)', 'NO', 'PRI', 'NULL', 'auto_increment',
  161. 'select,insert,update,references', ''
  162. ),
  163. array(
  164. 'o', 'varchar(100)', 'NO', 'MUL', 'NULL', '',
  165. 'select,insert,update,references', ''
  166. ),
  167. )
  168. ),
  169. array(
  170. 'query' => 'SELECT * FROM information_schema.CHARACTER_SETS',
  171. 'columns' => array(
  172. 'CHARACTER_SET_NAME', 'DEFAULT_COLLATE_NAME', 'DESCRIPTION', 'MAXLEN'
  173. ),
  174. 'result' => array(
  175. array('utf8', 'utf8_general_ci', 'UTF-8 Unicode', 3),
  176. )
  177. ),
  178. array(
  179. 'query' => 'SELECT * FROM information_schema.COLLATIONS',
  180. 'columns' => array(
  181. 'COLLATION_NAME', 'CHARACTER_SET_NAME', 'ID', 'IS_DEFAULT',
  182. 'IS_COMPILED', 'SORTLEN'
  183. ),
  184. 'result' => array(
  185. array('utf8_general_ci', 'utf8', 33, 'Yes', 'Yes', 1),
  186. array('utf8_bin', 'utf8', 83, '', 'Yes', 1),
  187. )
  188. ),
  189. array(
  190. 'query' => 'SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES`'
  191. . ' WHERE `TABLE_SCHEMA`=\'pma_test\' AND `TABLE_TYPE`=\'BASE TABLE\'',
  192. 'result' => array(),
  193. ),
  194. array(
  195. 'query' => 'SELECT upper(plugin_name) f FROM data_dictionary.plugins'
  196. . ' WHERE plugin_name IN (\'MYSQL_PASSWORD\',\'ROT13\')'
  197. . ' AND plugin_type = \'Function\' AND is_active',
  198. 'columns' => array('f'),
  199. 'result' => array(array('ROT13')),
  200. ),
  201. array(
  202. 'query' => 'SELECT `column_name`, `mimetype`, `transformation`,'
  203. . ' `transformation_options` FROM `pmadb`.`column_info`'
  204. . ' WHERE `db_name` = \'pma_test\' AND `table_name` = \'table1\''
  205. . ' AND ( `mimetype` != \'\' OR `transformation` != \'\''
  206. . ' OR `transformation_options` != \'\')',
  207. 'columns' => array(
  208. 'column_name', 'mimetype', 'transformation', 'transformation_options'
  209. ),
  210. 'result' => array(
  211. array('o', 'text/plain', 'sql'),
  212. )
  213. ),
  214. array(
  215. 'query' => 'SELECT TABLE_NAME FROM information_schema.VIEWS'
  216. . ' WHERE TABLE_SCHEMA = \'pma_test\' AND TABLE_NAME = \'table1\'',
  217. 'result' => array(),
  218. ),
  219. array(
  220. 'query' => 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`,'
  221. . ' `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`,'
  222. . ' `ENGINE` AS `Type`, `VERSION` AS `Version`,'
  223. . ' `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`,'
  224. . ' `AVG_ROW_LENGTH` AS `Avg_row_length`,'
  225. . ' `DATA_LENGTH` AS `Data_length`,'
  226. . ' `MAX_DATA_LENGTH` AS `Max_data_length`,'
  227. . ' `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`,'
  228. . ' `AUTO_INCREMENT` AS `Auto_increment`,'
  229. . ' `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`,'
  230. . ' `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`,'
  231. . ' `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`,'
  232. . ' `TABLE_COMMENT` AS `Comment`'
  233. . ' FROM `information_schema`.`TABLES` t'
  234. . ' WHERE BINARY `TABLE_SCHEMA` IN (\'pma_test\')'
  235. . ' AND t.`TABLE_NAME` = \'table1\' ORDER BY Name ASC',
  236. 'columns' => array(
  237. 'TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'TABLE_TYPE', 'ENGINE',
  238. 'VERSION', 'ROW_FORMAT', 'TABLE_ROWS', 'AVG_ROW_LENGTH', 'DATA_LENGTH',
  239. 'MAX_DATA_LENGTH', 'INDEX_LENGTH', 'DATA_FREE', 'AUTO_INCREMENT',
  240. 'CREATE_TIME', 'UPDATE_TIME', 'CHECK_TIME', 'TABLE_COLLATION',
  241. 'CHECKSUM', 'CREATE_OPTIONS', 'TABLE_COMMENT', 'Db', 'Name',
  242. 'TABLE_TYPE', 'Engine', 'Type', 'Version', 'Row_format', 'Rows',
  243. 'Avg_row_length', 'Data_length', 'Max_data_length', 'Index_length',
  244. 'Data_free', 'Auto_increment', 'Create_time', 'Update_time',
  245. 'Check_time', 'Collation', 'Checksum', 'Create_options', 'Comment'
  246. ),
  247. 'result' => array(
  248. array(
  249. 'def', 'smash', 'issues_issue', 'BASE TABLE', 'InnoDB', '10',
  250. 'Compact', '9136', '862', '7880704', '0', '1032192', '420478976',
  251. '155862', '2012-08-29 13:28:28', 'NULL', 'NULL', 'utf8_general_ci',
  252. 'NULL', '', '', 'smash', 'issues_issue', 'BASE TABLE', 'InnoDB',
  253. 'InnoDB', '10', 'Compact', '9136', '862', '7880704', '0', '1032192',
  254. '420478976', '155862', '2012-08-29 13:28:28', 'NULL', 'NULL',
  255. 'utf8_general_ci', 'NULL'
  256. ),
  257. ),
  258. ),
  259. array(
  260. 'query' => 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`,'
  261. . ' `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`,'
  262. . ' `ENGINE` AS `Type`, `VERSION` AS `Version`,'
  263. . ' `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`,'
  264. . ' `AVG_ROW_LENGTH` AS `Avg_row_length`,'
  265. . ' `DATA_LENGTH` AS `Data_length`,'
  266. . ' `MAX_DATA_LENGTH` AS `Max_data_length`,'
  267. . ' `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`,'
  268. . ' `AUTO_INCREMENT` AS `Auto_increment`,'
  269. . ' `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`,'
  270. . ' `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`,'
  271. . ' `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`,'
  272. . ' `TABLE_COMMENT` AS `Comment`'
  273. . ' FROM `information_schema`.`TABLES` t'
  274. . ' WHERE `TABLE_SCHEMA` IN (\'pma_test\')'
  275. . ' AND t.`TABLE_NAME` = \'table1\' ORDER BY Name ASC',
  276. 'columns' => array('TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME',
  277. 'TABLE_TYPE', 'ENGINE', 'VERSION', 'ROW_FORMAT', 'TABLE_ROWS',
  278. 'AVG_ROW_LENGTH', 'DATA_LENGTH', 'MAX_DATA_LENGTH',
  279. 'INDEX_LENGTH', 'DATA_FREE', 'AUTO_INCREMENT', 'CREATE_TIME',
  280. 'UPDATE_TIME', 'CHECK_TIME', 'TABLE_COLLATION', 'CHECKSUM',
  281. 'CREATE_OPTIONS', 'TABLE_COMMENT', 'Db', 'Name', 'TABLE_TYPE',
  282. 'Engine', 'Type', 'Version', 'Row_format', 'Rows',
  283. 'Avg_row_length', 'Data_length', 'Max_data_length',
  284. 'Index_length', 'Data_free', 'Auto_increment', 'Create_time',
  285. 'Update_time', 'Check_time', 'Collation', 'Checksum',
  286. 'Create_options', 'Comment'),
  287. 'result' => array(
  288. array('def', 'smash', 'issues_issue', 'BASE TABLE', 'InnoDB', '10',
  289. 'Compact', '9136', '862', '7880704', '0', '1032192',
  290. '420478976', '155862', '2012-08-29 13:28:28', 'NULL', 'NULL',
  291. 'utf8_general_ci', 'NULL', '', '', 'smash', 'issues_issue',
  292. 'BASE TABLE', 'InnoDB', 'InnoDB', '10', 'Compact', '9136',
  293. '862', '7880704', '0', '1032192', '420478976', '155862',
  294. '2012-08-29 13:28:28', 'NULL', 'NULL', 'utf8_general_ci',
  295. 'NULL'),
  296. ),
  297. ),
  298. array(
  299. 'query' => 'SELECT COUNT(*) FROM `pma_test`.`table1`',
  300. 'result' => array(array(0)),
  301. ),
  302. array(
  303. 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
  304. . '`USER_PRIVILEGES`'
  305. . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
  306. . ' AND PRIVILEGE_TYPE=\'TRIGGER\'',
  307. 'result' => array(),
  308. ),
  309. array(
  310. 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
  311. . '`SCHEMA_PRIVILEGES`'
  312. . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
  313. . ' AND PRIVILEGE_TYPE=\'TRIGGER\' AND \'pma\\\\_test\''
  314. . ' REGEXP REPLACE(REPLACE(TABLE_SCHEMA, \'_\', \'.\'), \'%\', \'.*\')',
  315. 'result' => array(),
  316. ),
  317. array(
  318. 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
  319. . '`TABLE_PRIVILEGES`'
  320. . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
  321. . ' AND PRIVILEGE_TYPE=\'TRIGGER\' AND \'pma\\\\_test\''
  322. . ' REGEXP REPLACE(REPLACE(TABLE_SCHEMA, \'_\', \'.\'), \'%\', \'.*\')'
  323. . ' AND TABLE_NAME=\'table1\'',
  324. 'result' => array(),
  325. ),
  326. array(
  327. 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
  328. . '`USER_PRIVILEGES`'
  329. . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
  330. . ' AND PRIVILEGE_TYPE=\'EVENT\'',
  331. 'result' => array(),
  332. ),
  333. array(
  334. 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
  335. . '`SCHEMA_PRIVILEGES`'
  336. . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
  337. . ' AND PRIVILEGE_TYPE=\'EVENT\' AND \'pma\\\\_test\''
  338. . ' REGEXP REPLACE(REPLACE(TABLE_SCHEMA, \'_\', \'.\'), \'%\', \'.*\')',
  339. 'result' => array(),
  340. ),
  341. array(
  342. 'query' => 'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.'
  343. . '`TABLE_PRIVILEGES`'
  344. . ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\''
  345. . ' AND PRIVILEGE_TYPE=\'EVENT\''
  346. . ' AND TABLE_SCHEMA=\'pma\\\\_test\' AND TABLE_NAME=\'table1\'',
  347. 'result' => array(),
  348. ),
  349. array(
  350. 'query' => 'RENAME TABLE `pma_test`.`table1` TO `pma_test`.`table3`;',
  351. 'result' => array(),
  352. ),
  353. array(
  354. 'query' => 'SELECT TRIGGER_SCHEMA, TRIGGER_NAME, EVENT_MANIPULATION,'
  355. . ' EVENT_OBJECT_TABLE, ACTION_TIMING, ACTION_STATEMENT, '
  356. . 'EVENT_OBJECT_SCHEMA, EVENT_OBJECT_TABLE, DEFINER'
  357. . ' FROM information_schema.TRIGGERS'
  358. . ' WHERE TRIGGER_SCHEMA= \'pma_test\''
  359. . ' AND EVENT_OBJECT_TABLE = \'table1\';',
  360. 'result' => array(),
  361. ),
  362. array(
  363. 'query' => 'SHOW TABLES FROM `pma`;',
  364. 'result' => array(),
  365. ),
  366. array(
  367. 'query' => "SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`."
  368. . "`SCHEMA_PRIVILEGES` WHERE GRANTEE='''pma_test''@''localhost'''"
  369. . " AND PRIVILEGE_TYPE='EVENT' AND TABLE_SCHEMA='pma'",
  370. 'result' => array(),
  371. ),
  372. array(
  373. 'query' => "SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`."
  374. . "`SCHEMA_PRIVILEGES` WHERE GRANTEE='''pma_test''@''localhost'''"
  375. . " AND PRIVILEGE_TYPE='TRIGGER' AND TABLE_SCHEMA='pma'",
  376. 'result' => array(),
  377. ),
  378. array(
  379. 'query' => 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA'
  380. . ' WHERE SCHEMA_NAME = \'pma_test\' LIMIT 1',
  381. 'columns' => array('DEFAULT_COLLATION_NAME'),
  382. 'result' => array(
  383. array('utf8_general_ci')
  384. )
  385. ),
  386. array(
  387. 'query' => 'SELECT DEFAULT_COLLATION_NAME FROM data_dictionary.SCHEMAS'
  388. . ' WHERE SCHEMA_NAME = \'pma_test\' LIMIT 1',
  389. 'columns' => array('DEFAULT_COLLATION_NAME'),
  390. 'result' => array(
  391. array('utf8_general_ci_pma_drizzle')
  392. )
  393. ),
  394. array(
  395. 'query' => 'SHOW VARIABLES LIKE \'collation_database\'',
  396. 'columns' => array('variable_name', 'variable_value'),
  397. 'result' => array(
  398. array('foo', 'bar'),
  399. )
  400. ),
  401. array(
  402. 'query' => "SHOW TABLES FROM `phpmyadmin`",
  403. 'result' => array(),
  404. ),
  405. array(
  406. 'query' => "SELECT tracking_active FROM pma_table_tracking" .
  407. " WHERE db_name = 'pma_test_db'" .
  408. " AND table_name = 'pma_test_table'" .
  409. " ORDER BY version DESC",
  410. 'columns' => array('tracking_active'),
  411. 'result' => array(
  412. array(1)
  413. )
  414. ),
  415. array(
  416. 'query' => "SELECT tracking_active FROM pma_table_tracking" .
  417. " WHERE db_name = 'pma_test_db'" .
  418. " AND table_name = 'pma_test_table2'" .
  419. " ORDER BY version DESC",
  420. 'result' => array()
  421. ),
  422. array(
  423. 'query' => "SHOW SLAVE STATUS",
  424. 'result' => array(
  425. array(
  426. 'Slave_IO_State' => 'running',
  427. 'Master_Host' => 'locahost',
  428. 'Master_User' => 'Master_User',
  429. 'Master_Port' => '1002',
  430. 'Connect_Retry' => 'Connect_Retry',
  431. 'Master_Log_File' => 'Master_Log_File',
  432. 'Read_Master_Log_Pos' => 'Read_Master_Log_Pos',
  433. 'Relay_Log_File' => 'Relay_Log_File',
  434. 'Relay_Log_Pos' => 'Relay_Log_Pos',
  435. 'Relay_Master_Log_File' => 'Relay_Master_Log_File',
  436. 'Slave_IO_Running' => 'NO',
  437. 'Slave_SQL_Running' => 'NO',
  438. 'Replicate_Do_DB' => 'Replicate_Do_DB',
  439. 'Replicate_Ignore_DB' => 'Replicate_Ignore_DB',
  440. 'Replicate_Do_Table' => 'Replicate_Do_Table',
  441. 'Replicate_Ignore_Table' => 'Replicate_Ignore_Table',
  442. 'Replicate_Wild_Do_Table' => 'Replicate_Wild_Do_Table',
  443. 'Replicate_Wild_Ignore_Table' => 'Replicate_Wild_Ignore_Table',
  444. 'Last_Errno' => 'Last_Errno',
  445. 'Last_Error' => 'Last_Error',
  446. 'Skip_Counter' => 'Skip_Counter',
  447. 'Exec_Master_Log_Pos' => 'Exec_Master_Log_Pos',
  448. 'Relay_Log_Space' => 'Relay_Log_Space',
  449. 'Until_Condition' => 'Until_Condition',
  450. 'Until_Log_File' => 'Until_Log_File',
  451. 'Until_Log_Pos' => 'Until_Log_Pos',
  452. 'Master_SSL_Allowed' => 'Master_SSL_Allowed',
  453. 'Master_SSL_CA_File' => 'Master_SSL_CA_File',
  454. 'Master_SSL_CA_Path' => 'Master_SSL_CA_Path',
  455. 'Master_SSL_Cert' => 'Master_SSL_Cert',
  456. 'Master_SSL_Cipher' => 'Master_SSL_Cipher',
  457. 'Master_SSL_Key' => 'Master_SSL_Key',
  458. 'Seconds_Behind_Master' => 'Seconds_Behind_Master',
  459. )
  460. )
  461. ),
  462. array(
  463. 'query' => "SHOW MASTER STATUS",
  464. 'result' => array(
  465. array(
  466. "File" => "master-bin.000030",
  467. "Position" => "107",
  468. "Binlog_Do_DB" => "Binlog_Do_DB",
  469. "Binlog_Ignore_DB" => "Binlog_Ignore_DB",
  470. )
  471. )
  472. ),
  473. array(
  474. 'query' => "SHOW GRANTS",
  475. 'result' => array()
  476. )
  477. );
  478. /**
  479. * Current database.
  480. */
  481. $GLOBALS['dummy_db'] = '';
  482. /* Some basic setup for dummy driver */
  483. $GLOBALS['userlink'] = 1;
  484. $GLOBALS['controllink'] = 2;
  485. $GLOBALS['cfg']['DBG']['sql'] = false;
  486. if (! defined('PMA_DRIZZLE')) {
  487. define('PMA_DRIZZLE', 0);
  488. }
  489. /**
  490. * Fake database driver for testing purposes
  491. *
  492. * It has hardcoded results for given queries what makes easy to use it
  493. * in testsuite. Feel free to include other queries which your test will
  494. * need.
  495. *
  496. * @package PhpMyAdmin-DBI
  497. * @subpackage Dummy
  498. */
  499. class PMA_DBI_Dummy implements PMA_DBI_Extension
  500. {
  501. /**
  502. * connects to the database server
  503. *
  504. * @param string $user mysql user name
  505. * @param string $password mysql user password
  506. * @param bool $is_controluser whether this is a control user connection
  507. * @param array $server host/port/socket/persistent
  508. * @param bool $auxiliary_connection (when true, don't go back to login if
  509. * connection fails)
  510. *
  511. * @return mixed false on error or a mysqli object on success
  512. */
  513. public function connect(
  514. $user, $password, $is_controluser = false, $server = null,
  515. $auxiliary_connection = false
  516. ) {
  517. return true;
  518. }
  519. /**
  520. * selects given database
  521. *
  522. * @param string $dbname name of db to select
  523. * @param resource $link mysql link resource
  524. *
  525. * @return bool
  526. */
  527. public function selectDb($dbname, $link = null)
  528. {
  529. $GLOBALS['dummy_db'] = $dbname;
  530. return true;
  531. }
  532. /**
  533. * runs a query and returns the result
  534. *
  535. * @param string $query query to run
  536. * @param resource $link mysql link resource
  537. * @param int $options query options
  538. *
  539. * @return mixed
  540. */
  541. public function realQuery($query, $link = null, $options = 0)
  542. {
  543. $query = trim(preg_replace('/ */', ' ', str_replace("\n", ' ', $query)));
  544. for ($i = 0, $nb = count($GLOBALS['dummy_queries']); $i < $nb; $i++) {
  545. if ($GLOBALS['dummy_queries'][$i]['query'] != $query) {
  546. continue;
  547. }
  548. $GLOBALS['dummy_queries'][$i]['pos'] = 0;
  549. if (!is_array($GLOBALS['dummy_queries'][$i]['result'])) {
  550. return false;
  551. }
  552. return $i;
  553. }
  554. echo "Not supported query: $query\n";
  555. return false;
  556. }
  557. /**
  558. * Run the multi query and output the results
  559. *
  560. * @param object $link connection object
  561. * @param string $query multi query statement to execute
  562. *
  563. * @return result collection | boolean(false)
  564. */
  565. public function realMultiQuery($link, $query)
  566. {
  567. return false;
  568. }
  569. /**
  570. * returns result data from $result
  571. *
  572. * @param resource $result result MySQL result
  573. *
  574. * @return array
  575. */
  576. public function fetchAny($result)
  577. {
  578. $query_data = $GLOBALS['dummy_queries'][$result];
  579. if ($query_data['pos'] >= count($query_data['result'])) {
  580. return false;
  581. }
  582. $ret = $query_data['result'][$query_data['pos']];
  583. $GLOBALS['dummy_queries'][$result]['pos'] += 1;
  584. return $ret;
  585. }
  586. /**
  587. * returns array of rows with associative and numeric keys from $result
  588. *
  589. * @param resource $result result MySQL result
  590. *
  591. * @return array
  592. */
  593. public function fetchArray($result)
  594. {
  595. $data = $this->fetchAny($result);
  596. if (!is_array($data)
  597. || !isset($GLOBALS['dummy_queries'][$result]['columns'])
  598. ) {
  599. return $data;
  600. }
  601. foreach ($data as $key => $val) {
  602. $data[$GLOBALS['dummy_queries'][$result]['columns'][$key]] = $val;
  603. }
  604. return $data;
  605. }
  606. /**
  607. * returns array of rows with associative keys from $result
  608. *
  609. * @param resource $result MySQL result
  610. *
  611. * @return array
  612. */
  613. public function fetchAssoc($result)
  614. {
  615. $data = $this->fetchAny($result);
  616. if (!is_array($data)
  617. || !isset($GLOBALS['dummy_queries'][$result]['columns'])
  618. ) {
  619. return $data;
  620. }
  621. $ret = array();
  622. foreach ($data as $key => $val) {
  623. $ret[$GLOBALS['dummy_queries'][$result]['columns'][$key]] = $val;
  624. }
  625. return $ret;
  626. }
  627. /**
  628. * returns array of rows with numeric keys from $result
  629. *
  630. * @param resource $result MySQL result
  631. *
  632. * @return array
  633. */
  634. public function fetchRow($result)
  635. {
  636. $data = $this->fetchAny($result);
  637. return $data;
  638. }
  639. /**
  640. * Adjusts the result pointer to an arbitrary row in the result
  641. *
  642. * @param resource $result database result
  643. * @param integer $offset offset to seek
  644. *
  645. * @return bool true on success, false on failure
  646. */
  647. public function dataSeek($result, $offset)
  648. {
  649. if ($offset > count($GLOBALS['dummy_queries'][$result]['result'])) {
  650. return false;
  651. }
  652. $GLOBALS['dummy_queries'][$result]['pos'] = $offset;
  653. return true;
  654. }
  655. /**
  656. * Frees memory associated with the result
  657. *
  658. * @param resource $result database result
  659. *
  660. * @return void
  661. */
  662. public function freeResult($result)
  663. {
  664. return;
  665. }
  666. /**
  667. * Check if there are any more query results from a multi query
  668. *
  669. * @param object $link the connection object
  670. *
  671. * @return bool false
  672. */
  673. public function moreResults($link = null)
  674. {
  675. return false;
  676. }
  677. /**
  678. * Prepare next result from multi_query
  679. *
  680. * @param object $link the connection object
  681. *
  682. * @return boolean false
  683. */
  684. public function nextResult($link = null)
  685. {
  686. return false;
  687. }
  688. /**
  689. * Store the result returned from multi query
  690. *
  691. * @return mixed false when empty results / result set when not empty
  692. */
  693. public function storeResult()
  694. {
  695. return false;
  696. }
  697. /**
  698. * Returns a string representing the type of connection used
  699. *
  700. * @param object $link mysql link
  701. *
  702. * @return string type of connection used
  703. */
  704. public function getHostInfo($link = null)
  705. {
  706. return '';
  707. }
  708. /**
  709. * Returns the version of the MySQL protocol used
  710. *
  711. * @param object $link mysql link
  712. *
  713. * @return integer version of the MySQL protocol used
  714. */
  715. public function getProtoInfo($link = null)
  716. {
  717. return -1;
  718. }
  719. /**
  720. * returns a string that represents the client library version
  721. *
  722. * @return string MySQL client library version
  723. */
  724. public function getClientInfo()
  725. {
  726. return '';
  727. }
  728. /**
  729. * returns last error message or false if no errors occurred
  730. *
  731. * @param object $link connection link
  732. *
  733. * @return string|bool $error or false
  734. */
  735. public function getError($link = null)
  736. {
  737. return false;
  738. }
  739. /**
  740. * returns the number of rows returned by last query
  741. *
  742. * @param resource $result MySQL result
  743. *
  744. * @return string|int
  745. */
  746. public function numRows($result)
  747. {
  748. if (is_bool($result)) {
  749. return 0;
  750. }
  751. return count($GLOBALS['dummy_queries'][$result]['result']);
  752. }
  753. /**
  754. * returns last inserted auto_increment id for given $link
  755. * or $GLOBALS['userlink']
  756. *
  757. * @param object $link the connection object
  758. *
  759. * @return string|int
  760. */
  761. public function insertId($link = null)
  762. {
  763. return -1;
  764. }
  765. /**
  766. * returns the number of rows affected by last query
  767. *
  768. * @param resource $link the mysql object
  769. * @param bool $get_from_cache whether to retrieve from cache
  770. *
  771. * @return string|int
  772. */
  773. public function affectedRows($link = null, $get_from_cache = true)
  774. {
  775. return 0;
  776. }
  777. /**
  778. * returns metainfo for fields in $result
  779. *
  780. * @param object $result result set identifier
  781. *
  782. * @return array meta info for fields in $result
  783. */
  784. public function getFieldsMeta($result)
  785. {
  786. return array();
  787. }
  788. /**
  789. * return number of fields in given $result
  790. *
  791. * @param resource $result MySQL result
  792. *
  793. * @return int field count
  794. */
  795. public function numFields($result)
  796. {
  797. if (!isset($GLOBALS['dummy_queries'][$result]['columns'])) {
  798. return 0;
  799. }
  800. return count($GLOBALS['dummy_queries'][$result]['columns']);
  801. }
  802. /**
  803. * returns the length of the given field $i in $result
  804. *
  805. * @param object $result result set identifier
  806. * @param int $i field
  807. *
  808. * @return int length of field
  809. */
  810. public function fieldLen($result, $i)
  811. {
  812. return -1;
  813. }
  814. /**
  815. * returns name of $i. field in $result
  816. *
  817. * @param object $result result set identifier
  818. * @param int $i field
  819. *
  820. * @return string name of $i. field in $result
  821. */
  822. public function fieldName($result, $i)
  823. {
  824. return '';
  825. }
  826. /**
  827. * returns concatenated string of human readable field flags
  828. *
  829. * @param object $result result set identifier
  830. * @param int $i field
  831. *
  832. * @return string field flags
  833. */
  834. public function fieldFlags($result, $i)
  835. {
  836. return '';
  837. }
  838. }
  839. ?>