Convert default queries to unified expansion.

This commit is contained in:
Michal Čihař
2010-07-27 10:01:58 +02:00
parent 01ded03e89
commit 39aa4355a9
5 changed files with 32 additions and 30 deletions

View File

@@ -91,8 +91,9 @@ $Id$
+ [core] Dropped AllowAnywhereRecoding configuration variable.
- rfe #3016457 [interface] Define tab order in SQL form to allow easier tab
navigation.
+ [code] Centralized format string expansion, @VARIABLES@ are recommended way
now.
+ [core] Centralized format string expansion, @VARIABLES@ are recommended way
now, used by file name templates, default queries, export and title
generating.
+ [validator] SQL validator works also with SOAP PHP extension.
- [interface] Better formatting for SQL validator results.
- [doc] The linked-tables infrastructure is now called phpMyAdmin

View File

@@ -2182,9 +2182,9 @@ setfacl -d -m "g:www-data:rwx" tmp
<span id="cfg_DefaultQueryDatabase">$cfg['DefaultQueryDatabase']</span> string
</dt>
<dd>Default queries that will be displayed in query boxes when user didn't
specify any. Use %d for database name, %t for table name and %f for a
comma separated list of column names. Note that %t and %f are only
applicable to <tt>$cfg['DefaultQueryTable']</tt>.</dd>
specify any. You can use standard
<a href="#faq6_27">format string expansion</a>.
</dd>
<dt id="cfg_SQP_fmtType">$cfg['SQP']['fmtType'] string [<tt>html</tt>|<tt>none</tt>]</dt>
<dd>
@@ -4353,6 +4353,8 @@ chmod o+rwx tmp
<dd>Currently opened database</dd>
<dt><code>@TABLE@</code></dt>
<dd>Currently opened table</dd>
<dt><code>@FIELDS@</code></dt>
<dd>Fields of currently opened table</dd>
<dt><code>@PHPMYADMIN@</code></dt>
<dd>phpMyAdmin with version</dd>
</dl>

View File

@@ -2891,6 +2891,24 @@ function PMA_expandUserString($string, $escape = NULL, $updates = array()) {
}
}
/* Fetch fields list if required */
if (strpos($string, '@FIELDS@') !== FALSE) {
$fields_list = PMA_DBI_fetch_result(
'SHOW FULL COLUMNS FROM ' . PMA_backquote($GLOBALS['db'])
. '.' . PMA_backquote($GLOBALS['table']));
$field_names = array();
foreach ($fields_list as $field) {
if (!is_null($escape)) {
$field_names[] = $escape($field['Field']);
} else {
$field_names[] = $field['Field'];
}
}
$replace['@FIELDS@'] = implode(',', $field_names);
}
/* Do the replacement */
return str_replace(array_keys($replace), array_values($replace), strftime($string));
}

View File

@@ -2344,22 +2344,14 @@ $cfg['ThemePerServer'] = false;
*/
/**
* Default queries
* %d will be replaced by the database name.
* %t will be replaced by the table name.
* %f will be replaced by a list of field names.
* (%t and %f only applies to DefaultQueryTable)
* Default query for table
*
* @global string $cfg['DefaultQueryTable']
*/
$cfg['DefaultQueryTable'] = 'SELECT * FROM %t WHERE 1';
$cfg['DefaultQueryTable'] = 'SELECT * FROM @TABLE@ WHERE 1';
/**
* Default queries
* %d will be replaced by the database name.
* %t will be replaced by the table name.
* %f will be replaced by a list of field names.
* (%t and %f only applies to DefaultQueryTable)
* Default query for database
*
* @global string $cfg['DefaultQueryDatabase']
*/

View File

@@ -233,8 +233,7 @@ function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false, $delimiter
// $tmp_db_link = htmlspecialchars($db);
$legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
if (empty($query)) {
$query = str_replace('%d',
PMA_backquote($db), $GLOBALS['cfg']['DefaultQueryDatabase']);
$query = PMA_expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'PMA_backquote');
}
} else {
$table = $GLOBALS['table'];
@@ -257,18 +256,8 @@ function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false, $delimiter
// else use
// $tmp_db_link = htmlspecialchars($db);
$legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
if (empty($query) && count($fields_list)) {
$field_names = array();
foreach ($fields_list as $field) {
$field_names[] = PMA_backquote($field['Field']);
}
$query =
str_replace('%d', PMA_backquote($db),
str_replace('%t', PMA_backquote($table),
str_replace('%f',
implode(', ', $field_names),
$GLOBALS['cfg']['DefaultQueryTable'])));
unset($field_names);
if (empty($query)) {
$query = PMA_expandUserString($GLOBALS['cfg']['DefaultQueryTable'], 'PMA_backquote');
}
}
$legend .= ': ' . PMA_showMySQLDocu('SQL-Syntax', 'SELECT');