From 06655bf45da2993967a4a9544727e7fe7114f177 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Wed, 17 Apr 2013 23:25:16 +0530 Subject: [PATCH 1/5] Fix bug #3879 Import broken for CSV using LOAD DATA --- import.php | 5 +++-- libraries/plugins/import/ImportLdi.class.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/import.php b/import.php index 2a4f4e15e7..9138d6ee40 100644 --- a/import.php +++ b/import.php @@ -77,7 +77,7 @@ if (! empty($sql_query)) { $ajax_reload['table_name'] = PMA_Util::unQuote($rename_table_names[2]); $ajax_reload['reload'] = true; } - + $sql_query = ''; } elseif (! empty($sql_localfile)) { // run SQL file on server @@ -474,7 +474,8 @@ if (! $error) { $import_plugin = PMA_getPlugin( "import", $format, - 'libraries/plugins/import/' + 'libraries/plugins/import/', + $import_type ); if ($import_plugin == null) { $error = true; diff --git a/libraries/plugins/import/ImportLdi.class.php b/libraries/plugins/import/ImportLdi.class.php index b38e74b052..50fd525b76 100644 --- a/libraries/plugins/import/ImportLdi.class.php +++ b/libraries/plugins/import/ImportLdi.class.php @@ -112,7 +112,7 @@ class ImportLdi extends ImportPlugin */ public function doImport() { - global $finished, $error, $import_file, $compression, $charset_conversion; + global $finished, $error, $import_file, $compression, $charset_conversion, $table; global $ldi_local_option, $ldi_replace, $ldi_terminated, $ldi_enclosed, $ldi_escaped, $ldi_new_line, $skip_queries, $ldi_columns; From 4477494216cce361986d47ce5bdc677752fd9b56 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Wed, 17 Apr 2013 23:25:53 +0530 Subject: [PATCH 2/5] Importing CSV was also broken --- libraries/plugins/import/ImportCsv.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/plugins/import/ImportCsv.class.php b/libraries/plugins/import/ImportCsv.class.php index 7cfa292c11..bdb29f5c0c 100644 --- a/libraries/plugins/import/ImportCsv.class.php +++ b/libraries/plugins/import/ImportCsv.class.php @@ -158,7 +158,7 @@ class ImportCsv extends ImportPlugin */ public function doImport() { - global $db, $csv_terminated, $csv_enclosed, $csv_escaped, $csv_new_line; + global $db, $table, $csv_terminated, $csv_enclosed, $csv_escaped, $csv_new_line; global $error, $timeout_passed, $finished; $replacements = array( From 175cb7b0ae15ebe97e8dbc89784e0d6dd1c72d53 Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Thu, 18 Apr 2013 22:44:49 +0530 Subject: [PATCH 3/5] Fix format specific options that were missing from ImportLdi plugin. Common code pulled out to AbstractImportCsv.class.php. --- .../import/AbstractImportCsv.class.php | 67 +++++++++++++++++++ libraries/plugins/import/ImportCsv.class.php | 33 +-------- libraries/plugins/import/ImportLdi.class.php | 22 ++++-- 3 files changed, 87 insertions(+), 35 deletions(-) create mode 100644 libraries/plugins/import/AbstractImportCsv.class.php diff --git a/libraries/plugins/import/AbstractImportCsv.class.php b/libraries/plugins/import/AbstractImportCsv.class.php new file mode 100644 index 0000000000..35277d8d79 --- /dev/null +++ b/libraries/plugins/import/AbstractImportCsv.class.php @@ -0,0 +1,67 @@ +setName("replace"); + $leaf->setText(__('Replace table data with file')); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("terminated"); + $leaf->setText(__('Columns separated with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("enclosed"); + $leaf->setText(__('Columns enclosed with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("escaped"); + $leaf->setText(__('Columns escaped with:')); + $leaf->setSize(2); + $leaf->setLen(2); + $generalOptions->addProperty($leaf); + $leaf = new TextPropertyItem(); + $leaf->setName("new_line"); + $leaf->setText(__('Lines terminated with:')); + $leaf->setSize(2); + $generalOptions->addProperty($leaf); + + return $generalOptions; + } +} +?> \ No newline at end of file diff --git a/libraries/plugins/import/ImportCsv.class.php b/libraries/plugins/import/ImportCsv.class.php index bdb29f5c0c..cad1cfb0d9 100644 --- a/libraries/plugins/import/ImportCsv.class.php +++ b/libraries/plugins/import/ImportCsv.class.php @@ -12,7 +12,7 @@ if (! defined('PHPMYADMIN')) { } /* Get the import interface */ -require_once 'libraries/plugins/ImportPlugin.class.php'; +require_once 'libraries/plugins/import/AbstractImportCsv.class.php'; /** * Handles the import for the CSV format @@ -20,7 +20,7 @@ require_once 'libraries/plugins/ImportPlugin.class.php'; * @package PhpMyAdmin-Import * @subpackage CSV */ -class ImportCsv extends ImportPlugin +class ImportCsv extends AbstractImportCsv { /** * Whether to analyze tables @@ -72,34 +72,7 @@ class ImportCsv extends ImportPlugin // general options main group $generalOptions = new OptionsPropertyMainGroup(); $generalOptions->setName("general_opts"); - // create primary items and add them to the group - $leaf = new BoolPropertyItem(); - $leaf->setName("replace"); - $leaf->setText(__('Replace table data with file')); - $generalOptions->addProperty($leaf); - $leaf = new TextPropertyItem(); - $leaf->setName("terminated"); - $leaf->setText(__('Columns separated with:')); - $leaf->setSize(2); - $leaf->setLen(2); - $generalOptions->addProperty($leaf); - $leaf = new TextPropertyItem(); - $leaf->setName("enclosed"); - $leaf->setText(__('Columns enclosed with:')); - $leaf->setSize(2); - $leaf->setLen(2); - $generalOptions->addProperty($leaf); - $leaf = new TextPropertyItem(); - $leaf->setName("escaped"); - $leaf->setText(__('Columns escaped with:')); - $leaf->setSize(2); - $leaf->setLen(2); - $generalOptions->addProperty($leaf); - $leaf = new TextPropertyItem(); - $leaf->setName("new_line"); - $leaf->setText(__('Lines terminated with:')); - $leaf->setSize(2); - $generalOptions->addProperty($leaf); + $generalOptions = $this->populateCommonOptions($generalOptions); if ($GLOBALS['plugin_param'] !== 'table') { $leaf = new BoolPropertyItem(); diff --git a/libraries/plugins/import/ImportLdi.class.php b/libraries/plugins/import/ImportLdi.class.php index 50fd525b76..dc2bfe8ead 100644 --- a/libraries/plugins/import/ImportLdi.class.php +++ b/libraries/plugins/import/ImportLdi.class.php @@ -11,7 +11,7 @@ if (! defined('PHPMYADMIN')) { } /* Get the import interface */ -require_once 'libraries/plugins/ImportPlugin.class.php'; +require_once 'libraries/plugins/import/AbstractImportCsv.class.php'; // We need relations enabled and we work only on database if ($GLOBALS['plugin_param'] !== 'table') { @@ -25,7 +25,7 @@ if ($GLOBALS['plugin_param'] !== 'table') { * @package PhpMyAdmin-Import * @subpackage LDI */ -class ImportLdi extends ImportPlugin +class ImportLdi extends AbstractImportCsv { /** * Constructor @@ -78,10 +78,22 @@ class ImportLdi extends ImportPlugin // general options main group $generalOptions = new OptionsPropertyMainGroup(); $generalOptions->setName("general_opts"); - // create primary items and add them to the group + $leaf = new BoolPropertyItem(); - $leaf->setName("replace"); - $leaf->setText(__('Replace table data with file')); + $leaf->setName("ignore"); + $leaf->setText(__('Do not abort on INSERT error')); + $generalOptions->addProperty($leaf); + + $generalOptions = $this->populateCommonOptions($generalOptions); + + $leaf = new TextPropertyItem(); + $leaf->setName("columns"); + $leaf->setText(__('Column names: ')); + $generalOptions->addProperty($leaf); + + $leaf = new BoolPropertyItem(); + $leaf->setName("local_option"); + $leaf->setText(__('Use LOCAL keyword')); $generalOptions->addProperty($leaf); // add the main group to the root group From edbe925d8a317a60155aa20edadf988f679ce41e Mon Sep 17 00:00:00 2001 From: Kasun Chathuranga Date: Fri, 19 Apr 2013 23:00:22 +0530 Subject: [PATCH 4/5] Minimize code duplication by pushing most of the common code to abstract parent class's setProperties() method --- .../import/AbstractImportCsv.class.php | 38 +++++++++++++--- libraries/plugins/import/ImportCsv.class.php | 32 ++------------ libraries/plugins/import/ImportLdi.class.php | 43 ++++--------------- 3 files changed, 42 insertions(+), 71 deletions(-) diff --git a/libraries/plugins/import/AbstractImportCsv.class.php b/libraries/plugins/import/AbstractImportCsv.class.php index 35277d8d79..62ca8bb541 100644 --- a/libraries/plugins/import/AbstractImportCsv.class.php +++ b/libraries/plugins/import/AbstractImportCsv.class.php @@ -22,16 +22,33 @@ require_once 'libraries/plugins/ImportPlugin.class.php'; abstract class AbstractImportCsv extends ImportPlugin { /** - * Populates the passed OptionsPropertyMainGroup object with options common to - * CSV type imports. + * Sets the import plugin properties. + * Called in the constructor. * - * @param object $generalOptions main group of format specific options - * - * @return object main group of format specific options populated - * with common options + * @return object OptionsPropertyMainGroup object of the plugin */ - protected function populateCommonOptions($generalOptions) + protected function setProperties() { + $props = 'libraries/properties/'; + include_once "$props/plugins/ImportPluginProperties.class.php"; + include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; + include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; + include_once "$props/options/items/BoolPropertyItem.class.php"; + include_once "$props/options/items/TextPropertyItem.class.php"; + + $importPluginProperties = new ImportPluginProperties(); + $importPluginProperties->setOptionsText(__('Options')); + + // create the root group that will be the options field for + // $importPluginProperties + // this will be shown as "Format specific options" + $importSpecificOptions = new OptionsPropertyRootGroup(); + $importSpecificOptions->setName("Format Specific Options"); + + // general options main group + $generalOptions = new OptionsPropertyMainGroup(); + $generalOptions->setName("general_opts"); + // create common items and add them to the group $leaf = new BoolPropertyItem(); $leaf->setName("replace"); @@ -61,6 +78,13 @@ abstract class AbstractImportCsv extends ImportPlugin $leaf->setSize(2); $generalOptions->addProperty($leaf); + // add the main group to the root group + $importSpecificOptions->addProperty($generalOptions); + + // set the options for the import plugin property item + $importPluginProperties->setOptions($importSpecificOptions); + $this->properties = $importPluginProperties; + return $generalOptions; } } diff --git a/libraries/plugins/import/ImportCsv.class.php b/libraries/plugins/import/ImportCsv.class.php index cad1cfb0d9..6d065a4697 100644 --- a/libraries/plugins/import/ImportCsv.class.php +++ b/libraries/plugins/import/ImportCsv.class.php @@ -51,28 +51,9 @@ class ImportCsv extends AbstractImportCsv $this->_setAnalyze(true); } - $props = 'libraries/properties/'; - include_once "$props/plugins/ImportPluginProperties.class.php"; - include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; - include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; - include_once "$props/options/items/BoolPropertyItem.class.php"; - include_once "$props/options/items/TextPropertyItem.class.php"; - - $importPluginProperties = new ImportPluginProperties(); - $importPluginProperties->setText('CSV'); - $importPluginProperties->setExtension('csv'); - $importPluginProperties->setOptionsText(__('Options')); - - // create the root group that will be the options field for - // $importPluginProperties - // this will be shown as "Format specific options" - $importSpecificOptions = new OptionsPropertyRootGroup(); - $importSpecificOptions->setName("Format Specific Options"); - - // general options main group - $generalOptions = new OptionsPropertyMainGroup(); - $generalOptions->setName("general_opts"); - $generalOptions = $this->populateCommonOptions($generalOptions); + $generalOptions = parent::setProperties(); + $this->properties->setText('CSV'); + $this->properties->setExtension('csv'); if ($GLOBALS['plugin_param'] !== 'table') { $leaf = new BoolPropertyItem(); @@ -102,13 +83,6 @@ class ImportCsv extends AbstractImportCsv ); $generalOptions->addProperty($leaf); } - - // add the main group to the root group - $importSpecificOptions->addProperty($generalOptions); - - // set the options for the import plugin property item - $importPluginProperties->setOptions($importSpecificOptions); - $this->properties = $importPluginProperties; } /** diff --git a/libraries/plugins/import/ImportLdi.class.php b/libraries/plugins/import/ImportLdi.class.php index dc2bfe8ead..8d375e63ac 100644 --- a/libraries/plugins/import/ImportLdi.class.php +++ b/libraries/plugins/import/ImportLdi.class.php @@ -57,51 +57,24 @@ class ImportLdi extends AbstractImportCsv unset($result); } - $props = 'libraries/properties/'; - include_once "$props/plugins/ImportPluginProperties.class.php"; - include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; - include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; - include_once "$props/options/items/BoolPropertyItem.class.php"; - include_once "$props/options/items/TextPropertyItem.class.php"; - - $importPluginProperties = new ImportPluginProperties(); - $importPluginProperties->setText('CSV using LOAD DATA'); - $importPluginProperties->setExtension('ldi'); - $importPluginProperties->setOptionsText(__('Options')); - - // create the root group that will be the options field for - // $importPluginProperties - // this will be shown as "Format specific options" - $importSpecificOptions = new OptionsPropertyRootGroup(); - $importSpecificOptions->setName("Format Specific Options"); - - // general options main group - $generalOptions = new OptionsPropertyMainGroup(); - $generalOptions->setName("general_opts"); - - $leaf = new BoolPropertyItem(); - $leaf->setName("ignore"); - $leaf->setText(__('Do not abort on INSERT error')); - $generalOptions->addProperty($leaf); - - $generalOptions = $this->populateCommonOptions($generalOptions); + $generalOptions = parent::setProperties(); + $this->properties->setText('CSV using LOAD DATA'); + $this->properties->setExtension('ldi'); $leaf = new TextPropertyItem(); $leaf->setName("columns"); $leaf->setText(__('Column names: ')); $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); + $leaf->setName("ignore"); + $leaf->setText(__('Do not abort on INSERT error')); + $generalOptions->addProperty($leaf); + $leaf = new BoolPropertyItem(); $leaf->setName("local_option"); $leaf->setText(__('Use LOCAL keyword')); $generalOptions->addProperty($leaf); - - // add the main group to the root group - $importSpecificOptions->addProperty($generalOptions); - - // set the options for the import plugin property item - $importPluginProperties->setOptions($importSpecificOptions); - $this->properties = $importPluginProperties; } /** From 79df30b3277c5bc6c43296071651fe3968abaf45 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Thu, 25 Apr 2013 20:49:47 +0530 Subject: [PATCH 5/5] Change log entry for bug fix for #3879 --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 62d8431b7a..3f1e58dc4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ phpMyAdmin - ChangeLog ====================== 4.0.1.0 (not yet released) +- bug #3879 Import broken for CSV using LOAD DATA 4.0.0.0 (not yet released) + Patch #3481047 for rfe #3480477 Insert as new row enhancement