示例#1
0
 @Override
 public void create(SQLiteDatabase db) {
   String sql;
   sql =
       "CREATE TABLE "
           + NAME
           + " ("
           + Fields._ID
           + " INTEGER PRIMARY KEY,"
           + Fields.ACCOUNT
           + " TEXT,"
           + Fields.ROOM
           + " TEXT,"
           + Fields.NICKNAME
           + " TEXT,"
           + Fields.PASSWORD
           + " TEXT,"
           + Fields.NEED_JOIN
           + " INTEGER);";
   DatabaseManager.execSQL(db, sql);
   sql =
       "CREATE UNIQUE INDEX "
           + NAME
           + "_list ON "
           + NAME
           + " ("
           + Fields.ACCOUNT
           + ", "
           + Fields.ROOM
           + ");";
   DatabaseManager.execSQL(db, sql);
 }
示例#2
0
 @Override
 public void migrate(SQLiteDatabase db, int toVersion) {
   super.migrate(db, toVersion);
   String sql;
   switch (toVersion) {
     case 24:
       sql =
           "CREATE TABLE rooms (_id INTEGER PRIMARY KEY,"
               + "account TEXT,"
               + "room TEXT,"
               + "nickname TEXT,"
               + "password TEXT,"
               + "timestamp INTEGER);";
       DatabaseManager.execSQL(db, sql);
       sql = "CREATE UNIQUE INDEX rooms_list ON rooms (account, room);";
       DatabaseManager.execSQL(db, sql);
       break;
     case 25:
       DatabaseManager.dropTable(db, "rooms");
       sql =
           "CREATE TABLE rooms (_id INTEGER PRIMARY KEY,"
               + "account TEXT,"
               + "room TEXT,"
               + "nickname TEXT,"
               + "password TEXT,"
               + "need_join INTEGER);";
       DatabaseManager.execSQL(db, sql);
       sql = "CREATE UNIQUE INDEX rooms_list ON rooms (account, room);";
       DatabaseManager.execSQL(db, sql);
       break;
     default:
       break;
   }
 }
示例#3
0
 /**
  * Adds or updates room.
  *
  * @param account
  * @param room
  * @param nickname
  * @param password
  * @param join
  */
 void write(String account, String room, String nickname, String password, boolean join) {
   synchronized (writeLock) {
     if (writeStatement == null) {
       SQLiteDatabase db = databaseManager.getWritableDatabase();
       writeStatement =
           db.compileStatement(
               "INSERT OR REPLACE INTO "
                   + NAME
                   + " ("
                   + Fields.ACCOUNT
                   + ", "
                   + Fields.ROOM
                   + ", "
                   + Fields.NICKNAME
                   + ", "
                   + Fields.PASSWORD
                   + ", "
                   + Fields.NEED_JOIN
                   + ") VALUES (?, ?, ?, ?, ?);");
     }
     writeStatement.bindString(1, account);
     writeStatement.bindString(2, room);
     writeStatement.bindString(3, nickname);
     writeStatement.bindString(4, password);
     writeStatement.bindLong(5, join ? 1 : 0);
     writeStatement.execute();
   }
 }
示例#4
0
 static {
   instance = new RoomTable(DatabaseManager.getInstance());
   DatabaseManager.getInstance().addTable(instance);
 }
示例#5
0
 /**
  * Removes room.
  *
  * @param account
  * @param room
  */
 void remove(String account, String room) {
   SQLiteDatabase db = databaseManager.getWritableDatabase();
   db.delete(
       NAME, Fields.ACCOUNT + " = ? AND " + Fields.ROOM + " = ?", new String[] {account, room});
 }