如何在空手道中参数化 SQL 查询
How to parameterize the SQL query in karate
- def query = read(intitation.sql);
- 字符串输出=查询
我想参数化并从功能文件动态传递 column2 ='value',你能帮我实现这个吗。
下面是 sql 文件 intitation.sql:
SELECT column1, column2, column3, column4, column5, column6, column7, column8, column9, column10, column11, column12 FROM table1 WHERE **column2='value'**;
这是正常的 JS 基础:
* def value = 'foo'
* def sql = "select * from dogs where name = '" + value + "'"
另见 replace
是否有帮助:https://github.com/intuit/karate#replace
也许这也行?只是作为一个有趣的解决方案值得咀嚼的东西。对于更复杂的参数化,这可能会很有效。
* def String = Java.type('java.lang.String')
* def pString = "Select * from Whatever where id = '%s' and name = '%s'"
* def query = String.format(pString, "my-id", "my-name")
此外,也许可以加载 Java PreparedStatement
class?
- def query = read(intitation.sql);
- 字符串输出=查询
我想参数化并从功能文件动态传递 column2 ='value',你能帮我实现这个吗。
下面是 sql 文件 intitation.sql:
SELECT column1, column2, column3, column4, column5, column6, column7, column8, column9, column10, column11, column12 FROM table1 WHERE **column2='value'**;
这是正常的 JS 基础:
* def value = 'foo'
* def sql = "select * from dogs where name = '" + value + "'"
另见 replace
是否有帮助:https://github.com/intuit/karate#replace
也许这也行?只是作为一个有趣的解决方案值得咀嚼的东西。对于更复杂的参数化,这可能会很有效。
* def String = Java.type('java.lang.String')
* def pString = "Select * from Whatever where id = '%s' and name = '%s'"
* def query = String.format(pString, "my-id", "my-name")
此外,也许可以加载 Java PreparedStatement
class?