2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
8 declare(strict_types
=1);
10 use PhpMyAdmin\Database\Qbe
;
11 use PhpMyAdmin\Message
;
12 use PhpMyAdmin\Relation
;
13 use PhpMyAdmin\Response
;
14 use PhpMyAdmin\SavedSearches
;
22 require_once 'libraries/common.inc.php';
24 $response = Response
::getInstance();
26 // Gets the relation settings
27 $relation = new Relation();
28 $cfgRelation = $relation->getRelationsParam();
30 $savedSearchList = array();
32 $currentSearchId = null;
33 if ($cfgRelation['savedsearcheswork']) {
34 $header = $response->getHeader();
35 $scripts = $header->getScripts();
36 $scripts->addFile('db_qbe.js');
38 //Get saved search list.
39 $savedSearch = new SavedSearches($GLOBALS);
40 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
41 ->setDbname($_REQUEST['db']);
43 if (!empty($_REQUEST['searchId'])) {
44 $savedSearch->setId($_REQUEST['searchId']);
47 //Action field is sent.
48 if (isset($_REQUEST['action'])) {
49 $savedSearch->setSearchName($_REQUEST['searchName']);
50 if ('create' === $_REQUEST['action']) {
51 $saveResult = $savedSearch->setId(null)
52 ->setCriterias($_REQUEST)
54 } elseif ('update' === $_REQUEST['action']) {
55 $saveResult = $savedSearch->setCriterias($_REQUEST)
57 } elseif ('delete' === $_REQUEST['action']) {
58 $deleteResult = $savedSearch->delete();
59 //After deletion, reset search.
60 $savedSearch = new SavedSearches($GLOBALS);
61 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
62 ->setDbname($_REQUEST['db']);
64 } elseif ('load' === $_REQUEST['action']) {
65 if (empty($_REQUEST['searchId'])) {
66 //when not loading a search, reset the object.
67 $savedSearch = new SavedSearches($GLOBALS);
68 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
69 ->setDbname($_REQUEST['db']);
72 $loadResult = $savedSearch->load();
75 //Else, it's an "update query"
78 $savedSearchList = $savedSearch->getList();
79 $currentSearchId = $savedSearch->getId();
83 * A query has been submitted -> (maybe) execute it
85 $message_to_display = false;
86 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
87 if (! preg_match('@^SELECT@i', $sql_query)) {
88 $message_to_display = true;
92 $sql->executeQueryAndSendQueryResponse(
93 null, // analyzed_sql_results
95 $_REQUEST['db'], // db
97 false, // find_real_end
98 null, // sql_query_for_bookmark
100 null, // message_to_show
104 $pmaThemeImage, // pmaThemeImage
106 null, // disp_message
108 $sql_query, // sql_query
109 null, // selectedTables
110 null // complete_query
116 require 'libraries/db_common.inc.php';
117 $url_query .= '&goto=db_qbe.php';
118 $url_params['goto'] = 'db_qbe.php';
126 $db_is_system_schema,
130 ) = Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
132 if ($message_to_display) {
134 __('You have to choose at least one column to display!')
138 unset($message_to_display);
140 // create new qbe search instance
141 $db_qbe = new Qbe($GLOBALS['dbi'], $GLOBALS['db'], $savedSearchList, $savedSearch);
143 $url = 'db_designer.php' . Url
::getCommon(
152 __('Switch to %svisual builder%s'),
153 '<a href="' . $url . '">',
160 * Displays the Query by example form
162 $response->addHTML($db_qbe->getSelectionForm());