public void runInternal() throws DatabaseUnavailableException {
        SQLiteDatabase database = HubApplication._().getDatabaseHandle();

        Cursor c = database.query("SyncableUser", null, null, null, null, null, null);
        try {
            SyncableUser actionable = null;
            for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
                SyncableUser u = SyncableUser.fromDb(c);

                if (u.getStatus() != SyncableUser.UserStatus.ModelFetched && u.getStatus() != SyncableUser.UserStatus.AuthError) {
                    //Only grab the first user to act on, we don't wanna be greedy in this thread
                    actionable = u;
                    break;
                }
            }

            if (actionable == null) {
                return;
            }

            if (actionable.getStatus() == SyncableUser.UserStatus.Requested) {
                fetchKeyForUser(actionable, database);
            } else if(actionable.getStatus() == SyncableUser.UserStatus.KeysFetched) {
                try {
                    fetchModelForUser(actionable, database);
                } catch(IOException ioe) {
                    ServicesMonitor.reportMessage("Error fetching user model for " + actionable.getUsername()+ " - " + ioe.getMessage());
                }
            }

        } finally {
            c.close();
        }

    }
  @Override
  public boolean execute(SQLiteDatabase database) {

    database.execSQL("create table t1(a INTEGER, b INTEGER);");
    database.execSQL("insert into t1(a,b) values(123, 456);");
    Cursor cursor = database.rawQuery("select * from t1;", new String[] {});
    if (cursor != null) {
      cursor.moveToFirst();
      cursor.copyStringToBuffer(1, charArrayBuffer);
      String actualValue = new String(charArrayBuffer.data, 0, charArrayBuffer.sizeCopied);
      return "456".equals(actualValue);
    }
    return false;
  }
  public void openLastSearch(View view) {
    // Suchanfragen aus Speicher holen

    String[] projection = {
      KleFuEntry.COLUMN_NAME_GEBIET, // 0
      KleFuEntry.COLUMN_NAME_GIPFELNUMMER_VON, // 1
      KleFuEntry.COLUMN_NAME_GIPFELNUMMER_BIS, // 2
      KleFuEntry.COLUMN_NAME_GIPFEL, // 3
      KleFuEntry.COLUMN_NAME_WEGNAME, // 4
      KleFuEntry.COLUMN_NAME_SCHWIERIGKEIT_VON, // 5
      KleFuEntry.COLUMN_NAME_SCHWIERIGKEIT_BIS, // 6
      KleFuEntry.COLUMN_NAME_GEKLETTERT, // 7
      KleFuEntry.COLUMN_NAME_NOCH_NICHT_GEKLETTERT // 8
    };
    Cursor c =
        KleFuEntry.db.query(
            KleFuEntry.TABLE_NAME_SUCHANFRAGEN, // The table to query
            projection, // The columns to return
            null, // The columns for the WHERE clause
            null, // The values for the WHERE clause
            null, // don't group the rows
            null, // don't filter by row groups
            null // The sort order
            );

    c.moveToLast();
    suchanfrage =
        new Suchanfrage(
            c.getString(0),
            c.getInt(1),
            c.getInt(2),
            c.getString(3),
            c.getString(4),
            new Schwierigkeit(c.getInt(5)),
            new Schwierigkeit(c.getInt(6)),
            c.getInt(7) > 0,
            c.getInt(8) > 0);
    c.close();

    sucheHandler = new SucheHandler(this, this, sucheThread);
    sucheThread = new SucheThread(this, this);
    sucheThread.start();
  }
 @OnClick({R.id.add_data, R.id.query_data})
 public void onClick(View view) {
   switch (view.getId()) {
     case R.id.add_data:
       ContentValues values = new ContentValues();
       values.put("name", "GOT");
       values.put("pages", 566);
       database.insert("Book", null, values);
       break;
     case R.id.query_data:
       Cursor cursor = database.query("Book", null, null, null, null, null, null);
       if (cursor != null) {
         while (cursor.moveToNext()) {
           String name = cursor.getString(cursor.getColumnIndex("name"));
           int pages = cursor.getInt(cursor.getColumnIndex("pages"));
           Log.d("TAG", "book names is " + name);
           Log.d("TAG", "book pages is " + pages);
         }
       }
       cursor.close();
       break;
   }
 }