From 5d660eb09d4c54a862c1b9fc48d1d42b6436eebd Mon Sep 17 00:00:00 2001 From: pratiksethia1 Date: Sat, 21 Mar 2015 00:15:30 +0530 Subject: [PATCH 1/3] Feature Request #1625 Autocomplete Sql Gives an option to user to toggle autocomplete of table and column names in config settings Signed-off-by: Pratik Sethia --- db_sql_autocomplete.php | 24 ++++++++++----------- doc/config.rst | 8 +++++++ libraries/config.default.php | 7 ++++++ libraries/config/messages.inc.php | 2 ++ libraries/config/setup.forms.php | 3 ++- libraries/config/user_preferences.forms.php | 3 ++- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/db_sql_autocomplete.php b/db_sql_autocomplete.php index 4897f0058a..29f117afcf 100644 --- a/db_sql_autocomplete.php +++ b/db_sql_autocomplete.php @@ -8,17 +8,17 @@ require_once 'libraries/common.inc.php'; -$db = isset($_POST['db']) ? $_POST['db'] : $GLOBALS['db']; -$sql_autocomplete = array(); - -if ($db) { - $tableNames = $GLOBALS['dbi']->getTables($db); - foreach ($tableNames as $tableName) { - $sql_autocomplete[$tableName] = $GLOBALS['dbi']->getColumns( - $db, $tableName - ); +if ($GLOBALS['cfg']['EnableAutocompleteForTablesAndColumns']) { + $db = isset($_POST['db']) ? $_POST['db'] : $GLOBALS['db']; + $sql_autocomplete = array(); + if ($db) { + $tableNames = $GLOBALS['dbi']->getTables($db); + foreach ($tableNames as $tableName) { + $sql_autocomplete[$tableName] = $GLOBALS['dbi']->getColumns( + $db, $tableName + ); + } } + $response = PMA_Response::getInstance(); + $response->addJSON("tables", json_encode($sql_autocomplete)); } - -$response = PMA_Response::getInstance(); -$response->addJSON("tables", json_encode($sql_autocomplete)); diff --git a/doc/config.rst b/doc/config.rst index aae9743e8d..3823f83552 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -2424,6 +2424,14 @@ Text fields Defines if the whole textarea of the query box will be selected on click. +.. config:option:: $cfg['EnableAutocompleteForTablesAndColumns'] + + :type: boolean + :default: true + + Whether to Enable Autocomplete for table and Column names in any + SQL Query box. + SQL query box settings ---------------------- diff --git a/libraries/config.default.php b/libraries/config.default.php index 652bdda4c6..b54c397284 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -2866,6 +2866,13 @@ $cfg['SQLQuery']['ShowAsPHP'] = true; */ $cfg['SQLQuery']['Refresh'] = true; +/** + * Enables AutoComplete for table & Column names in SQL queries + * + * default = 'true' + */ +$cfg['EnableAutocompleteForTablesAndColumns'] = true; + /******************************************************************************* * Web server upload/save/import directories diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 6985fa26d2..86d1e4036b 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -91,6 +91,8 @@ $strConfigDefaultTabServer_desc = __('Tab that is displayed when entering a serv $strConfigDefaultTabServer_name = __('Default server tab'); $strConfigDefaultTabTable_desc = __('Tab that is displayed when entering a table.'); $strConfigDefaultTabTable_name = __('Default table tab'); +$strConfigEnableAutocompleteForTablesAndColumns_desc = __('Auto-Complete of the table and Column names in the SQL queries.'); +$strConfigEnableAutocompleteForTablesAndColumns_name = __('Enable AutoComplete for Table '); $strConfigHideStructureActions_desc = __('Whether the table structure actions should be hidden.'); $strConfigHideStructureActions_name = __('Hide table structure actions'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index 42f23c9924..18d7c45e52 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -158,7 +158,8 @@ $forms['Sql_queries']['Sql_queries'] = array( 'IgnoreMultiSubmitErrors', 'MaxCharactersInDisplayedSQL', 'RetainQueryBox', - 'CodemirrorEnable'); + 'CodemirrorEnable', + 'EnableAutocompleteForTablesAndColumns'); $forms['Sql_queries']['Sql_box'] = array('SQLQuery' => array( 'Edit', 'Explain', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index 150642e93f..210e7cdea5 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -67,7 +67,8 @@ $forms['Sql_queries']['Sql_queries'] = array( 'IgnoreMultiSubmitErrors', 'MaxCharactersInDisplayedSQL', 'RetainQueryBox', - 'CodemirrorEnable'); + 'CodemirrorEnable', + 'EnableAutocompleteForTablesAndColumns'); $forms['Sql_queries']['Sql_box'] = array( 'SQLQuery/Edit', 'SQLQuery/Explain', From f7c08962c7c44e69e78c24827db42dbb443aff30 Mon Sep 17 00:00:00 2001 From: pratiksethia1 Date: Sat, 21 Mar 2015 02:24:41 +0530 Subject: [PATCH 2/3] moved response outside "if" condition Signed-off-by: Pratik Sethia --- db_sql_autocomplete.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db_sql_autocomplete.php b/db_sql_autocomplete.php index 29f117afcf..35660c710e 100644 --- a/db_sql_autocomplete.php +++ b/db_sql_autocomplete.php @@ -19,6 +19,6 @@ if ($GLOBALS['cfg']['EnableAutocompleteForTablesAndColumns']) { ); } } - $response = PMA_Response::getInstance(); - $response->addJSON("tables", json_encode($sql_autocomplete)); } +$response = PMA_Response::getInstance(); +$response->addJSON("tables", json_encode($sql_autocomplete)); From c3e0a58ec16655513dd43bf525b7bb296997280f Mon Sep 17 00:00:00 2001 From: pratiksethia1 Date: Sun, 22 Mar 2015 04:33:48 +0530 Subject: [PATCH 3/3] rfe1625 - Solves the repeated POST issues and javascript fatal error Signed-off-by: Pratik Sethia --- db_sql_autocomplete.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db_sql_autocomplete.php b/db_sql_autocomplete.php index 35660c710e..3be88c43ca 100644 --- a/db_sql_autocomplete.php +++ b/db_sql_autocomplete.php @@ -19,6 +19,8 @@ if ($GLOBALS['cfg']['EnableAutocompleteForTablesAndColumns']) { ); } } +} else { + $sql_autocomplete = true; } $response = PMA_Response::getInstance(); $response->addJSON("tables", json_encode($sql_autocomplete));