void createTable() { SQLiteDatabase db = Obtainer.AcquireDB(); db.beginTransaction(); boolean createComplete = false; try { Obtainer.getDB().execSQL(CREATE); createComplete = true; } catch (SQLException ex) { String msg = null; if (ex != null) { msg = ex.getMessage(); } if (msg != null && msg.contains("already exists")) { createComplete = true; } else { createComplete = false; } } if (createComplete) { db.setTransactionSuccessful(); } db.endTransaction(); Obtainer.ReleaseDB(); }
public void insertWithBeginTransaction(long user_id, String nickName, String nickNameMine) { String cachedNick = null; String cachedNickMine = null; Cursor cursor = Obtainer.getDB() .query( TableName, new String[] {IDXKEY, USER_ID, NICK_NAME, NICK_NAME_MINE}, USER_ID + " = " + user_id, null, null, null, null); try { if (cursor.moveToFirst()) { cachedNick = cursor.getString(NICK_NAME_IDX); cachedNickMine = cursor.getString(NICK_NAME_MINE_IDX); } } finally { closeCursor(cursor); } if (cachedNick != null || cachedNickMine != null) { ContentValues newVal = new ContentValues(); if (nickName != null) { newVal.put(NICK_NAME, nickName); cachedNick = nickName; } if (nickNameMine != null) { newVal.put(NICK_NAME_MINE, nickNameMine); cachedNickMine = nickNameMine; } Obtainer.getDB().update(TableName, newVal, "user_id = " + user_id, null); } else { ContentValues newVal = new ContentValues(); newVal.put(USER_ID, user_id); if (nickName != null) { newVal.put(NICK_NAME, nickName); cachedNick = nickName; } if (nickNameMine != null) { newVal.put(NICK_NAME_MINE, nickNameMine); cachedNickMine = nickNameMine; } Obtainer.getDB().insert(TableName, null, newVal); } cursor.close(); if (cachedNickMine != null) { cacheMap.put(user_id, cachedNickMine); } else { cacheMap.put(user_id, cachedNick); } }
Cursor getCursor(String statement) { Cursor ret; try { ret = Obtainer.AcquireDB() .query( TableName, new String[] {IDXKEY, USER_ID, NICK_NAME, NICK_NAME_MINE}, statement, null, null, null, null); } finally { Obtainer.ReleaseDB(); } return ret; }