public void saveAndWriteRecent(boolean saveEmpty) {
    Database database = new Database(c);

    // We need server address or SSH server to be filled out to save. Otherwise,
    // we keep adding empty connections.
    // However, if there is partial data from a URI, we can present the edit screen.
    // Alternately, perhaps we could process some extra data
    if ((getConnectionType() == Constants.CONN_TYPE_SSH && getSshServer().equals("")
            || getAddress().equals(""))
        && !saveEmpty) {
      return;
    }

    SQLiteDatabase db = database.getWritableDatabase();
    db.beginTransaction();
    try {
      save(db);
      MostRecentBean mostRecent = getMostRecent(db);
      if (mostRecent == null) {
        mostRecent = new MostRecentBean();
        mostRecent.setConnectionId(get_Id());
        mostRecent.Gen_insert(db);
      } else {
        mostRecent.setConnectionId(get_Id());
        mostRecent.Gen_update(db);
      }
      db.setTransactionSuccessful();
    } finally {
      db.endTransaction();
      db.close();
    }
    if (db.isOpen()) {
      db.close();
    }
  }
  @Override
  public void onCreate(SQLiteDatabase database) {

    try {
      database.beginTransaction();

      TableBuilder builder = new TableBuilder(ApplicationRecord.class);
      database.execSQL(builder.getTableCreateString());

      builder = new TableBuilder(AndroidSharedKeyRecord.class);
      database.execSQL(builder.getTableCreateString());

      builder = new TableBuilder(AndroidLogEntry.STORAGE_KEY);
      builder.addData(new AndroidLogEntry());
      database.execSQL(builder.getTableCreateString());

      DbUtil.createNumbersTable(database);

      database.setVersion(GLOBAL_DB_VERSION);

      database.setTransactionSuccessful();
    } finally {
      database.endTransaction();
    }
  }
Пример #3
0
 public static int executeSqlStatementsInTx(SQLiteDatabase db, String[] statements) {
   db.beginTransaction();
   try {
     int count = executeSqlStatements(db, statements);
     db.setTransactionSuccessful();
     return count;
   } finally {
     db.endTransaction();
   }
 }