2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
8 use PhpMyAdmin\Relation
;
9 use PhpMyAdmin\Response
;
10 use PhpMyAdmin\SavedSearches
;
17 require_once 'libraries/common.inc.php';
19 $response = Response
::getInstance();
21 // Gets the relation settings
22 $cfgRelation = Relation
::getRelationsParam();
24 $savedSearchList = array();
26 $currentSearchId = null;
27 if ($cfgRelation['savedsearcheswork']) {
28 $header = $response->getHeader();
29 $scripts = $header->getScripts();
30 $scripts->addFile('db_qbe.js');
32 //Get saved search list.
33 $savedSearch = new SavedSearches($GLOBALS);
34 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
35 ->setDbname($_REQUEST['db']);
37 if (!empty($_REQUEST['searchId'])) {
38 $savedSearch->setId($_REQUEST['searchId']);
41 //Action field is sent.
42 if (isset($_REQUEST['action'])) {
43 $savedSearch->setSearchName($_REQUEST['searchName']);
44 if ('create' === $_REQUEST['action']) {
45 $saveResult = $savedSearch->setId(null)
46 ->setCriterias($_REQUEST)
48 } elseif ('update' === $_REQUEST['action']) {
49 $saveResult = $savedSearch->setCriterias($_REQUEST)
51 } elseif ('delete' === $_REQUEST['action']) {
52 $deleteResult = $savedSearch->delete();
53 //After deletion, reset search.
54 $savedSearch = new SavedSearches($GLOBALS);
55 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
56 ->setDbname($_REQUEST['db']);
58 } elseif ('load' === $_REQUEST['action']) {
59 if (empty($_REQUEST['searchId'])) {
60 //when not loading a search, reset the object.
61 $savedSearch = new SavedSearches($GLOBALS);
62 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
63 ->setDbname($_REQUEST['db']);
66 $loadResult = $savedSearch->load();
69 //Else, it's an "update query"
72 $savedSearchList = $savedSearch->getList();
73 $currentSearchId = $savedSearch->getId();
77 * A query has been submitted -> (maybe) execute it
79 $message_to_display = false;
80 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
81 if (! preg_match('@^SELECT@i', $sql_query)) {
82 $message_to_display = true;
85 Sql
::executeQueryAndSendQueryResponse(
86 null, // analyzed_sql_results
88 $_REQUEST['db'], // db
90 false, // find_real_end
91 null, // sql_query_for_bookmark
93 null, // message_to_show
97 $pmaThemeImage, // pmaThemeImage
101 $sql_query, // sql_query
102 null, // selectedTables
103 null // complete_query
109 require 'libraries/db_common.inc.php';
110 $url_query .= '&goto=db_qbe.php';
111 $url_params['goto'] = 'db_qbe.php';
119 $db_is_system_schema,
123 ) = PhpMyAdmin\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
125 if ($message_to_display) {
126 PhpMyAdmin\Message
::error(
127 __('You have to choose at least one column to display!')
131 unset($message_to_display);
133 // create new qbe search instance
134 $db_qbe = new PhpMyAdmin\
DbQbe($GLOBALS['db'], $savedSearchList, $savedSearch);
136 $url = 'db_designer.php' . Url
::getCommon(
143 PhpMyAdmin\Message
::notice(
145 __('Switch to %svisual builder%s'),
146 '<a href="' . $url . '">',
153 * Displays the Query by example form
155 $response->addHTML($db_qbe->getSelectionForm());