title: Logging SQL queries in android
body: <p>I am using the <code>query</code> 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 somewhere?</p>
  
  <p>So far the best I could do was to have a look at the cursor's member mQuery using a breakpoint. I'd love to output the queries automatically though. This member is of course not public and does not have a getter.</p>
  
  <hr>
  
  <p>Just for the record, here is an implementation of the accepted answer. </p>
  
  <pre><code>/**
   * Implement the cursor factory in order to log the queries before returning 
   * the cursor
   * 
   * @author Vincent @ MarvinLabs
   */
  public class SQLiteCursorFactory implements CursorFactory {
  
      private boolean debugQueries = false;
  
      public SQLiteCursorFactory() {
          this.debugQueries = false;
      }
  
      public SQLiteCursorFactory(boolean debugQueries) {
          this.debugQueries = debugQueries;
      }
  
      @Override
      public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery, 
                              String editTable, SQLiteQuery query) {
          if (debugQueries) {
              Log.d("SQL", query.toString());
          }
          return new SQLiteCursor(db, masterQuery, editTable, query);
      }
  }
  </code></pre>