2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
8 use PhpMyAdmin\Database\Qbe
;
9 use PhpMyAdmin\Message
;
10 use PhpMyAdmin\Relation
;
11 use PhpMyAdmin\Response
;
12 use PhpMyAdmin\SavedSearches
;
14 use PhpMyAdmin\Template
;
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();
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)
53 } elseif ('update' === $_POST['action']) {
54 $saveResult = $savedSearch->setCriterias($_POST)
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']);
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']);
71 $loadResult = $savedSearch->load();
74 //Else, it's an "update query"
77 $savedSearchList = $savedSearch->getList();
78 $currentSearchId = $savedSearch->getId();
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;
91 $sql->executeQueryAndSendQueryResponse(
92 null, // analyzed_sql_results
96 false, // find_real_end
97 null, // sql_query_for_bookmark
99 null, // message_to_show
103 $pmaThemeImage, // pmaThemeImage
105 null, // disp_message
107 $sql_query, // sql_query
108 null, // selectedTables
109 null // complete_query
115 require 'libraries/db_common.inc.php';
116 $url_query .= '&goto=db_qbe.php';
117 $url_params['goto'] = 'db_qbe.php';
125 $db_is_system_schema,
129 ) = Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
131 if ($message_to_display) {
133 __('You have to choose at least one column to display!')
137 unset($message_to_display);
139 // create new qbe search instance
140 $db_qbe = new Qbe($GLOBALS['db'], $savedSearchList, $savedSearch);
144 'link' => 'db_multi_table_query.php',
145 'text' => __('Multi-table query'),
148 'link' => 'db_qbe.php',
149 'text' => __('Query by example'),
153 Template
::get('secondary_tabs')->render([
154 'url_params' => $url_params,
155 'sub_tabs' => $secondaryTabs,
159 $url = 'db_designer.php' . Url
::getCommon(
168 __('Switch to %svisual builder%s'),
169 '<a href="' . $url . '">',
176 * Displays the Query by example form
178 $response->addHTML($db_qbe->getSelectionForm());