Пример #1
0
    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;
  }