return also works for includes ... so don't mess with intends

This commit is contained in:
Sebastian Mendel
2007-03-29 11:45:12 +00:00
parent adc43110f6
commit 02ecd621bb
4 changed files with 675 additions and 661 deletions

View File

@@ -10,8 +10,11 @@
/** /**
* *
*/ */
if ($plugin_param == 'table') { if ($plugin_param !== 'table') {
if (isset($plugin_list)) { return;
}
if (isset($plugin_list)) {
$plugin_list['csv'] = array( $plugin_list['csv'] = array(
'text' => 'strCSV', 'text' => 'strCSV',
'extension' => 'csv', 'extension' => 'csv',
@@ -26,52 +29,54 @@ if ($plugin_param == 'table') {
), ),
'options_text' => 'strCSVImportOptions', 'options_text' => 'strCSVImportOptions',
); );
} else {
/* We do not define function when plugin is just queried for information above */ /* We do not define function when plugin is just queried for information above */
$replacements = array( return;
}
$replacements = array(
'\\n' => "\n", '\\n' => "\n",
'\\t' => "\t", '\\t' => "\t",
'\\r' => "\r", '\\r' => "\r",
); );
$csv_terminated = strtr($csv_terminated, $replacements); $csv_terminated = strtr($csv_terminated, $replacements);
$csv_enclosed = strtr($csv_enclosed, $replacements); $csv_enclosed = strtr($csv_enclosed, $replacements);
$csv_escaped = strtr($csv_escaped, $replacements); $csv_escaped = strtr($csv_escaped, $replacements);
$csv_new_line = strtr($csv_new_line, $replacements); $csv_new_line = strtr($csv_new_line, $replacements);
if (strlen($csv_terminated) != 1) { if (strlen($csv_terminated) != 1) {
$message = sprintf($strInvalidCSVParameter, $strFieldsTerminatedBy); $message = sprintf($strInvalidCSVParameter, $strFieldsTerminatedBy);
$show_error_header = TRUE; $show_error_header = TRUE;
$error = TRUE; $error = TRUE;
} elseif (strlen($csv_enclosed) != 1) { } elseif (strlen($csv_enclosed) != 1) {
$message = sprintf($strInvalidCSVParameter, $strFieldsEnclosedBy); $message = sprintf($strInvalidCSVParameter, $strFieldsEnclosedBy);
$show_error_header = TRUE; $show_error_header = TRUE;
$error = TRUE; $error = TRUE;
} elseif (strlen($csv_escaped) != 1) { } elseif (strlen($csv_escaped) != 1) {
$message = sprintf($strInvalidCSVParameter, $strFieldsEscapedBy); $message = sprintf($strInvalidCSVParameter, $strFieldsEscapedBy);
$show_error_header = TRUE; $show_error_header = TRUE;
$error = TRUE; $error = TRUE;
} elseif (strlen($csv_new_line) != 1 && $csv_new_line != 'auto') { } elseif (strlen($csv_new_line) != 1 && $csv_new_line != 'auto') {
$message = sprintf($strInvalidCSVParameter, $strLinesTerminatedBy); $message = sprintf($strInvalidCSVParameter, $strLinesTerminatedBy);
$show_error_header = TRUE; $show_error_header = TRUE;
$error = TRUE; $error = TRUE;
} }
$buffer = ''; $buffer = '';
if (isset($csv_replace)) { if (isset($csv_replace)) {
$sql_template = 'REPLACE'; $sql_template = 'REPLACE';
} else { } else {
$sql_template = 'INSERT'; $sql_template = 'INSERT';
if (isset($csv_ignore)) { if (isset($csv_ignore)) {
$sql_template .= ' IGNORE'; $sql_template .= ' IGNORE';
} }
} }
$sql_template .= ' INTO ' . PMA_backquote($table); $sql_template .= ' INTO ' . PMA_backquote($table);
$tmp_fields = PMA_DBI_get_fields($db, $table); $tmp_fields = PMA_DBI_get_fields($db, $table);
if (empty($csv_columns)) { if (empty($csv_columns)) {
$fields = $tmp_fields; $fields = $tmp_fields;
} else { } else {
$sql_template .= ' ('; $sql_template .= ' (';
$fields = array(); $fields = array();
$tmp = split(',( ?)', $csv_columns); $tmp = split(',( ?)', $csv_columns);
@@ -97,21 +102,21 @@ if ($plugin_param == 'table') {
$sql_template .= PMA_backquote($val); $sql_template .= PMA_backquote($val);
} }
$sql_template .= ') '; $sql_template .= ') ';
} }
$required_fields = count($fields); $required_fields = count($fields);
$sql_template .= ' VALUES ('; $sql_template .= ' VALUES (';
// Defaults for parser // Defaults for parser
$i = 0; $i = 0;
$len = 0; $len = 0;
$line = 1; $line = 1;
$lasti = -1; $lasti = -1;
$values = array(); $values = array();
$csv_finish = FALSE; $csv_finish = FALSE;
while (!($finished && $i >= $len) && !$error && !$timeout_passed) { while (!($finished && $i >= $len) && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk(); $data = PMA_importGetNextChunk();
if ($data === FALSE) { if ($data === FALSE) {
// subtract data we didn't handle yet and stop processing // subtract data we didn't handle yet and stop processing
@@ -294,16 +299,14 @@ if ($plugin_param == 'table') {
$ch = $buffer[0]; $ch = $buffer[0];
} }
} // End of parser loop } // End of parser loop
} // End of import loop } // End of import loop
// Commit any possible data in buffers // Commit any possible data in buffers
PMA_importRunQuery(); PMA_importRunQuery();
if (count($values) != 0 && !$error) { if (count($values) != 0 && !$error) {
$message = sprintf($strInvalidCSVFormat, $line); $message = sprintf($strInvalidCSVFormat, $line);
$show_error_header = TRUE; $show_error_header = TRUE;
$error = TRUE; $error = TRUE;
}
}
} }
?> ?>

View File

@@ -6,11 +6,17 @@
* @version $Id$ * @version $Id$
*/ */
$cfgRelation = PMA_getRelationsParam();
/** /**
* We need relations enabled and we work only on database * We need relations enabled and we work only on database
*/ */
if ($plugin_param == 'database' && $GLOBALS['num_tables'] > 0 && $GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['commwork']) { if ($plugin_param !== 'database' || $GLOBALS['num_tables'] < 1
if (isset($plugin_list)) { || ! $cfgRelation['relwork'] || ! $cfgRelation['commwork']) {
return;
}
if (isset($plugin_list)) {
$plugin_list['docsql'] = array( // set name of your plugin $plugin_list['docsql'] = array( // set name of your plugin
'text' => 'strDocSQL', // text to be displayed as choice 'text' => 'strDocSQL', // text to be displayed as choice
'extension' => '', // extension this plugin can handle 'extension' => '', // extension this plugin can handle
@@ -19,12 +25,14 @@ if ($plugin_param == 'database' && $GLOBALS['num_tables'] > 0 && $GLOBALS['cfgRe
), ),
'options_text' => 'strDocSQLOptions', // text to describe plugin options (must be set if options are used) 'options_text' => 'strDocSQLOptions', // text to describe plugin options (must be set if options are used)
); );
} else {
/* We do not define function when plugin is just queried for information above */ /* We do not define function when plugin is just queried for information above */
$tab = $_POST['docsql_table']; return;
$buffer = ''; }
/* Read whole buffer, we except it is small enough */
while (!$finished && !$error && !$timeout_passed) { $tab = $_POST['docsql_table'];
$buffer = '';
/* Read whole buffer, we except it is small enough */
while (!$finished && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk(); $data = PMA_importGetNextChunk();
if ($data === FALSE) { if ($data === FALSE) {
// subtract data we didn't handle yet and stop processing // subtract data we didn't handle yet and stop processing
@@ -36,9 +44,9 @@ if ($plugin_param == 'database' && $GLOBALS['num_tables'] > 0 && $GLOBALS['cfgRe
// Append new data to buffer // Append new data to buffer
$buffer .= $data; $buffer .= $data;
} }
} // End of import loop } // End of import loop
/* Process the data */ /* Process the data */
if ($data === TRUE && !$error && !$timeout_passed) { if ($data === TRUE && !$error && !$timeout_passed) {
$buffer = str_replace("\r\n", "\n", $buffer); $buffer = str_replace("\r\n", "\n", $buffer);
$buffer = str_replace("\r", "\n", $buffer); $buffer = str_replace("\r", "\n", $buffer);
$lines = explode("\n", $buffer); $lines = explode("\n", $buffer);
@@ -48,7 +56,7 @@ if ($plugin_param == 'database' && $GLOBALS['num_tables'] > 0 && $GLOBALS['cfgRe
if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) { if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
$qry = ' $qry = '
INSERT INTO INSERT INTO
' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
( db_name, table_name, column_name, ' . PMA_backquote('comment') . ' ) ( db_name, table_name, column_name, ' . PMA_backquote('comment') . ' )
VALUES ( VALUES (
\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\', \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
@@ -61,7 +69,7 @@ if ($plugin_param == 'database' && $GLOBALS['num_tables'] > 0 && $GLOBALS['cfgRe
$for = explode('->', $inf[2]); $for = explode('->', $inf[2]);
$qry = ' $qry = '
INSERT INTO INSERT INTO
' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
( master_db, master_table, master_field, foreign_db, foreign_table, foreign_field) ( master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)
VALUES ( VALUES (
\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\', \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
@@ -73,9 +81,7 @@ if ($plugin_param == 'database' && $GLOBALS['num_tables'] > 0 && $GLOBALS['cfgRe
PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '(' . htmlspecialchars($inf[2]) . ')', true); PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '(' . htmlspecialchars($inf[2]) . ')', true);
} // end inf[2] exists } // end inf[2] exists
} // End lines loop } // End lines loop
} // End import } // End import
// Commit any possible data in buffers // Commit any possible data in buffers
PMA_importRunQuery(); PMA_importRunQuery();
}
}
?> ?>

View File

@@ -9,8 +9,11 @@
/** /**
* *
*/ */
if ($plugin_param == 'table') { if ($plugin_param !== 'table') {
if (isset($plugin_list)) { return;
}
if (isset($plugin_list)) {
if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') { if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') {
$GLOBALS['cfg']['Import']['ldi_local_option'] = FALSE; $GLOBALS['cfg']['Import']['ldi_local_option'] = FALSE;
@@ -45,46 +48,50 @@ if ($plugin_param == 'table') {
), ),
'options_text' => 'strLDIImportOptions', 'options_text' => 'strLDIImportOptions',
); );
} else {
/* We do not define function when plugin is just queried for information above */ /* We do not define function when plugin is just queried for information above */
if ($import_file == 'none' || $compression != 'none' || $charset_conversion) { return;
}
if ($import_file == 'none' || $compression != 'none' || $charset_conversion) {
// We handle only some kind of data! // We handle only some kind of data!
$message = $strInvalidLDIImport; $message = $strInvalidLDIImport;
$show_error_header = TRUE; $show_error_header = TRUE;
$error = TRUE; $error = TRUE;
} else { return;
$sql = 'LOAD DATA'; }
if (isset($ldi_local_option)) {
$sql .= ' LOCAL';
}
$sql .= ' INFILE \'' . PMA_sqlAddslashes($import_file) . '\'';
if (isset($ldi_replace)) {
$sql .= ' REPLACE';
} elseif (isset($ldi_ignore)) {
$sql .= ' IGNORE';
}
$sql .= ' INTO TABLE ' . PMA_backquote($table);
if (strlen($ldi_terminated) > 0) { $sql = 'LOAD DATA';
if (isset($ldi_local_option)) {
$sql .= ' LOCAL';
}
$sql .= ' INFILE \'' . PMA_sqlAddslashes($import_file) . '\'';
if (isset($ldi_replace)) {
$sql .= ' REPLACE';
} elseif (isset($ldi_ignore)) {
$sql .= ' IGNORE';
}
$sql .= ' INTO TABLE ' . PMA_backquote($table);
if (strlen($ldi_terminated) > 0) {
$sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\''; $sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
} }
if (strlen($ldi_enclosed) > 0) { if (strlen($ldi_enclosed) > 0) {
$sql .= ' ENCLOSED BY \'' . PMA_sqlAddslashes($ldi_enclosed) . '\''; $sql .= ' ENCLOSED BY \'' . PMA_sqlAddslashes($ldi_enclosed) . '\'';
} }
if (strlen($ldi_escaped) > 0) { if (strlen($ldi_escaped) > 0) {
$sql .= ' ESCAPED BY \'' . PMA_sqlAddslashes($ldi_escaped) . '\''; $sql .= ' ESCAPED BY \'' . PMA_sqlAddslashes($ldi_escaped) . '\'';
} }
if (strlen($ldi_new_line) > 0){ if (strlen($ldi_new_line) > 0){
if ($ldi_new_line == 'auto') { if ($ldi_new_line == 'auto') {
$ldi_new_line = PMA_whichCrlf() == "\n" ? '\n' : '\r\n'; $ldi_new_line = PMA_whichCrlf() == "\n" ? '\n' : '\r\n';
} }
$sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\''; $sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
} }
if ($skip_queries > 0) { if ($skip_queries > 0) {
$sql .= ' IGNORE ' . $skip_queries . ' LINES'; $sql .= ' IGNORE ' . $skip_queries . ' LINES';
$skip_queries = 0; $skip_queries = 0;
} }
if (strlen($ldi_columns) > 0) { if (strlen($ldi_columns) > 0) {
$sql .= ' ('; $sql .= ' (';
$tmp = split(',( ?)', $ldi_columns); $tmp = split(',( ?)', $ldi_columns);
$cnt_tmp = count($tmp); $cnt_tmp = count($tmp);
@@ -95,13 +102,9 @@ if ($plugin_param == 'table') {
$sql .= PMA_backquote(trim($tmp[$i])); $sql .= PMA_backquote(trim($tmp[$i]));
} // end for } // end for
$sql .= ')'; $sql .= ')';
}
PMA_importRunQuery($sql, $sql);
PMA_importRunQuery();
$finished = TRUE;
}
}
} }
PMA_importRunQuery($sql, $sql);
PMA_importRunQuery();
$finished = TRUE;
?> ?>

View File

@@ -25,25 +25,28 @@ if (isset($plugin_list)) {
array('type' => 'select', 'name' => 'compatibility', 'text' => 'strSQLCompatibility', 'values' => $values, 'doc' => array('manual_MySQL_Database_Administration', 'Server_SQL_mode')) array('type' => 'select', 'name' => 'compatibility', 'text' => 'strSQLCompatibility', 'values' => $values, 'doc' => array('manual_MySQL_Database_Administration', 'Server_SQL_mode'))
); );
} }
} else {
/* We do not define function when plugin is just queried for information above */
$buffer = '';
// Defaults for parser
$sql = '';
$start_pos = 0;
$i = 0;
$len= 0;
if (isset($_POST['sql_delimiter'])) {
$sql_delimiter = $_POST['sql_delimiter'];
} else {
$sql_delimiter = ';';
}
// Handle compatibility option /* We do not define function when plugin is just queried for information above */
if (isset($_REQUEST['sql_compatibility'])) { return;
}
$buffer = '';
// Defaults for parser
$sql = '';
$start_pos = 0;
$i = 0;
$len= 0;
if (isset($_POST['sql_delimiter'])) {
$sql_delimiter = $_POST['sql_delimiter'];
} else {
$sql_delimiter = ';';
}
// Handle compatibility option
if (isset($_REQUEST['sql_compatibility'])) {
PMA_DBI_try_query('SET SQL_MODE="' . $_REQUEST['sql_compatibility'] . '"'); PMA_DBI_try_query('SET SQL_MODE="' . $_REQUEST['sql_compatibility'] . '"');
} }
while (!($finished && $i >= $len) && !$error && !$timeout_passed) { while (!($finished && $i >= $len) && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk(); $data = PMA_importGetNextChunk();
if ($data === FALSE) { if ($data === FALSE) {
// subtract data we didn't handle yet and stop processing // subtract data we didn't handle yet and stop processing
@@ -256,9 +259,8 @@ if (isset($plugin_list)) {
} }
} // End of parser loop } // End of parser loop
} // End of import loop } // End of import loop
// Commit any possible data in buffers // Commit any possible data in buffers
PMA_importRunQuery('', substr($buffer, 0, $len)); PMA_importRunQuery('', substr($buffer, 0, $len));
PMA_importRunQuery(); PMA_importRunQuery();
}
?> ?>