mysql2sqlite icon indicating copy to clipboard operation
mysql2sqlite copied to clipboard

Syntax error in output (missing backtick)

Open PetterS opened this issue 5 years ago • 5 comments

The following input (obtained with mysqldump --skip-extended-insert --compact):

/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mytablename` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `event_time` datetime(6) NOT NULL,
  `record_type` int(11) NOT NULL,
  `value_text` longtext,
  `value_numerical` double DEFAULT NULL,
  `value_enum` int(11) DEFAULT NULL,
  `created_at` datetime(6) NOT NULL,
  `medical_record_id` int(11) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;

Gives this output:

PRAGMA synchronous = OFF;
PRAGMA journal_mode = MEMORY;
BEGIN TRANSACTION;
CREATE TABLE `mytablename` (
  `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
,  `event_time` datetime(6) NOT NULL
,  `record_type` integer NOT NULL
,  `value_text` longtext
,  `value_numerical` double DEFAULT NULL
,  `value_text  DEFAULT NULL
,  `created_at` datetime(6) NOT NULL
,  `medical_record_id` integer NOT NULL
);
END TRANSACTION;

This is clearly a syntax error (missing backtick after value_text)

PetterS avatar May 04 '20 11:05 PetterS

Thanks for reporting! If you'll find some time, could you please try it with patch https://github.com/dumblob/mysql2sqlite/pull/71 ? The pull request changes some INT handling and I'd be interested whether the patch should be extended or not. Either way I think we could incorporate the input and output SQL code you provided as an additional unit test.

@vdechef thoughts?

(I hope I'll find some more time for mysql2sqlite few weeks later, but now I can only quickly comment with my ideas)

dumblob avatar May 04 '20 13:05 dumblob

@PetterS I think I saw something similar in previous issues : there is a bug with the way enums are handled. I should have fixed it in #71, so you should give it a try (beware to add --hex-blob option to mysqldump).

vdechef avatar May 04 '20 19:05 vdechef

I was able to work around my issue by changing one instance of int(11) to integer in the input. After that, I got output that sqlite accepted.

PetterS avatar May 05 '20 05:05 PetterS

Nice 👍 I confirm that your problem is due to the "enum" bug : your field named value_enum was parsed incorrectly by mysql2sqlite. So using #71 would solve it.
I added a unit test in PR #71 with your example.

vdechef avatar May 05 '20 07:05 vdechef

Cheers! 👍

PetterS avatar May 05 '20 08:05 PetterS