2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
8 use PMA\libraries\SavedSearches
;
14 require_once 'libraries/common.inc.php';
15 require_once 'libraries/bookmark.lib.php';
16 require_once 'libraries/sql.lib.php';
18 $response = PMA\libraries\Response
::getInstance();
20 // Gets the relation settings
21 $cfgRelation = PMA_getRelationsParam();
23 $savedSearchList = array();
25 $currentSearchId = null;
26 if ($cfgRelation['savedsearcheswork']) {
27 $header = $response->getHeader();
28 $scripts = $header->getScripts();
29 $scripts->addFile('db_qbe.js');
31 //Get saved search list.
32 $savedSearch = new 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 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 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;
84 PMA_executeQueryAndSendQueryResponse(
85 null, // analyzed_sql_results
87 $_REQUEST['db'], // db
89 false, // find_real_end
90 null, // sql_query_for_bookmark
92 null, // message_to_show
96 $pmaThemeImage, // pmaThemeImage
100 $sql_query, // sql_query
101 null, // selectedTables
102 null // complete_query
108 require 'libraries/db_common.inc.php';
109 $url_query .= '&goto=db_qbe.php';
110 $url_params['goto'] = 'db_qbe.php';
118 $db_is_system_schema,
122 ) = PMA\libraries\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
124 if ($message_to_display) {
125 PMA\libraries\Message
::error(
126 __('You have to choose at least one column to display!')
130 unset($message_to_display);
132 // create new qbe search instance
133 $db_qbe = new PMA\libraries\
DbQbe($GLOBALS['db'], $savedSearchList, $savedSearch);
135 $url = 'db_designer.php' . URL
::getCommon(
142 PMA\libraries\Message
::notice(
144 __('Switch to %svisual builder%s'),
145 '<a href="' . $url . '">',
152 * Displays the Query by example form
154 $response->addHTML($db_qbe->getSelectionForm());