Continue refactoring db tracking
[phpmyadmin.git] / db_qbe.php
blob2fcc52d37ddb878178cf719a25d7d8a6a8f8225a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * query by example the whole database
6 * @package PhpMyAdmin
7 */
9 /**
10 * requirements
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/DBQbe.class.php';
14 require_once 'libraries/bookmark.lib.php';
15 require_once 'libraries/sql.lib.php';
17 $response = PMA_Response::getInstance();
19 // Gets the relation settings
20 $cfgRelation = PMA_getRelationsParam();
22 $savedSearchList = array();
23 $savedSearch = null;
24 $currentSearchId = null;
25 if ($cfgRelation['savedsearcheswork']) {
26 include 'libraries/SavedSearches.class.php';
27 $header = $response->getHeader();
28 $scripts = $header->getScripts();
29 $scripts->addFile('db_qbe.js');
31 //Get saved search list.
32 $savedSearch = new PMA_SavedSearches($GLOBALS);
33 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
34 ->setDbname($_REQUEST['db']);
36 if (!empty($_REQUEST['searchId'])) {
37 $savedSearch->setId($_REQUEST['searchId']);
40 //Action field is sent.
41 if (isset($_REQUEST['action'])) {
42 $savedSearch->setSearchName($_REQUEST['searchName']);
43 if ('create' === $_REQUEST['action']) {
44 $saveResult = $savedSearch->setId(null)
45 ->setCriterias($_REQUEST)
46 ->save();
47 } elseif ('update' === $_REQUEST['action']) {
48 $saveResult = $savedSearch->setCriterias($_REQUEST)
49 ->save();
50 } elseif ('delete' === $_REQUEST['action']) {
51 $deleteResult = $savedSearch->delete();
52 //After deletion, reset search.
53 $savedSearch = new PMA_SavedSearches($GLOBALS);
54 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
55 ->setDbname($_REQUEST['db']);
56 $_REQUEST = array();
57 } elseif ('load' === $_REQUEST['action']) {
58 if (empty($_REQUEST['searchId'])) {
59 //when not loading a search, reset the object.
60 $savedSearch = new PMA_SavedSearches($GLOBALS);
61 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
62 ->setDbname($_REQUEST['db']);
63 $_REQUEST = array();
64 } else {
65 $loadResult = $savedSearch->load();
68 //Else, it's an "update query"
71 $savedSearchList = $savedSearch->getList();
72 $currentSearchId = $savedSearch->getId();
75 /**
76 * A query has been submitted -> (maybe) execute it
78 $message_to_display = false;
79 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
80 if (! preg_match('@^SELECT@i', $sql_query)) {
81 $message_to_display = true;
82 } else {
83 $goto = 'db_sql.php';
85 // Parse and analyze the query
86 include_once 'libraries/parse_analyze.inc.php';
88 PMA_executeQueryAndSendQueryResponse(
89 $analyzed_sql_results, // analyzed_sql_results
90 false, // is_gotofile
91 $_REQUEST['db'], // db
92 null, // table
93 false, // find_real_end
94 null, // sql_query_for_bookmark
95 null, // extra_data
96 null, // message_to_show
97 null, // message
98 null, // sql_data
99 $goto, // goto
100 $pmaThemeImage, // pmaThemeImage
101 null, // disp_query
102 null, // disp_message
103 null, // query_type
104 $sql_query, // sql_query
105 null, // selectedTables
106 null // complete_query
111 $sub_part = '_qbe';
112 require 'libraries/db_common.inc.php';
113 $url_query .= '&amp;goto=db_qbe.php';
114 $url_params['goto'] = 'db_qbe.php';
115 require 'libraries/db_info.inc.php';
117 if ($message_to_display) {
118 PMA_Message::error(__('You have to choose at least one column to display!'))
119 ->display();
121 unset($message_to_display);
123 // create new qbe search instance
124 $db_qbe = new PMA_DbQbe($GLOBALS['db'], $savedSearchList, $savedSearch);
126 $url = 'db_designer.php' . PMA_URL_getCommon(
127 array_merge(
128 $url_params,
129 array('query' => 1)
132 $response->addHTML(
133 PMA_Message::notice(
134 sprintf(
135 __('Switch to %svisual builder%s'),
136 '<a href="' . $url . '">',
137 '</a>'
143 * Displays the Query by example form
145 $response->addHTML($db_qbe->getSelectionForm());