有没有办法检索从如下调用生成的原始查询字符串?我想弄清楚“?”是怎么来的。占位符被填充。
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
我很好奇操作顺序。例如,如果上面的查询转换为下面的 select 并使用下面的 whereClause 参数,我会得到 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')";
最佳答案
快速测试将表明它用字符串中的位置替换选择参数,没有任何操作顺序的概念。
关于java - android 光标操作顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16996311/