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

View File

@@ -6,11 +6,17 @@
* @version $Id$
*/
$cfgRelation = PMA_getRelationsParam();
/**
* 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 (isset($plugin_list)) {
if ($plugin_param !== 'database' || $GLOBALS['num_tables'] < 1
|| ! $cfgRelation['relwork'] || ! $cfgRelation['commwork']) {
return;
}
if (isset($plugin_list)) {
$plugin_list['docsql'] = array( // set name of your plugin
'text' => 'strDocSQL', // text to be displayed as choice
'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)
);
} else {
/* We do not define function when plugin is just queried for information above */
$tab = $_POST['docsql_table'];
$buffer = '';
/* Read whole buffer, we except it is small enough */
while (!$finished && !$error && !$timeout_passed) {
return;
}
$tab = $_POST['docsql_table'];
$buffer = '';
/* Read whole buffer, we except it is small enough */
while (!$finished && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk();
if ($data === FALSE) {
// 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
$buffer .= $data;
}
} // End of import loop
/* Process the data */
if ($data === TRUE && !$error && !$timeout_passed) {
} // End of import loop
/* Process the data */
if ($data === TRUE && !$error && !$timeout_passed) {
$buffer = str_replace("\r\n", "\n", $buffer);
$buffer = str_replace("\r", "\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) {
$qry = '
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') . ' )
VALUES (
\'' . PMA_sqlAddslashes($GLOBALS['db']) . '\',
@@ -61,7 +69,7 @@ if ($plugin_param == 'database' && $GLOBALS['num_tables'] > 0 && $GLOBALS['cfgRe
$for = explode('->', $inf[2]);
$qry = '
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)
VALUES (
\'' . 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);
} // end inf[2] exists
} // End lines loop
} // End import
// Commit any possible data in buffers
PMA_importRunQuery();
}
}
} // End import
// Commit any possible data in buffers
PMA_importRunQuery();
?>

View File

@@ -9,8 +9,11 @@
/**
*
*/
if ($plugin_param == 'table') {
if (isset($plugin_list)) {
if ($plugin_param !== 'table') {
return;
}
if (isset($plugin_list)) {
if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') {
$GLOBALS['cfg']['Import']['ldi_local_option'] = FALSE;
@@ -45,46 +48,50 @@ if ($plugin_param == 'table') {
),
'options_text' => 'strLDIImportOptions',
);
} else {
/* 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!
$message = $strInvalidLDIImport;
$show_error_header = TRUE;
$error = TRUE;
} else {
$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);
return;
}
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 . '\'';
}
if (strlen($ldi_enclosed) > 0) {
}
if (strlen($ldi_enclosed) > 0) {
$sql .= ' ENCLOSED BY \'' . PMA_sqlAddslashes($ldi_enclosed) . '\'';
}
if (strlen($ldi_escaped) > 0) {
}
if (strlen($ldi_escaped) > 0) {
$sql .= ' ESCAPED BY \'' . PMA_sqlAddslashes($ldi_escaped) . '\'';
}
if (strlen($ldi_new_line) > 0){
}
if (strlen($ldi_new_line) > 0){
if ($ldi_new_line == 'auto') {
$ldi_new_line = PMA_whichCrlf() == "\n" ? '\n' : '\r\n';
}
$sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
}
if ($skip_queries > 0) {
}
if ($skip_queries > 0) {
$sql .= ' IGNORE ' . $skip_queries . ' LINES';
$skip_queries = 0;
}
if (strlen($ldi_columns) > 0) {
}
if (strlen($ldi_columns) > 0) {
$sql .= ' (';
$tmp = split(',( ?)', $ldi_columns);
$cnt_tmp = count($tmp);
@@ -95,13 +102,9 @@ if ($plugin_param == 'table') {
$sql .= PMA_backquote(trim($tmp[$i]));
} // end for
$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'))
);
}
} 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
if (isset($_REQUEST['sql_compatibility'])) {
/* We do not define function when plugin is just queried for information above */
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'] . '"');
}
while (!($finished && $i >= $len) && !$error && !$timeout_passed) {
}
while (!($finished && $i >= $len) && !$error && !$timeout_passed) {
$data = PMA_importGetNextChunk();
if ($data === FALSE) {
// subtract data we didn't handle yet and stop processing
@@ -256,9 +259,8 @@ if (isset($plugin_list)) {
}
} // End of parser loop
} // End of import loop
// Commit any possible data in buffers
PMA_importRunQuery('', substr($buffer, 0, $len));
PMA_importRunQuery();
}
} // End of import loop
// Commit any possible data in buffers
PMA_importRunQuery('', substr($buffer, 0, $len));
PMA_importRunQuery();
?>