2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
8 use PMA\libraries\SavedSearches
;
13 require_once 'libraries/common.inc.php';
14 require_once 'libraries/bookmark.lib.php';
15 require_once 'libraries/sql.lib.php';
17 $response = PMA\libraries\Response
::getInstance();
19 // Gets the relation settings
20 $cfgRelation = PMA_getRelationsParam();
22 $savedSearchList = array();
24 $currentSearchId = null;
25 if ($cfgRelation['savedsearcheswork']) {
26 $header = $response->getHeader();
27 $scripts = $header->getScripts();
28 $scripts->addFile('db_qbe.js');
30 //Get saved search list.
31 $savedSearch = new SavedSearches($GLOBALS);
32 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
33 ->setDbname($_REQUEST['db']);
35 if (!empty($_REQUEST['searchId'])) {
36 $savedSearch->setId($_REQUEST['searchId']);
39 //Action field is sent.
40 if (isset($_REQUEST['action'])) {
41 $savedSearch->setSearchName($_REQUEST['searchName']);
42 if ('create' === $_REQUEST['action']) {
43 $saveResult = $savedSearch->setId(null)
44 ->setCriterias($_REQUEST)
46 } elseif ('update' === $_REQUEST['action']) {
47 $saveResult = $savedSearch->setCriterias($_REQUEST)
49 } elseif ('delete' === $_REQUEST['action']) {
50 $deleteResult = $savedSearch->delete();
51 //After deletion, reset search.
52 $savedSearch = new SavedSearches($GLOBALS);
53 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
54 ->setDbname($_REQUEST['db']);
56 } elseif ('load' === $_REQUEST['action']) {
57 if (empty($_REQUEST['searchId'])) {
58 //when not loading a search, reset the object.
59 $savedSearch = new SavedSearches($GLOBALS);
60 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
61 ->setDbname($_REQUEST['db']);
64 $loadResult = $savedSearch->load();
67 //Else, it's an "update query"
70 $savedSearchList = $savedSearch->getList();
71 $currentSearchId = $savedSearch->getId();
75 * A query has been submitted -> (maybe) execute it
77 $message_to_display = false;
78 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
79 if (! preg_match('@^SELECT@i', $sql_query)) {
80 $message_to_display = true;
84 // Parse and analyze the query
85 include_once 'libraries/parse_analyze.lib.php';
87 $analyzed_sql_results,
90 ) = PMA_parseAnalyze($sql_query, $db);
91 // @todo: possibly refactor
92 extract($analyzed_sql_results);
94 PMA_executeQueryAndSendQueryResponse(
95 $analyzed_sql_results, // analyzed_sql_results
97 $_REQUEST['db'], // db
99 false, // find_real_end
100 null, // sql_query_for_bookmark
102 null, // message_to_show
106 $pmaThemeImage, // pmaThemeImage
108 null, // disp_message
110 $sql_query, // sql_query
111 null, // selectedTables
112 null // complete_query
118 require 'libraries/db_common.inc.php';
119 $url_query .= '&goto=db_qbe.php';
120 $url_params['goto'] = 'db_qbe.php';
128 $db_is_system_schema,
132 ) = PMA\libraries\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
134 if ($message_to_display) {
135 PMA\libraries\Message
::error(__('You have to choose at least one column to display!'))
138 unset($message_to_display);
140 // create new qbe search instance
141 $db_qbe = new PMA\libraries\
DbQbe($GLOBALS['db'], $savedSearchList, $savedSearch);
143 $url = 'db_designer.php' . PMA_URL_getCommon(
150 PMA\libraries\Message
::notice(
152 __('Switch to %svisual builder%s'),
153 '<a href="' . $url . '">',
160 * Displays the Query by example form
162 $response->addHTML($db_qbe->getSelectionForm());