bgranvea / mysql2h2-converter Goto Github PK
View Code? Open in Web Editor NEWA MySQL to H2 SQL conversion library written in Java
License: MIT License
A MySQL to H2 SQL conversion library written in Java
License: MIT License
Really like your tool, saved me a lot of time.
Lines like this seem to not work:
SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
SET @@SESSION.SQL_LOG_BIN= 0;
SET @@GLOBAL.GTID_PURGED='0f1f94eb-5891-11e5-8f0e-005056992d4d:1-730085,
500ab157-5894-11e5-8f23-00505685788b:1-12738';
SET @@SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;
This is the Start of my file:
-- MySQL dump 10.13 Distrib 5.6.27, for Linux (x86_64)
--
-- Host: localhost Database: xxx
-- ------------------------------------------------------
-- Server version 5.6.27-log
/*!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 */;
/*!40101 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 */;
SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
SET @@SESSION.SQL_LOG_BIN= 0;
--
-- GTID state at the beginning of the backup
--
SET @@GLOBAL.GTID_PURGED='0f1f94eb-5891-11e5-8f0e-005056992d4d:1-730085,
500ab157-5894-11e5-8f23-00505685788b:1-12738';
And this the error:
Exception in thread "main" com.granveaud.mysql2h2converter.parser.TokenMgrError: Lexical error at line 17, column 5. Encountered: "@" (64), after : ""
at com.granveaud.mysql2h2converter.parser.SQLParserTokenManager.getNextToken(SQLParserTokenManager.java:1806)
at com.granveaud.mysql2h2converter.parser.SQLParser.jj_ntk(SQLParser.java:3058)
at com.granveaud.mysql2h2converter.parser.SQLParser.DbObjectName(SQLParser.java:1922)
at com.granveaud.mysql2h2converter.parser.SQLParser.Assignment(SQLParser.java:1969)
at com.granveaud.mysql2h2converter.parser.SQLParser.SetVariableStatement(SQLParser.java:137)
at com.granveaud.mysql2h2converter.parser.SQLParser.Statement(SQLParser.java:100)
at com.granveaud.mysql2h2converter.parser.SQLParser.ScriptStatement(SQLParser.java:76)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.parseNextStatement(SQLParserManager.java:23)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.next(SQLParserManager.java:37)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.next(SQLParserManager.java:12)
at com.granveaud.mysql2h2converter.converter.H2Converter$ConverterIterator.loadNextStatements(H2Converter.java:28)
at com.granveaud.mysql2h2converter.converter.H2Converter$ConverterIterator.<init>(H2Converter.java:23)
at com.granveaud.mysql2h2converter.converter.H2Converter.convertScript(H2Converter.java:221)
at com.granveaud.mysql2h2converter.converter.Main.main(Main.java:28)
in sqlgrammar.jj I was this piece of code
`
PARSER_BEGIN(SQLParser)
package com.granveaud.mysql2h2converter.parser;
import java.util.;
import java.io.;
import com.granveaud.mysql2h2converter.sql.*;
public class SQLParser {
}
PARSER_END(SQLParser)
`
but there isn't any SQLParser.java. And also ParseException class is missing. What jdk should I use for the project ? 1.6 ?
subj
If you you use something like UNIQUE KEY
user_email.email (
gf_user_id,
email)
for instance then the parser causes the following error:
com.granveaud.mysql2h2converter.parser.TokenMgrError: Lexical error at line 14, column 25. Encountered: "." (46), after : "`user_email"
at com.granveaud.mysql2h2converter.parser.SQLParserTokenManager.getNextToken(SQLParserTokenManager.java:1806)
at com.granveaud.mysql2h2converter.parser.SQLParser.jj_ntk(SQLParser.java:3085)
at com.granveaud.mysql2h2converter.parser.SQLParser.ColumnConstraint(SQLParser.java:1550)
at com.granveaud.mysql2h2converter.parser.SQLParser.CreateTableDefinition(SQLParser.java:569)
at com.granveaud.mysql2h2converter.parser.SQLParser.CreateTableStatement(SQLParser.java:421)
at com.granveaud.mysql2h2converter.parser.SQLParser.CreateStatement(SQLParser.java:359)
at com.granveaud.mysql2h2converter.parser.SQLParser.Statement(SQLParser.java:103)
at com.granveaud.mysql2h2converter.parser.SQLParser.ScriptStatement(SQLParser.java:76)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.parseNextStatement(SQLParserManager.java:23)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.next(SQLParserManager.java:37)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.next(SQLParserManager.java:12)
at com.granveaud.mysql2h2converter.converter.H2Converter$ConverterIterator.loadNextStatements(H2Converter.java:28)
at com.granveaud.mysql2h2converter.converter.H2Converter$ConverterIterator.<init>(H2Converter.java:23)
at com.granveaud.mysql2h2converter.converter.H2Converter.convertScript(H2Converter.java:221)
at com.granveaud.mysql2h2converter.converter.ConverterTest.executeScript(ConverterTest.java:86)
at com.granveaud.mysql2h2converter.converter.ConverterTest.loadScript(ConverterTest.java:148)
at com.granveaud.mysql2h2converter.converter.ConverterTest.testScript6(ConverterTest.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
I've been trying to debug it, but its quite difficult to figure out what's going on, if you can point me in the right direction i can help you fix it
If you have a clause like CONSTRAINT
user_email_user_id_key FOREIGN KEY (
user_id) REFERENCES
user (
id) ON UPDATE NO ACTION ON DELETE CASCADE
it causes the following error:
java.lang.IllegalArgumentException: Cannot parse next statement
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.parseNextStatement(SQLParserManager.java:25)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.next(SQLParserManager.java:37)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.next(SQLParserManager.java:12)
at com.granveaud.mysql2h2converter.converter.H2Converter$ConverterIterator.loadNextStatements(H2Converter.java:28)
at com.granveaud.mysql2h2converter.converter.H2Converter$ConverterIterator.<init>(H2Converter.java:23)
at com.granveaud.mysql2h2converter.converter.H2Converter.convertScript(H2Converter.java:221)
at com.granveaud.mysql2h2converter.converter.ConverterTest.executeScript(ConverterTest.java:86)
at com.granveaud.mysql2h2converter.converter.ConverterTest.loadScript(ConverterTest.java:148)
at com.granveaud.mysql2h2converter.converter.ConverterTest.testScript6(ConverterTest.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: com.granveaud.mysql2h2converter.parser.ParseException: Encountered " "ON" "ON "" at line 17, column 108.
Was expecting one of:
")" ...
"," ...
at com.granveaud.mysql2h2converter.parser.SQLParser.generateParseException(SQLParser.java:3161)
at com.granveaud.mysql2h2converter.parser.SQLParser.jj_consume_token(SQLParser.java:3037)
at com.granveaud.mysql2h2converter.parser.SQLParser.CreateTableDefinition(SQLParser.java:579)
at com.granveaud.mysql2h2converter.parser.SQLParser.CreateTableStatement(SQLParser.java:421)
at com.granveaud.mysql2h2converter.parser.SQLParser.CreateStatement(SQLParser.java:359)
at com.granveaud.mysql2h2converter.parser.SQLParser.Statement(SQLParser.java:103)
at com.granveaud.mysql2h2converter.parser.SQLParser.ScriptStatement(SQLParser.java:76)
at com.granveaud.mysql2h2converter.parser.SQLParserManager$ScriptIterator.parseNextStatement(SQLParserManager.java:23)
... 37 more
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.