Use correct field names when exporting custom SQL

This commit is contained in:
Michal Čihař
2003-06-25 16:19:03 +00:00
parent d2a95f306a
commit e41ad772b2
4 changed files with 27 additions and 34 deletions

View File

@@ -9,6 +9,9 @@ $Source$
* libraries/sqlparser.lib.php3: Fixed XSS problem. * libraries/sqlparser.lib.php3: Fixed XSS problem.
* tbl_properties.inc.php3, libraries/functions.js: Alert user when not * tbl_properties.inc.php3, libraries/functions.js: Alert user when not
specied length for CHAR/VARCHAR fields. specied length for CHAR/VARCHAR fields.
* libraries/export/{csv,latex,xml}.php3: Use correct field names when
exporting custom SQL (also saves one SQL query for export) (fixes bug
#755386).
2003-06-24 Marc Delisle <lem9@users.sourceforge.net> 2003-06-24 Marc Delisle <lem9@users.sourceforge.net>
* sql.php3, bug 759568, row count, DISTINCT and MySQL 4 * sql.php3, bug 759568, row count, DISTINCT and MySQL 4

View File

@@ -109,30 +109,27 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
global $enclosed; global $enclosed;
global $escaped; global $escaped;
// Gets the data from the database
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
$fields_cnt = mysql_num_fields($result);
// If required, get fields name at the first line // If required, get fields name at the first line
if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') { if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') {
$schema_insert = ''; $schema_insert = '';
$local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db); for ($i = 0; $i < $fields_cnt; $i++) {
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); if ($enclosed == '') {
while ($row = PMA_mysql_fetch_array($result)) { $schema_insert .= mysql_field_name($result, $i);
if ($enc_by == '') {
$schema_insert .= $row['Field'];
} else { } else {
$schema_insert .= $enc_by $schema_insert .= $enclosed
. str_replace($enc_by, $esc_by . $enc_by, $row['Field']) . str_replace($enclosed, $escaped . $enclosed, mysql_field_name($result, $i))
. $enc_by; . $enclosed;
} }
$schema_insert .= $sep; $schema_insert .= $separator;
} // end while } // end for
$schema_insert =trim(substr($schema_insert, 0, -1)); $schema_insert =trim(substr($schema_insert, 0, -1));
if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE; if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE;
} // end if } // end if
// Gets the data from the database
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
$fields_cnt = mysql_num_fields($result);
// Format the data // Format the data
$i = 0; $i = 0;
while ($row = PMA_mysql_fetch_row($result)) { while ($row = PMA_mysql_fetch_row($result)) {

View File

@@ -100,21 +100,16 @@ function PMA_exportDBCreate($db) {
* @access public * @access public
*/ */
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
for ($i = 0; $row = PMA_mysql_fetch_array($result, MYSQL_ASSOC); $i++) {
$columns[$i] = $row['Field'];
}
$columns_cnt = count($columns);
unset($i);
unset($local_query);
mysql_free_result($result);
$tex_escape = array("$", "%", "{", "}", "&", "#", "_", "^"); $tex_escape = array("$", "%", "{", "}", "&", "#", "_", "^");
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url); $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
$columns_cnt = mysql_num_fields($result);
for ($i = 0; $i < $columns_cnt; $i++) {
$columns[$i] = mysql_field_name($result, $i);
}
unset($i);
$buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strData'] . $crlf . '%' . $crlf $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strData'] . $crlf . '%' . $crlf
. '\\begin{table} ' . $crlf . '\\begin{table} ' . $crlf
. ' \\begin{longtable}{|'; . ' \\begin{longtable}{|';

View File

@@ -106,16 +106,14 @@ function PMA_exportDBCreate($db) {
* @access public * @access public
*/ */
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
for ($i = 0; $row = PMA_mysql_fetch_array($result, MYSQL_ASSOC); $i++) {
$columns[$i] = $row['Field'];
}
$columns_cnt = count($columns);
unset($i);
mysql_free_result($result);
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url); $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
$columns_cnt = mysql_num_fields($result);
for ($i = 0; $i < $columns_cnt; $i++) {
$columns[$i] = mysql_field_name($result, $i);
}
unset($i);
$buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf; $buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
if (!PMA_exportOutputHandler($buffer)) return FALSE; if (!PMA_exportOutputHandler($buffer)) return FALSE;