Java 操作顺序
有没有一种方法可以检索从如下调用生成的原始查询字符串?我想知道“?”占位符是如何填充的Java 操作顺序,java,android,cursor,Java,Android,Cursor,有没有一种方法可以检索从如下调用生成的原始查询字符串?我想知道“?”占位符是如何填充的 Cursor cursor = database.query( adapter.getTable(), // The table to query - String adapter.getColumns(), // The columns to return - String[] adapte
Cursor cursor = database.query(
adapter.getTable(), // The table to query - String
adapter.getColumns(), // The columns to return - String[]
adapter.getWhereClause(), // The columns for the WHERE clause - String
adapter.getWhereClauseArgs(), // The values for the WHERE clause - String[]
null, // Group by - String
null, // Groups having - String
adapter.getSortBy(), // The sort order - String
adapter.getLimit()); // The limit - String
我对操作顺序很好奇。例如,如果上面的查询使用下面的where子句args转换为select,我会得到result1还是result2?它是否像数学中的运算顺序一样,先执行括号中的语句?或者它严格依赖于“?”在字符串中的位置
String select = "SELECT * FROM table1 WHERE someField = ? AND _id in(SELECT _id FROM table2 WHERE status = ?)";
String[] args = new String[]{ "blue", "active" };
String result1 = "SELECT * FROM table1 WHERE someField = 'blue' AND _id in(SELECT _id FROM table2 WHERE status = 'active')";
String result2 = "SELECT * FROM table1 WHERE someField = 'active' AND _id in(SELECT _id FROM table2 WHERE status = 'blue')";
快速测试将显示它用字符串中的位置替换选择参数,而不考虑操作顺序。如何测试?看到实际执行的查询了吗?嗯,您可以运行查询并查看它是否返回您想要的结果-这当然可以作为测试。如果使用调试器暂停应用程序,还可以查看返回的
SQLiteCursor
的privatemQuery
字段,该字段存储最终执行的查询。