简体   繁体   English

如何测试SQL动态查询?

[英]How to test SQL dynamic queries?

My applications are Spring/iBatis (2.3) based. 我的应用程序基于Spring / iBatis(2.3)。 I usually write a lot of dynamic queries in my sqlMaps and I'd like to test my generated SQL queries to avoid any syntax errors. 我通常在sqlMaps中编写很多动态查询,并且我想测试生成的SQL查询以避免任何语法错误。 For more precision, I want to: 为了获得更高的精度,我想:

  1. check the SQL syntax (depending on the sql dialect) of all my generated queries 检查所有生成的查询的SQL语法(取决于sql方言)
  2. check if my queries work correctly with the actual database structure 检查我的查询是否与实际的数据库结构一起正常工作

Does already exist a library that gives me the chance to check the SQL syntax (step 1), depending on the sql dialect (I'm actually using Oracle), without a database connection? 是否已经存在一个没有数据库连接的库,该库使我有机会根据sql方言(实际上是在使用Oracle)检查SQL语法(步骤1)?

Does already exist a sqlMap parser which could help me generating all potential queries, containing all combinations of dynamic parameters? 是否已经存在一个sqlMap解析器,可以帮助我生成所有潜在查询,其中包含动态参数的所有组合?

Basically, I'm thinking about a way to avoid writing one (or more) unit test per query. 基本上,我正在考虑一种避免每个查询编写一个(或多个)单元测试的方法。 I'd like to automate this step to be sure that my generated queries are always right. 我想自动执行此步骤,以确保生成的查询始终正确。 Any other suggestions? 还有其他建议吗?

There is a related question and some people suggested using DBUnit . 有一个相关的问题 ,有人建议使用DBUnit Maybe you should give it a try. 也许您应该尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM