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.
* tbl_properties.inc.php3, libraries/functions.js: Alert user when not
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>
* 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 $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 (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') {
$schema_insert = '';
$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);
while ($row = PMA_mysql_fetch_array($result)) {
if ($enc_by == '') {
$schema_insert .= $row['Field'];
for ($i = 0; $i < $fields_cnt; $i++) {
if ($enclosed == '') {
$schema_insert .= mysql_field_name($result, $i);
} else {
$schema_insert .= $enc_by
. str_replace($enc_by, $esc_by . $enc_by, $row['Field'])
. $enc_by;
$schema_insert .= $enclosed
. str_replace($enclosed, $escaped . $enclosed, mysql_field_name($result, $i))
. $enclosed;
}
$schema_insert .= $sep;
} // end while
$schema_insert .= $separator;
} // end for
$schema_insert =trim(substr($schema_insert, 0, -1));
if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE;
} // 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
$i = 0;
while ($row = PMA_mysql_fetch_row($result)) {

View File

@@ -100,21 +100,16 @@ function PMA_exportDBCreate($db) {
* @access public
*/
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("$", "%", "{", "}", "&", "#", "_", "^");
$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
. '\\begin{table} ' . $crlf
. ' \\begin{longtable}{|';

View File

@@ -106,16 +106,14 @@ function PMA_exportDBCreate($db) {
* @access public
*/
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);
$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;
if (!PMA_exportOutputHandler($buffer)) return FALSE;