diff --git a/libraries/sql_query_form.lib.php b/libraries/sql_query_form.lib.php
index ecfa3b6e6b..08e7c2bdc1 100644
--- a/libraries/sql_query_form.lib.php
+++ b/libraries/sql_query_form.lib.php
@@ -123,6 +123,67 @@ function PMA_getHtmlForSqlQueryForm(
return $html;
}
+/**
+ * Get initial values for Sql Query Form Insert
+ *
+ * @param string $query query to display in the textarea
+ *
+ * @return array ($legend, $query, $columns_list)
+ *
+ * @usedby PMA_getHtmlForSqlQueryFormInsert()
+ */
+function PMA_initQueryForm($query)
+{
+ $columns_list = array();
+ if (! /*overload*/mb_strlen($GLOBALS['db'])) {
+ // prepare for server related
+ $legend = sprintf(
+ __('Run SQL query/queries on server %s'),
+ '"' . htmlspecialchars(
+ ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'])
+ ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']
+ : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']
+ ) . '"'
+ );
+ } elseif (! /*overload*/mb_strlen($GLOBALS['table'])) {
+ // prepare for db related
+ $db = $GLOBALS['db'];
+ // if you want navigation:
+ $tmp_db_link = '';
+ $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
+ if (empty($query)) {
+ $query = PMA_Util::expandUserString(
+ $GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'
+ );
+ }
+ } else {
+ $db = $GLOBALS['db'];
+ // Get the list and number of fields
+ // we do a try_query here, because we could be in the query window,
+ // trying to synchronize and the table has not yet been created
+ $columns_list = $GLOBALS['dbi']->getColumns(
+ $db, $GLOBALS['table'], null, true
+ );
+
+ $tmp_db_link = '';
+ $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
+ if (empty($query)) {
+ $query = PMA_Util::expandUserString(
+ $GLOBALS['cfg']['DefaultQueryTable'], 'backquote'
+ );
+ }
+ }
+ $legend .= ': ' . PMA_Util::showMySQLDocu('SELECT');
+
+ return array($legend, $query, $columns_list);
+}
+
/**
* return HTML for Sql Query Form Insert
*
@@ -146,58 +207,9 @@ function PMA_getHtmlForSqlQueryFormInsert(
$locking = '';
$height = $GLOBALS['cfg']['TextareaRows'] * 2;
- $fields_list = array();
- if (! /*overload*/mb_strlen($GLOBALS['db'])) {
- // prepare for server related
- $legend = sprintf(
- __('Run SQL query/queries on server %s'),
- '"' . htmlspecialchars(
- ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'])
- ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']
- : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']
- ) . '"'
- );
- } elseif (! /*overload*/mb_strlen($GLOBALS['table'])) {
- // prepare for db related
- $db = $GLOBALS['db'];
- // if you want navigation:
- $tmp_db_link = '';
- // else use
- // $tmp_db_link = htmlspecialchars($db);
- $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
- if (empty($query)) {
- $query = PMA_Util::expandUserString(
- $GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'
- );
- }
- } else {
- $db = $GLOBALS['db'];
- // Get the list and number of fields
- // we do a try_query here, because we could be in the query window,
- // trying to synchronize and the table has not yet been created
- $fields_list = $GLOBALS['dbi']->getColumns(
- $db, $GLOBALS['table'], null, true
- );
+ list($legend, $query, $columns_list) = PMA_initQueryForm($query);
- $tmp_db_link = '';
- // else use
- // $tmp_db_link = htmlspecialchars($db);
- $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
- if (empty($query)) {
- $query = PMA_Util::expandUserString(
- $GLOBALS['cfg']['DefaultQueryTable'], 'backquote'
- );
- }
- }
- $legend .= ': ' . PMA_Util::showMySQLDocu('SELECT');
-
- if (count($fields_list)) {
+ if (! empty($columns_list)) {
$sqlquerycontainer_id = 'sqlquerycontainer';
} else {
$sqlquerycontainer_id = 'sqlquerycontainerfull';
@@ -219,7 +231,7 @@ function PMA_getHtmlForSqlQueryFormInsert(
$html .= '';
// Add buttons to generate query easily for
// select all, single select, insert, update and delete
- if (count($fields_list)) {
+ if (! empty($columns_list)) {
$html .= '';
$html .= '' . __('Columns') . ''
. '