Bug #94719 "Error copying table data" on using "Import MySQL data" button
Submitted: 20 Mar 2019 13:23 Modified: 23 Mar 2019 2:09
Reporter: TEST TEST Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL for Windows: MySQL for Excel Severity:S2 (Serious)
Version:1.3.7 OS:Windows (8)
Assigned to: CPU Architecture:x86

[20 Mar 2019 13:23] TEST TEST
Description:
This bug is similar to the one described here https://forums.mysql.com/read.php?172,668243,668928#msg-668928 and may also be related to bugs #93051 and #80139.

When trying to use the "Import MySQL data", the function sometimes crashes with an alert "Error copying table data" with the below details:

Exception thrown by:
MySqlDataTable.CopyTableData

Stack trace:
   à System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   à System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   à System.String.System.IConvertible.ToInt32(IFormatProvider provider)
   à System.Data.Common.Int32Storage.Set(Int32 record, Object value)
   à System.Data.DataColumn.set_Item(Int32 record, Object value)

This seems to be caused by the script switching column order while trying to import the table, if columns have a different type and are not created in the alphabetical order. This can be reproduced by creating a test database (below) and trying to import it into Excel.

How to repeat:
' Copy-paste the below script and try to import the table "foo" into Excel
' using the Import MySQL data button
'
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' WARNING : WILL DELETE TABLE "FOO" IN DATABASE "TEST" IF SUCH
' A DATABASE ALREADY EXISTS
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CREATE DATABASE  IF NOT EXISTS `test` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */;
USE `test`;
-- MySQL dump 10.13  Distrib 8.0.15, for Win64 (x86_64)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version	8.0.15

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
 SET NAMES utf8 ;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `foo`
--

DROP TABLE IF EXISTS `foo`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
 SET character_set_client = utf8mb4 ;
CREATE TABLE `foo` (
  `b` int(11) NOT NULL,
  `a` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `foo`
--

LOCK TABLES `foo` WRITE;
/*!40000 ALTER TABLE `foo` DISABLE KEYS */;
INSERT INTO `foo` VALUES (1,'somestring');
/*!40000 ALTER TABLE `foo` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2019-03-20 14:17:30
[20 Mar 2019 13:28] TEST TEST
in "how to repeat" section: the script is meant to be executed by mysql so as to set up the test environment, not by Excel, of course.
[20 Mar 2019 21:30] MySQL Verification Team
Thank you for the bug report.
[23 Mar 2019 2:09] Javier Treviño
This is a duplicate of bug http://bugs.mysql.com/bug.php?id=93501 already being worked on.