lealone / Lealone

比 MySQL 和 MongoDB 快10倍的 OLTP 关系数据库和文档数据库
Other
2.48k stars 519 forks source link

创建mysql数据库报错 #206

Closed J1031 closed 1 year ago

J1031 commented 1 year ago

测试代码如下

    @Test
    public void createDatabase() throws Throwable {
        try {
            Statement statement = conn.createStatement();
            statement.executeUpdate("drop table if exists mysqldbtest");
            statement.executeUpdate("create database `mysqldbtest` default character set utf8mb4 collate utf8mb4_general_ci");
        } catch (SQLException e) {
            sqlException(e);
            throw e;
        } catch (Throwable t) {
            throw t;
        }
    }

服务端抛的异常

ERROR 08:55:48.942 Failed to prepare statement: create database `mysqldbtest` default character set utf8mb4 collate utf8mb4_general_ci
org.lealone.common.exceptions.JdbcSQLException: Syntax error in SQL statement "CREATE DATABASE ""MYSQLDBTEST"" DEFAULT[*] CHARACTER SET UTF8MB4 COLLATE UTF8MB4_GENERAL_CI "; SQL statement:
create database `mysqldbtest` default character set utf8mb4 collate utf8mb4_general_ci [42000-0]
    at org.lealone.common.exceptions.DbException.getJdbcSQLException(DbException.java:342) ~[classes/:?]
    at org.lealone.common.exceptions.DbException.get(DbException.java:173) ~[classes/:?]
    at org.lealone.common.exceptions.DbException.get(DbException.java:150) ~[classes/:?]
    at org.lealone.common.exceptions.DbException.getSyntaxError(DbException.java:185) ~[classes/:?]
    at org.lealone.sql.SQLParserBase.getSyntaxError(SQLParserBase.java:538) ~[classes/:?]
    at org.lealone.sql.SQLParserBase.parse(SQLParserBase.java:300) ~[classes/:?]
    at org.lealone.sql.SQLParserBase.parse(SQLParserBase.java:181) ~[classes/:?]
    at org.lealone.db.session.ServerSession.prepareStatement(ServerSession.java:475) ~[classes/:?]
    at org.lealone.plugins.mysql.server.MySQLServerConnection.prepareStatement(MySQLServerConnection.java:188) [classes/:?]
    at org.lealone.plugins.mysql.server.MySQLServerConnection.executeStatement(MySQLServerConnection.java:208) [classes/:?]
    at org.lealone.plugins.mysql.server.handler.CommandPacketHandler.handle(CommandPacketHandler.java:37) [classes/:?]
    at org.lealone.plugins.mysql.server.MySQLServerConnection.handle(MySQLServerConnection.java:391) [classes/:?]
    at org.lealone.net.nio.NioEventLoop.read(NioEventLoop.java:258) [classes/:?]
    at org.lealone.net.nio.NioEventLoop.handleSelectedKeys(NioEventLoop.java:475) [classes/:?]
    at org.lealone.server.Scheduler.runEventLoop(Scheduler.java:504) [classes/:?]
    at org.lealone.server.Scheduler.run(Scheduler.java:135) [classes/:?]

客户端抛的异常

SQLException:java.sql.SQLException: Syntax error in SQL statement "CREATE DATABASE ""MYSQLDBTEST"" DEFAULT[*] CHARACTER SET UTF8MB4 COLLATE UTF8MB4_GENERAL_CI " [42000-0]
-----------------------------------
Message  : Syntax error in SQL statement "CREATE DATABASE ""MYSQLDBTEST"" DEFAULT[*] CHARACTER SET UTF8MB4 COLLATE UTF8MB4_GENERAL_CI " [42000-0]
SQLState : HY000
ErrorCode: 42000

java.sql.SQLException: Syntax error in SQL statement "CREATE DATABASE ""MYSQLDBTEST"" DEFAULT[*] CHARACTER SET UTF8MB4 COLLATE UTF8MB4_GENERAL_CI " [42000-0]

    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1335)
    at com.mysql.cj.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2084)
    at com.mysql.cj.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1246)
    at org.lealone.test.plugins.mysql.MySQLJdbcTest.createDatabase(MySQLJdbcTest.java:53)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
codefollower commented 1 year ago

这个语法还没实现,接下来会做

codefollower commented 1 year ago

已经实现 create/alter database 语句