Logging SQL queries in android

后端 未结 9 2288
野趣味
野趣味 2020-12-04 17:45

I am using the query functions in order to build the SQL queries for my tables. Is there a way to see the actual query that is run? For instance log it somewher

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 18:09

    Using an SQLiteQueryBuilder it's painfully simple. buildQuery() returns a raw sql string, which can then be logged:

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(ExampleTable.TABLE_NAME);
    String sql = qb.buildQuery(projection, selection, null, null, sortOrder, null);
    Log.d("Example", sql);
    

提交回复
热议问题