2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
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();
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)
47 } elseif ('update' === $_REQUEST['action']) {
48 $saveResult = $savedSearch->setCriterias($_REQUEST)
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']);
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']);
65 $loadResult = $savedSearch->load();
68 //Else, it's an "update query"
71 $savedSearchList = $savedSearch->getList();
72 $currentSearchId = $savedSearch->getId();
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;
85 // Parse and analyze the query
86 include_once 'libraries/parse_analyze.inc.php';
88 PMA_executeQueryAndSendQueryResponse(
89 $analyzed_sql_results, // analyzed_sql_results
91 $_REQUEST['db'], // db
93 false, // find_real_end
94 null, // sql_query_for_bookmark
96 null, // message_to_show
100 $pmaThemeImage, // pmaThemeImage
102 null, // disp_message
104 $sql_query, // sql_query
105 null, // selectedTables
106 null // complete_query
112 require 'libraries/db_common.inc.php';
113 $url_query .= '&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!'))
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(
135 __('Switch to %svisual builder%s'),
136 '<a href="' . $url . '">',
143 * Displays the Query by example form
145 $response->addHTML($db_qbe->getSelectionForm());