printout the sql statement built from SQLiteQueryBuilder
To facilita开发者_StackOverflowte debugging, is there any way print out a sql statement before executing following query?
c = qb.query(
epgDB,
projection,
selection,
selectionArgs,
null,
null,
sortOrder);
If you already used specific SQLiteQueryBuilder methods, e.g. appendWhere(), you can generate the underlying SQL statement simply by calling buildQuery()
:
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
// call qb.appendWhere(), qb.appendColumns(), qb.setProjectionMap() etc.
String sql;
sql = qb.buildQuery(null, null, null, null, null, null, null); // pre API 11
sql = qb.buildQuery(null, null, null, null, null, null); // API 11 and later
Both methods combine the parameters previously set by individual methods with their own parameters before calling buildQueryString()
. They do not change the state of the SQLiteQueryBuilder object and so are safe to use before executing the query.
A word of caution: I learnt this from the code itself, while the javadoc does not mention using this method to get the SQL string. Hence, I advise to be alert of changes that would alter the behavior of the method.
精彩评论