druid PostgreSQL 中 对 “CREATE TYPE ” 解析报错

bd1hkmkf  于 5个月前  发布在  Druid
关注(0)|答案(1)|浏览(60)

druid 1.1.10

  1. java.sql.SQLException: sql injection violation, syntax error: TODO TYPE : CREATE TYPE CACHE_COMMON_TYPE_ENUM_ AS ENUM('EHCACHE', 'REDIS', 'NONE')
  2. at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:798)
  3. at com.alibaba.druid.wall.WallFilter.check(WallFilter.java:780)
  4. at com.alibaba.druid.wall.WallFilter.statement_executeUpdate(WallFilter.java:542)
  5. at com.alibaba.druid.filter.FilterChainImpl.statement_executeUpdate(FilterChainImpl.java:2844)
  6. at com.alibaba.druid.filter.FilterAdapter.statement_executeUpdate(FilterAdapter.java:2508)
  7. at com.alibaba.druid.filter.FilterEventAdapter.statement_executeUpdate(FilterEventAdapter.java:327)
  8. at com.alibaba.druid.filter.FilterChainImpl.statement_executeUpdate(FilterChainImpl.java:2844)
  9. at com.alibaba.druid.filter.FilterAdapter.statement_executeUpdate(FilterAdapter.java:2508)
  10. at com.alibaba.druid.filter.FilterChainImpl.statement_executeUpdate(FilterChainImpl.java:2844)
  11. at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeUpdate(StatementProxyImpl.java:235)
  12. at com.alibaba.druid.pool.DruidPooledStatement.executeUpdate(DruidPooledStatement.java:319)
  13. at com.weaver.emobile.core.config.DatabaseUpgradeConfig.init(DatabaseUpgradeConfig.java:275)
  14. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  15. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  16. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  17. at java.lang.reflect.Method.invoke(Method.java:498)
  18. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363)
  19. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307)
  20. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
  21. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:419)
  22. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1737)
  23. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
  24. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
  25. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
  26. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
  27. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
  28. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
  29. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
  30. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
  31. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
  32. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
  33. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
  34. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
  35. at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
  36. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
  37. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
  38. at com.weaver.emobile.WebApplication.main(WebApplication.java:35)
  39. Caused by: com.alibaba.druid.sql.parser.ParserException: TODO TYPE
  40. at com.alibaba.druid.sql.parser.SQLStatementParser.parseCreate(SQLStatementParser.java:2142)
  41. at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:161)
  42. at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:83)
  43. at com.alibaba.druid.wall.WallProvider.checkInternal(WallProvider.java:624)
  44. at com.alibaba.druid.wall.WallProvider.check(WallProvider.java:578)
  45. at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:785)
  46. ... 36 common frames omitted
bvuwiixz

bvuwiixz1#

我用下面代码处理,仅供参考

  1. private def stripUnsurpported(sql: String): String =
  2. sql
  3. .replaceAll("\\b(DEFAULT|default)\\b.+?(?=,|\\n|not|NOT)", "")
  4. .replaceAll("CREATE SCHEMA.+?;", "")
  5. .replaceAll("CREATE SEQUENCE(.|\\n)+?;", "")
  6. .replaceAll("CREATE TYPE(.|\\n)+?;", "")
  7. .replaceAll("NOT DEFERRABLE", "")
  8. .replaceAll("INITIALLY IMMEDIATE", "")
  9. .replaceAll("CREATE (UNIQUE)? INDEX(.|\\n)+?;", "")
  10. private def extractEnums(sql: String): List[TyEnum] = {
  11. new Regex("(CREATE|create)\\s+(TYPE|type)\\s+(.+)\\s+(AS|as)\\s+(ENUM|enum)\\s*\\((.+?)\\);")
  12. .findAllMatchIn(sql)
  13. .map(m => m.group(3) -> m.group(6))
  14. .map { (k, v) =>
  15. k -> v
  16. .split(",")
  17. .map(StringUtils.strip(_, " '"))
  18. .map(variantName => TyVariant(List(variantName), None, Some(variantName)))
  19. }
  20. .map {
  21. case (s"$schema.$name", v) =>
  22. TyEnum(v.toList, None, Some(name), Some(TyStringImpl()), Some(schema))
  23. case (enumName, v) =>
  24. TyEnum(v.toList, None, Some(enumName), Some(TyStringImpl()))
  25. }
  26. .toList
  27. }
展开查看全部

相关问题