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\DatabaseInterface
;
12 use PhpMyAdmin\Message
;
13 use PhpMyAdmin\Relation
;
14 use PhpMyAdmin\Response
;
15 use PhpMyAdmin\SavedSearches
;
17 use PhpMyAdmin\Template
;
21 if (! defined('ROOT_PATH')) {
22 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
25 global $db, $pmaThemeImage, $url_query;
27 require_once ROOT_PATH
. 'libraries/common.inc.php';
29 /** @var Response $response */
30 $response = $containerBuilder->get(Response
::class);
32 /** @var DatabaseInterface $dbi */
33 $dbi = $containerBuilder->get(DatabaseInterface
::class);
35 /** @var Relation $relation */
36 $relation = $containerBuilder->get('relation');
37 /** @var Template $template */
38 $template = $containerBuilder->get('template');
40 // Gets the relation settings
41 $cfgRelation = $relation->getRelationsParam();
43 $savedSearchList = [];
45 $currentSearchId = null;
46 if ($cfgRelation['savedsearcheswork']) {
47 $header = $response->getHeader();
48 $scripts = $header->getScripts();
49 $scripts->addFile('database/qbe.js');
51 //Get saved search list.
52 $savedSearch = new SavedSearches($GLOBALS, $relation);
53 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
56 if (! empty($_POST['searchId'])) {
57 $savedSearch->setId($_POST['searchId']);
60 //Action field is sent.
61 if (isset($_POST['action'])) {
62 $savedSearch->setSearchName($_POST['searchName']);
63 if ('create' === $_POST['action']) {
64 $saveResult = $savedSearch->setId(null)
65 ->setCriterias($_POST)
67 } elseif ('update' === $_POST['action']) {
68 $saveResult = $savedSearch->setCriterias($_POST)
70 } elseif ('delete' === $_POST['action']) {
71 $deleteResult = $savedSearch->delete();
72 //After deletion, reset search.
73 $savedSearch = new SavedSearches($GLOBALS, $relation);
74 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
77 } elseif ('load' === $_POST['action']) {
78 if (empty($_POST['searchId'])) {
79 //when not loading a search, reset the object.
80 $savedSearch = new SavedSearches($GLOBALS, $relation);
81 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
85 $loadResult = $savedSearch->load();
88 //Else, it's an "update query"
91 $savedSearchList = $savedSearch->getList();
92 $currentSearchId = $savedSearch->getId();
96 * A query has been submitted -> (maybe) execute it
98 $message_to_display = false;
99 if (isset($_POST['submit_sql']) && ! empty($sql_query)) {
100 if (0 !== stripos($sql_query, "SELECT")) {
101 $message_to_display = true;
103 $goto = 'db_sql.php';
105 $sql->executeQueryAndSendQueryResponse(
106 null, // analyzed_sql_results
107 false, // is_gotofile
110 false, // find_real_end
111 null, // sql_query_for_bookmark
113 null, // message_to_show
117 $pmaThemeImage, // pmaThemeImage
119 null, // disp_message
121 $sql_query, // sql_query
122 null, // selectedTables
123 null // complete_query
129 require ROOT_PATH
. 'libraries/db_common.inc.php';
130 $url_query .= '&goto=db_qbe.php';
131 $url_params['goto'] = 'db_qbe.php';
139 $db_is_system_schema,
143 ) = Util
::getDbInfo($db, $sub_part === null ?
'' : $sub_part);
145 if ($message_to_display) {
147 __('You have to choose at least one column to display!')
151 unset($message_to_display);
153 // create new qbe search instance
154 $db_qbe = new Qbe($relation, $template, $dbi, $db, $savedSearchList, $savedSearch);
158 'link' => 'db_multi_table_query.php',
159 'text' => __('Multi-table query'),
162 'link' => 'db_qbe.php',
163 'text' => __('Query by example'),
167 $template->render('secondary_tabs', [
168 'url_params' => $url_params,
169 'sub_tabs' => $secondaryTabs,
173 $url = 'db_designer.php' . Url
::getCommon(
182 __('Switch to %svisual builder%s'),
183 '<a href="' . $url . '">',
190 * Displays the Query by example form
192 $response->addHTML($db_qbe->getSelectionForm());