Improve create-release script to handle QA branches higher than QA_4_8.
[phpmyadmin.git] / db_qbe.php
blob7b02648f8a0738b1fd6ccb7366d792a77d311ed3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * query by example the whole database
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Database\Qbe;
11 use PhpMyAdmin\DatabaseInterface;
12 use PhpMyAdmin\Di\Container;
13 use PhpMyAdmin\Message;
14 use PhpMyAdmin\Relation;
15 use PhpMyAdmin\Response;
16 use PhpMyAdmin\SavedSearches;
17 use PhpMyAdmin\Sql;
18 use PhpMyAdmin\Template;
19 use PhpMyAdmin\Url;
20 use PhpMyAdmin\Util;
22 if (! defined('ROOT_PATH')) {
23 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
26 global $db, $pmaThemeImage, $url_query;
28 require_once ROOT_PATH . 'libraries/common.inc.php';
30 $container = Container::getDefaultContainer();
31 $container->set(Response::class, Response::getInstance());
33 /** @var Response $response */
34 $response = $container->get(Response::class);
36 /** @var DatabaseInterface $dbi */
37 $dbi = $container->get(DatabaseInterface::class);
39 /** @var Relation $relation */
40 $relation = $containerBuilder->get('relation');
41 /** @var Template $template */
42 $template = $containerBuilder->get('template');
44 // Gets the relation settings
45 $cfgRelation = $relation->getRelationsParam();
47 $savedSearchList = [];
48 $savedSearch = null;
49 $currentSearchId = null;
50 if ($cfgRelation['savedsearcheswork']) {
51 $header = $response->getHeader();
52 $scripts = $header->getScripts();
53 $scripts->addFile('db_qbe.js');
55 //Get saved search list.
56 $savedSearch = new SavedSearches($GLOBALS, $relation);
57 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
58 ->setDbname($db);
60 if (! empty($_POST['searchId'])) {
61 $savedSearch->setId($_POST['searchId']);
64 //Action field is sent.
65 if (isset($_POST['action'])) {
66 $savedSearch->setSearchName($_POST['searchName']);
67 if ('create' === $_POST['action']) {
68 $saveResult = $savedSearch->setId(null)
69 ->setCriterias($_POST)
70 ->save();
71 } elseif ('update' === $_POST['action']) {
72 $saveResult = $savedSearch->setCriterias($_POST)
73 ->save();
74 } elseif ('delete' === $_POST['action']) {
75 $deleteResult = $savedSearch->delete();
76 //After deletion, reset search.
77 $savedSearch = new SavedSearches($GLOBALS, $relation);
78 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
79 ->setDbname($db);
80 $_POST = [];
81 } elseif ('load' === $_POST['action']) {
82 if (empty($_POST['searchId'])) {
83 //when not loading a search, reset the object.
84 $savedSearch = new SavedSearches($GLOBALS, $relation);
85 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
86 ->setDbname($db);
87 $_POST = [];
88 } else {
89 $loadResult = $savedSearch->load();
92 //Else, it's an "update query"
95 $savedSearchList = $savedSearch->getList();
96 $currentSearchId = $savedSearch->getId();
99 /**
100 * A query has been submitted -> (maybe) execute it
102 $message_to_display = false;
103 if (isset($_POST['submit_sql']) && ! empty($sql_query)) {
104 if (0 !== stripos($sql_query, "SELECT")) {
105 $message_to_display = true;
106 } else {
107 $goto = 'db_sql.php';
108 $sql = new Sql();
109 $sql->executeQueryAndSendQueryResponse(
110 null, // analyzed_sql_results
111 false, // is_gotofile
112 $_POST['db'], // db
113 null, // table
114 false, // find_real_end
115 null, // sql_query_for_bookmark
116 null, // extra_data
117 null, // message_to_show
118 null, // message
119 null, // sql_data
120 $goto, // goto
121 $pmaThemeImage, // pmaThemeImage
122 null, // disp_query
123 null, // disp_message
124 null, // query_type
125 $sql_query, // sql_query
126 null, // selectedTables
127 null // complete_query
132 $sub_part = '_qbe';
133 require ROOT_PATH . 'libraries/db_common.inc.php';
134 $url_query .= '&amp;goto=db_qbe.php';
135 $url_params['goto'] = 'db_qbe.php';
137 list(
138 $tables,
139 $num_tables,
140 $total_num_tables,
141 $sub_part,
142 $is_show_stats,
143 $db_is_system_schema,
144 $tooltip_truename,
145 $tooltip_aliasname,
146 $pos
147 ) = Util::getDbInfo($db, is_null($sub_part) ? '' : $sub_part);
149 if ($message_to_display) {
150 Message::error(
151 __('You have to choose at least one column to display!')
153 ->display();
155 unset($message_to_display);
157 // create new qbe search instance
158 $db_qbe = new Qbe($relation, $template, $dbi, $db, $savedSearchList, $savedSearch);
160 $secondaryTabs = [
161 'multi' => [
162 'link' => 'db_multi_table_query.php',
163 'text' => __('Multi-table query'),
165 'qbe' => [
166 'link' => 'db_qbe.php',
167 'text' => __('Query by example'),
170 $response->addHTML(
171 $template->render('secondary_tabs', [
172 'url_params' => $url_params,
173 'sub_tabs' => $secondaryTabs,
177 $url = 'db_designer.php' . Url::getCommon(
178 array_merge(
179 $url_params,
180 ['query' => 1]
183 $response->addHTML(
184 Message::notice(
185 sprintf(
186 __('Switch to %svisual builder%s'),
187 '<a href="' . $url . '">',
188 '</a>'
194 * Displays the Query by example form
196 $response->addHTML($db_qbe->getSelectionForm());