Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] SQL 解析的DbType 的语法集疑问 #6190

Open
spenxu opened this issue Oct 23, 2024 · 0 comments
Open

[BUG] SQL 解析的DbType 的语法集疑问 #6190

spenxu opened this issue Oct 23, 2024 · 0 comments

Comments

@spenxu
Copy link

spenxu commented Oct 23, 2024

SQLUtils.parseStatements(sql, "tidb")
使用Druid 解析, 测下来目前看起来mysql 语法集兼容性更大一些 ! 是不是不管什么数据库类型, 都可以无脑用mysql类型?
比如下面这个sql , 目标库是tidb ,但是用tidb 的类型去解析的话解析失败, 用mysql 类型解析则能正常解析

Druid Version

1.2.11

JDK Version

jdk8

Error SQL

select

    `id`, `msg_id`, `reconciliation_diff_id`, `bank`, `fund_type`, `batch_no`, `settle_serial`,
    `bank_repay_status`, `order_no`, `stage`, `standing_book_id`, `recon_date`, `settlement_date`,
    `settlement_type`, `self_amount`, `bank_amount`, `diff_amount`, `compensatory`, `settlement_label`, `result`,
    `process_status`, `edition`, `extra1`, `extra2`, `extra3`, `created_at`, `updated_at`
 
    from `reconciliation_diff_queue_msg`
    force index(idx_process_status)
    where `process_status` = ?
    and `id`   >   ?
     
     
        and settlement_type not in (0,7)
     
     
    and `fund_type` = ?
    and substr(order_no, -4, 4) between ? and ?
    order by `id` ASC
    limit ?

Testcase Code

 @Test
    public void testReplace2() {
      String sql = "select\n" +
              "         \n" +
              "        \n" +
              "        `id`, `msg_id`, `reconciliation_diff_id`, `bank`, `fund_type`, `batch_no`, `settle_serial`,\n" +
              "        `bank_repay_status`, `order_no`, `stage`, `standing_book_id`, `recon_date`, `settlement_date`,\n" +
              "        `settlement_type`, `self_amount`, `bank_amount`, `diff_amount`, `compensatory`, `settlement_label`, `result`,\n" +
              "        `process_status`, `edition`, `extra1`, `extra2`, `extra3`, `created_at`, `updated_at`\n" +
              "     \n" +
              "        from `reconciliation_diff_queue_msg`\n" +
              "        force index(idx_process_status)\n" +
              "        where `process_status` = ?\n" +
              "        and `id`   >   ?\n" +
              "         \n" +
              "         \n" +
              "            and settlement_type not in (0,7)\n" +
              "         \n" +
              "         \n" +
              "        and `fund_type` = ?\n" +
              "        and substr(order_no, -4, 4) between ? and ?\n" +
              "        order by `id` ASC\n" +
              "        limit ?";

//这里指定tidb 就解析失败, 指定mysql就可以
//看起来mysql 语法集兼容性更大一些,是不是不管什么数据库类型, 都可以无脑用mysql
        List<SQLStatement> sqlStatements = com.alibaba.druid.sql.SQLUtils.parseStatements(sql, "tidb");
        System.out.println(sqlStatements);

Stacktrace Info

No response

Error Info


com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'orce index(idx_process_status)
    ', expect INDEX, actual INDEX pos 511, line 10, column 15, token INDEX

	at com.alibaba.druid.sql.parser.SQLParser.printError(SQLParser.java:284)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:433)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:72)
	at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:464)
	at cn.caijiajia.dal.jdbc.core.datasource.collect.utils.SQLUtilsTest.testReplace2(SQLUtilsTest.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant