Translated using Weblate (Portuguese)
[phpmyadmin.git] / db_qbe.php
blobe25268766e10508e8fc4e6482fd7a1674ca3f6a1
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 use PhpMyAdmin\Database\Qbe;
9 use PhpMyAdmin\Message;
10 use PhpMyAdmin\Relation;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\SavedSearches;
13 use PhpMyAdmin\Sql;
14 use PhpMyAdmin\Template;
15 use PhpMyAdmin\Url;
16 use PhpMyAdmin\Util;
18 /**
19 * requirements
21 require_once 'libraries/common.inc.php';
23 $response = Response::getInstance();
24 $relation = new Relation();
26 // Gets the relation settings
27 $cfgRelation = $relation->getRelationsParam();
29 $savedSearchList = array();
30 $savedSearch = null;
31 $currentSearchId = null;
32 if ($cfgRelation['savedsearcheswork']) {
33 $header = $response->getHeader();
34 $scripts = $header->getScripts();
35 $scripts->addFile('db_qbe.js');
37 //Get saved search list.
38 $savedSearch = new SavedSearches($GLOBALS);
39 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
40 ->setDbname($GLOBALS['db']);
42 if (!empty($_POST['searchId'])) {
43 $savedSearch->setId($_POST['searchId']);
46 //Action field is sent.
47 if (isset($_POST['action'])) {
48 $savedSearch->setSearchName($_POST['searchName']);
49 if ('create' === $_POST['action']) {
50 $saveResult = $savedSearch->setId(null)
51 ->setCriterias($_POST)
52 ->save();
53 } elseif ('update' === $_POST['action']) {
54 $saveResult = $savedSearch->setCriterias($_POST)
55 ->save();
56 } elseif ('delete' === $_POST['action']) {
57 $deleteResult = $savedSearch->delete();
58 //After deletion, reset search.
59 $savedSearch = new SavedSearches($GLOBALS);
60 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
61 ->setDbname($GLOBALS['db']);
62 $_POST = array();
63 } elseif ('load' === $_POST['action']) {
64 if (empty($_POST['searchId'])) {
65 //when not loading a search, reset the object.
66 $savedSearch = new SavedSearches($GLOBALS);
67 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
68 ->setDbname($GLOBALS['db']);
69 $_POST = array();
70 } else {
71 $loadResult = $savedSearch->load();
74 //Else, it's an "update query"
77 $savedSearchList = $savedSearch->getList();
78 $currentSearchId = $savedSearch->getId();
81 /**
82 * A query has been submitted -> (maybe) execute it
84 $message_to_display = false;
85 if (isset($_POST['submit_sql']) && ! empty($sql_query)) {
86 if (! preg_match('@^SELECT@i', $sql_query)) {
87 $message_to_display = true;
88 } else {
89 $goto = 'db_sql.php';
90 $sql = new Sql();
91 $sql->executeQueryAndSendQueryResponse(
92 null, // analyzed_sql_results
93 false, // is_gotofile
94 $_POST['db'], // db
95 null, // table
96 false, // find_real_end
97 null, // sql_query_for_bookmark
98 null, // extra_data
99 null, // message_to_show
100 null, // message
101 null, // sql_data
102 $goto, // goto
103 $pmaThemeImage, // pmaThemeImage
104 null, // disp_query
105 null, // disp_message
106 null, // query_type
107 $sql_query, // sql_query
108 null, // selectedTables
109 null // complete_query
114 $sub_part = '_qbe';
115 require 'libraries/db_common.inc.php';
116 $url_query .= '&amp;goto=db_qbe.php';
117 $url_params['goto'] = 'db_qbe.php';
119 list(
120 $tables,
121 $num_tables,
122 $total_num_tables,
123 $sub_part,
124 $is_show_stats,
125 $db_is_system_schema,
126 $tooltip_truename,
127 $tooltip_aliasname,
128 $pos
129 ) = Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
131 if ($message_to_display) {
132 Message::error(
133 __('You have to choose at least one column to display!')
135 ->display();
137 unset($message_to_display);
139 // create new qbe search instance
140 $db_qbe = new Qbe($GLOBALS['db'], $savedSearchList, $savedSearch);
142 $secondaryTabs = [
143 'multi' => [
144 'link' => 'db_multi_table_query.php',
145 'text' => __('Multi-table query'),
147 'qbe' => [
148 'link' => 'db_qbe.php',
149 'text' => __('Query by example'),
152 $response->addHTML(
153 Template::get('secondary_tabs')->render([
154 'url_params' => $url_params,
155 'sub_tabs' => $secondaryTabs,
159 $url = 'db_designer.php' . Url::getCommon(
160 array_merge(
161 $url_params,
162 array('query' => 1)
165 $response->addHTML(
166 Message::notice(
167 sprintf(
168 __('Switch to %svisual builder%s'),
169 '<a href="' . $url . '">',
170 '</a>'
176 * Displays the Query by example form
178 $response->addHTML($db_qbe->getSelectionForm());