android.database.sqlite.SQLiteDatabase

Here are the examples of the java api class android.database.sqlite.SQLiteDatabase taken from open source projects.

1. MySQLiteHelper#insert()

Project: AndroidLife
Source File: MySQLiteHelper.java
View license
/**
     * ????
     */
public void insert(String content) {
    SQLiteDatabase insert = this.getWritableDatabase();
    insert.beginTransaction();
    ContentValues values = new ContentValues();
    values.put("content", content);
    insert.insert(TB_CAMNTER, "", values);
    /**
         * ????????????????????
         */
    insert.setTransactionSuccessful();
    /**
         * ????
         */
    insert.endTransaction();
}

2. MySQLiteHelper#updateFirst()

Project: AndroidLife
Source File: MySQLiteHelper.java
View license
/**
     * ???????
     */
public void updateFirst() {
    List<SQLiteData> allData = this.queryAll();
    if (allData == null || allData.size() < 1)
        return;
    int firstId = allData.get(0).id;
    SQLiteDatabase update = this.getWritableDatabase();
    update.beginTransaction();
    ContentValues values = new ContentValues();
    values.put("content", UUID.randomUUID().toString());
    update.update(TB_CAMNTER, values, "_id=?", new String[] { firstId + "" });
    update.setTransactionSuccessful();
    update.endTransaction();
}

3. DatabaseBackend#wipeAxolotlDb()

Project: Conversations
Source File: DatabaseBackend.java
View license
public void wipeAxolotlDb(Account account) {
    String accountName = account.getUuid();
    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + ">>> WIPING AXOLOTL DATABASE FOR ACCOUNT " + accountName + " <<<");
    SQLiteDatabase db = this.getWritableDatabase();
    String[] deleteArgs = { accountName };
    db.delete(SQLiteAxolotlStore.SESSION_TABLENAME, SQLiteAxolotlStore.ACCOUNT + " = ?", deleteArgs);
    db.delete(SQLiteAxolotlStore.PREKEY_TABLENAME, SQLiteAxolotlStore.ACCOUNT + " = ?", deleteArgs);
    db.delete(SQLiteAxolotlStore.SIGNED_PREKEY_TABLENAME, SQLiteAxolotlStore.ACCOUNT + " = ?", deleteArgs);
    db.delete(SQLiteAxolotlStore.IDENTITIES_TABLENAME, SQLiteAxolotlStore.ACCOUNT + " = ?", deleteArgs);
}

4. DatabaseImpl#create()

Project: jamendo-android
Source File: DatabaseImpl.java
View license
/**
	 * Initializes database and tables
	 */
private void create() {
    SQLiteDatabase db = mActivity.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
    // create tables if necessary
    db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_PLAYLIST + " (PlaylistName VARCHAR UNIQUE," + " FileName INTEGER PRIMARY KEY AUTOINCREMENT);");
    db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_RECENT_RADIOS + " (radio_id INTEGER UNIQUE, radio_idstr VARCHAR, radio_name VARCHAR, radio_image VARCHAR, radio_date INTEGER);");
    db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_FAVORITES + " (track_id INTEGER UNIQUE, track_name VARCHAR," + " track_duration INTEGER, track_url VARCHAR, track_stream VARCHAR, track_rating REAL," + " album_id INTEGER, album_name VARCHAR, album_image VARCHAR, album_rating REAL, artist_name VARCHAR);");
    db.close();
}

5. Utils#clearCache()

Project: Leisure
Source File: Utils.java
View license
public static void clearCache() {
    WebView wb = new WebView(mContext);
    wb.clearCache(true);
    DatabaseHelper mHelper = DatabaseHelper.instance(mContext);
    SQLiteDatabase db = mHelper.getWritableDatabase();
    db.execSQL(mHelper.DELETE_TABLE_DATA + DailyTable.NAME);
    //  db.execSQL(DailyTable.CREATE_TABLE);
    db.execSQL(mHelper.DELETE_TABLE_DATA + NewsTable.NAME);
    //  db.execSQL(NewsTable.CREATE_TABLE);
    db.execSQL(mHelper.DELETE_TABLE_DATA + ReadingTable.NAME);
    //  db.execSQL(ReadingTable.CREATE_TABLE);
    db.execSQL(mHelper.DELETE_TABLE_DATA + ScienceTable.NAME);
//  db.execSQL(ScienceTable.CREATE_TABLE);
}

6. MySQLiteHelper#queryAll()

Project: AndroidLife
Source File: MySQLiteHelper.java
View license
/**
     * ????
     *
     * @return List list
     */
public List<SQLiteData> queryAll() {
    List<SQLiteData> allData = new ArrayList<>();
    SQLiteDatabase queryAll = this.getReadableDatabase();
    queryAll.beginTransaction();
    String sql = "select * from " + TB_CAMNTER;
    Cursor result = queryAll.rawQuery(sql, null);
    for (result.moveToFirst(); !result.isAfterLast(); result.moveToNext()) {
        SQLiteData data = new SQLiteData();
        data.id = result.getInt(result.getColumnIndex("_id"));
        data.content = result.getString(result.getColumnIndex("content"));
        allData.add(data);
    }
    queryAll.setTransactionSuccessful();
    queryAll.endTransaction();
    result.close();
    return allData;
}

7. EnterpriseHDMProvider#addEnterpriseHDMAddress()

View license
@Override
public void addEnterpriseHDMAddress(List<EnterpriseHDMAddress> enterpriseHDMAddressList) {
    SQLiteDatabase db = this.mDb.getWritableDatabase();
    db.beginTransaction();
    for (EnterpriseHDMAddress enterpriseHDMAddress : enterpriseHDMAddressList) {
        ContentValues cv = applyContentValues(enterpriseHDMAddress);
        db.insert(AbstractDb.Tables.ENTERPRISE_HDM_ADDRESS, null, cv);
    }
    db.setTransactionSuccessful();
    db.endTransaction();
}

8. DatabaseBackend#writeRoster()

Project: Conversations
Source File: DatabaseBackend.java
View license
public void writeRoster(final Roster roster) {
    final Account account = roster.getAccount();
    final SQLiteDatabase db = this.getWritableDatabase();
    db.beginTransaction();
    for (Contact contact : roster.getContacts()) {
        if (contact.getOption(Contact.Options.IN_ROSTER)) {
            db.insert(Contact.TABLENAME, null, contact.getContentValues());
        } else {
            String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?";
            String[] whereArgs = { account.getUuid(), contact.getJid().toString() };
            db.delete(Contact.TABLENAME, where, whereArgs);
        }
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    account.setRosterVersion(roster.getVersion());
    updateAccount(account);
}

9. RecipientPreferenceDatabase#updateOrInsert()

View license
private void updateOrInsert(Recipients recipients, ContentValues contentValues) {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    database.beginTransaction();
    int updated = database.update(TABLE_NAME, contentValues, RECIPIENT_IDS + " = ?", new String[] { String.valueOf(recipients.getSortedIdsString()) });
    if (updated < 1) {
        contentValues.put(RECIPIENT_IDS, recipients.getSortedIdsString());
        database.insert(TABLE_NAME, null, contentValues);
    }
    database.setTransactionSuccessful();
    database.endTransaction();
    context.getContentResolver().notifyChange(Uri.parse(RECIPIENT_PREFERENCES_URI), null);
}

10. HistoryDatabase#getHistory()

Project: actor-platform
Source File: HistoryDatabase.java
View license
public static ArrayList<String> getHistory(Context context) {
    ArrayList<String> history = new ArrayList<String>();
    SQLiteDatabase database = new HistoryDatabase(context).getWritableDatabase();
    Cursor cursor = database.query(SELECTED_HISTORY_TABLE, SELECTED_HISTORY_COLUMNS, null, null, null, null, "last_selected DESC");
    int pathColumnIndex = cursor.getColumnIndex("path");
    ArrayList<String> removeIndexes = new ArrayList<String>();
    if (cursor.moveToFirst()) {
        int count = 0;
        do {
            if (count < 20) {
                count++;
                history.add(cursor.getString(pathColumnIndex));
            } else {
                removeIndexes.add(cursor.getString(pathColumnIndex));
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    String[] removeIndexesArray = new String[removeIndexes.size()];
    database.delete(SELECTED_HISTORY_TABLE, "path = ?", removeIndexes.toArray(removeIndexesArray));
    database.close();
    return history;
}

11. MySQLiteHelper#addBook()

View license
public void addBook(Book book) {
    Log.d("addBook", book.toString());
    // 1. get reference to writable DB
    SQLiteDatabase db = this.getWritableDatabase();
    // 2. create ContentValues to add key "column"/value
    ContentValues values = new ContentValues();
    // get title 
    values.put(KEY_TITLE, book.getTitle());
    // get author
    values.put(KEY_AUTHOR, book.getAuthor());
    // 3. insert
    // table
    db.insert(// table
    TABLE_BOOKS, //nullColumnHack
    null, // key/value -> keys = column names/ values = column values
    values);
    // 4. close
    db.close();
}

12. MySQLiteHelper#deleteBook()

View license
// Deleting single book
public void deleteBook(Book book) {
    // 1. get reference to writable DB
    SQLiteDatabase db = this.getWritableDatabase();
    // 2. delete
    db.delete(TABLE_BOOKS, KEY_ID + " = ?", new String[] { String.valueOf(book.getId()) });
    // 3. close
    db.close();
    Log.d("deleteBook", book.toString());
}

13. AnalyticsDatabase#removeEvents()

View license
public void removeEvents(List<AnalyticsEvent> events) {
    StringBuilder where = new StringBuilder(ID).append(" in (");
    String[] whereArgs = new String[events.size()];
    for (int i = 0; i < events.size(); i++) {
        whereArgs[i] = Integer.toString(events.get(i).id);
        where.append("?");
        if (i < events.size() - 1) {
            where.append(",");
        } else {
            where.append(")");
        }
    }
    SQLiteDatabase db = getWritableDatabase();
    db.delete(TABLE_NAME, where.toString(), whereArgs);
    db.close();
}

14. DailyModel#saveDailyGsonDB()

Project: BuildingBlocks
Source File: DailyModel.java
View license
private void saveDailyGsonDB(DailyGson daily) {
    SQLiteDatabase database = mSQLiteHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put("id", daily.id);
    values.put("title", daily.title);
    values.put("type", daily.type);
    values.put("image_source", daily.image_source);
    values.put("image", daily.image);
    values.put("share_url", daily.share_url);
    values.put("ga_prefix", daily.ga_prefix);
    values.put("body", daily.body);
    database.insertWithOnConflict("daily", null, values, SQLiteDatabase.CONFLICT_IGNORE);
    database.close();
}

15. EventDetailsDBHandler#insertRow()

View license
public void insertRow(EventDetails event) {
    ContentValues values = new ContentValues();
    values.put(COLUMN_TIME_STAMP, event.get_TimeStamp());
    values.put(COLUMN_NAME, event.get_EventName());
    values.put(COLUMN_PLACE, event.get_EventPlace());
    values.put(COLUMN_START_DATE_TIME, event.get_StartDateTime());
    values.put(COLUMN_END_DATE_TIME, event.get_EndDateTime());
    values.put(COLUMN_REPETITION, event.get_Repetition());
    values.put(COLUMN_TYPE, event.get_Type());
    values.put(COLUMN_REGN_PLACE, event.get_Regn_Place());
    values.put(COLUMN_WEBSITE, event.get_Website());
    values.put(COLUMN_DEADLINE_DATE_TIME, event.get_DeadlineDateTime());
    values.put(COLUMN_COMMENTS, event.get_Comments());
    values.put(COLUMN_STARTS_FROM, event.get_StartsFromDailyOrWeekly());
    values.put(COLUMN_ENDS_ON, event.get_EndsFromDailyOrWeekly());
    SQLiteDatabase db = getWritableDatabase();
    db.insert(TABLE_NAME, null, values);
    db.close();
}

16. EventDetailsDBHandler#updateRow()

View license
public void updateRow(EventDetails event, int id) {
    ContentValues values = new ContentValues();
    values.put(COLUMN_TIME_STAMP, event.get_TimeStamp());
    values.put(COLUMN_NAME, event.get_EventName());
    values.put(COLUMN_PLACE, event.get_EventPlace());
    values.put(COLUMN_START_DATE_TIME, event.get_StartDateTime());
    values.put(COLUMN_END_DATE_TIME, event.get_EndDateTime());
    values.put(COLUMN_REPETITION, event.get_Repetition());
    values.put(COLUMN_TYPE, event.get_Type());
    values.put(COLUMN_REGN_PLACE, event.get_Regn_Place());
    values.put(COLUMN_WEBSITE, event.get_Website());
    values.put(COLUMN_DEADLINE_DATE_TIME, event.get_DeadlineDateTime());
    values.put(COLUMN_COMMENTS, event.get_Comments());
    values.put(COLUMN_STARTS_FROM, event.get_StartsFromDailyOrWeekly());
    values.put(COLUMN_ENDS_ON, event.get_EndsFromDailyOrWeekly());
    SQLiteDatabase db = getWritableDatabase();
    String where = COLUMN_ID + "='" + id + "'";
    db.update(TABLE_NAME, values, where, null);
    db.close();
}

17. OnlineEventDetailsDBHandler#insertRow()

View license
public void insertRow(OnlineEventDetails event) {
    ContentValues values = new ContentValues();
    values.put(COLUMN_TIME_STAMP, event.get_TimeStamp());
    values.put(COLUMN_EEVEE_ID, event.get_eeVeeID());
    values.put(COLUMN_NAME, event.get_EventName());
    values.put(COLUMN_PLACE, event.get_EventPlace());
    values.put(COLUMN_START_DATE_TIME, event.get_StartDateTime());
    values.put(COLUMN_END_DATE_TIME, event.get_EndDateTime());
    values.put(COLUMN_REPETITION, event.get_Repetition());
    values.put(COLUMN_TYPE, event.get_Type());
    values.put(COLUMN_REGN_PLACE, event.get_Regn_Place());
    values.put(COLUMN_WEBSITE, event.get_Website());
    values.put(COLUMN_DEADLINE_DATE_TIME, event.get_DeadlineDateTime());
    values.put(COLUMN_COMMENTS, event.get_Comments());
    values.put(COLUMN_STARTS_FROM, event.get_StartsFromDailyOrWeekly());
    values.put(COLUMN_ENDS_ON, event.get_EndsFromDailyOrWeekly());
    values.put(COLUMN_STATUS, event.get_Status());
    values.put(COLUMN_CLUBNAME, event.get_ClubName());
    values.put(COLUMN_APPROVAL, event.get_Approval());
    SQLiteDatabase db = getWritableDatabase();
    db.insert(TABLE_NAME, null, values);
    db.close();
}

18. TaskDetailsDBHandler#insertRow()

View license
public void insertRow(TaskDetails task) {
    ContentValues values = new ContentValues();
    values.put(COLUMN_TIME_STAMP, task.get_TimeStamp());
    values.put(COLUMN_DESCRIPTION, task.get_TaskDescription());
    values.put(COLUMN_TAG, task.get_TaskTag());
    values.put(COLUMN_START_DATE_TIME, task.get_StartDateTime());
    values.put(COLUMN_END_DATE_TIME, task.get_EndDateTime());
    values.put(COLUMN_REPETITION, task.get_Repetition());
    values.put(COLUMN_TYPE, task.get_Type());
    values.put(COLUMN_STARTS_FROM, task.get_StartsFromDailyOrWeekly());
    values.put(COLUMN_ENDS_ON, task.get_EndsFromDailyOrWeekly());
    SQLiteDatabase db = getWritableDatabase();
    db.insert(TABLE_NAME, null, values);
    db.close();
}

19. TaskDetailsDBHandler#updateRow()

View license
public void updateRow(TaskDetails task, int id) {
    ContentValues values = new ContentValues();
    values.put(COLUMN_TIME_STAMP, task.get_TimeStamp());
    values.put(COLUMN_DESCRIPTION, task.get_TaskDescription());
    values.put(COLUMN_TAG, task.get_TaskTag());
    values.put(COLUMN_START_DATE_TIME, task.get_StartDateTime());
    values.put(COLUMN_END_DATE_TIME, task.get_EndDateTime());
    values.put(COLUMN_REPETITION, task.get_Repetition());
    values.put(COLUMN_TYPE, task.get_Type());
    values.put(COLUMN_STARTS_FROM, task.get_StartsFromDailyOrWeekly());
    values.put(COLUMN_ENDS_ON, task.get_EndsFromDailyOrWeekly());
    SQLiteDatabase db = getWritableDatabase();
    String where = COLUMN_ID + "='" + id + "'";
    db.update(TABLE_NAME, values, where, null);
    db.close();
}

20. UserDetailsDBHandler#updateFirstRow()

View license
/**
     * As you increase no Columns this function increases
     */
public void updateFirstRow(UserDetails user) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COLUMN_USER_NAME, user.get_userName());
    values.put(COLUMN_MALE, user.is_Male());
    values.put(COLUMN_SUBSCRIPTION, user.get_Subscription());
    db.update(TABLE_NAME, values, COLUMN_ID + " = 1", null);
    setStaticUserDetails();
    db.close();
}

21. WebEventDetailsDBHandler#insertRow()

View license
public void insertRow(WebEventDetails event) {
    ContentValues values = new ContentValues();
    values.put(COLUMN_TIME_STAMP, event.get_TimeStamp());
    values.put(COLUMN_EEVEE_ID, event.get_eeVeeID());
    values.put(COLUMN_NAME, event.get_EventName());
    values.put(COLUMN_PLACE, event.get_EventPlace());
    values.put(COLUMN_START_DATE_TIME, event.get_StartDateTime());
    values.put(COLUMN_END_DATE_TIME, event.get_EndDateTime());
    values.put(COLUMN_REPETITION, event.get_Repetition());
    values.put(COLUMN_TYPE, event.get_Type());
    values.put(COLUMN_REGN_PLACE, event.get_Regn_Place());
    values.put(COLUMN_WEBSITE, event.get_Website());
    values.put(COLUMN_DEADLINE_DATE_TIME, event.get_DeadlineDateTime());
    values.put(COLUMN_COMMENTS, event.get_Comments());
    values.put(COLUMN_STARTS_FROM, event.get_StartsFromDailyOrWeekly());
    values.put(COLUMN_ENDS_ON, event.get_EndsFromDailyOrWeekly());
    values.put(COLUMN_STATUS, event.get_Status());
    values.put(COLUMN_CLUBNAME, event.get_ClubName());
    SQLiteDatabase db = getWritableDatabase();
    db.insert(TABLE_NAME, null, values);
    db.close();
}

22. AccountDbTest#testConstruct_whenDatabaseWithoutProviderColumn()

View license
public void testConstruct_whenDatabaseWithoutProviderColumn() {
    deleteAccountDb();
    SQLiteDatabase database = DependencyInjector.getContext().openOrCreateDatabase(AccountDb.PATH, Context.MODE_PRIVATE, null);
    database.execSQL("CREATE TABLE " + AccountDb.TABLE_NAME + " (first INTEGER)");
    MoreAsserts.assertContentsInAnyOrder(AccountDb.listTableColumnNamesLowerCase(database, AccountDb.TABLE_NAME), "first");
    database.close();
    database = null;
    accountDb = DependencyInjector.getAccountDb();
    MoreAsserts.assertContentsInAnyOrder(AccountDb.listTableColumnNamesLowerCase(accountDb.mDatabase, AccountDb.TABLE_NAME), "first", AccountDb.PROVIDER_COLUMN);
}

23. DatabaseImpl#deletePlaylist()

Project: jamendo-android
Source File: DatabaseImpl.java
View license
@Override
public void deletePlaylist(String playlistName) {
    SQLiteDatabase db = mActivity.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
    String fileName = queryForFileName(playlistName, db);
    if (fileName != null)
        mActivity.deleteFile(fileName);
    //mActivity.openFileOutput(fileName, Context.MODE_PRIVATE).getFD().
    String[] whereArgs = { playlistName };
    db.delete(TABLE_PLAYLIST, "PlaylistName = ?", whereArgs);
    db.close();
}

24. DBHelper#insertShortcut()

Project: KISS
Source File: DBHelper.java
View license
public static void insertShortcut(Context context, ShortcutRecord shortcut) {
    SQLiteDatabase db = getDatabase(context);
    ContentValues values = new ContentValues();
    values.put("name", shortcut.name);
    values.put("package", shortcut.packageName);
    values.put("icon", shortcut.iconResource);
    values.put("intent_uri", shortcut.intentUri);
    values.put("icon_blob", shortcut.icon_blob);
    db.insert("shortcuts", null, values);
    db.close();
}

25. DBHelper#removeShortcuts()

Project: KISS
Source File: DBHelper.java
View license
public static void removeShortcuts(Context context, String packageName) {
    SQLiteDatabase db = getDatabase(context);
    // Cursor query (String table, String[] columns, String selection,
    // String[] selectionArgs, String groupBy, String having, String
    // orderBy)
    Cursor cursor = db.query("shortcuts", new String[] { "name", "package", "icon", "intent_uri", "icon_blob" }, "intent_uri LIKE ?", new String[] { "%" + packageName + "%" }, null, null, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        // remove from history
        db.delete("history", "record = ?", new String[] { ShortcutsPojo.SCHEME + cursor.getString(0).toLowerCase() });
        cursor.moveToNext();
    }
    cursor.close();
    //remove shortcuts
    db.delete("shortcuts", "intent_uri LIKE ?", new String[] { "%" + packageName + "%" });
    db.close();
}

26. RedditAccountManager#setDefaultAccount()

Project: RedReader
Source File: RedditAccountManager.java
View license
public synchronized void setDefaultAccount(final RedditAccount newDefault) {
    final SQLiteDatabase db = getWritableDatabase();
    db.execSQL(String.format("UPDATE %s SET %s=(SELECT MIN(%s)-1 FROM %s) WHERE %s=?", TABLE, FIELD_PRIORITY, FIELD_PRIORITY, TABLE, FIELD_USERNAME), new String[] { newDefault.username });
    reloadAccounts(db);
    db.close();
    updateNotifier.updateAllListeners();
}

27. DatabaseHandler#addFriend()

Project: repay-android
Source File: DatabaseHandler.java
View license
/**
	 * Add a friend into the database. To get a RepayID, use generateRepayID()
	 * @param friend
	 * @throws android.database.SQLException
	 */
public void addFriend(final Friend friend) throws SQLException {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(Names.F_REPAYID, friend.getRepayID());
    try {
        values.put(Names.F_LOOKUPURI, friend.getLookupURI());
    } catch (NullPointerException e) {
        Log.i(TAG, "Added by name, Null for lookupUri");
        values.putNull(Names.F_LOOKUPURI);
    }
    values.put(Names.F_NAME, friend.getName());
    values.put(Names.F_DEBT, friend.getDebt().toString());
    db.insert(Names.F_TABLENAME, null, values);
    db.close();
}

28. DatabaseHandler#addDebt()

Project: repay-android
Source File: DatabaseHandler.java
View license
/**
	 * Add a debt into the database, linked to a RepayID
	 * @param repayID
	 * @param amount
	 * @param description
	 * @throws android.database.SQLException
	 * @throws NullPointerException
	 */
public void addDebt(final String repayID, final BigDecimal amount, String description) throws SQLException, NullPointerException {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(Names.D_REPAYID, repayID);
    values.put(Names.D_DATE, new Date().toString());
    values.put(Names.D_AMOUNT, amount.toString());
    values.put(Names.D_DESCRIPTION, description.replaceAll("[-+.^:,']", ""));
    db.insert(Names.D_TABLENAME, null, values);
    db.close();
}

29. SQLiteConnectionRepository#updateConnection()

View license
public void updateConnection(Connection<?> connection) {
    ConnectionData data = connection.createData();
    SQLiteDatabase db = repositoryHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put("displayName", data.getDisplayName());
    values.put("profileUrl", data.getProfileUrl());
    values.put("imageUrl", data.getImageUrl());
    values.put("accessToken", encrypt(data.getAccessToken()));
    values.put("secret", encrypt(data.getSecret()));
    values.put("refreshToken", encrypt(data.getRefreshToken()));
    values.put("expireTime", data.getExpireTime());
    final String whereClause = "userId = ? and providerId = ? and providerUserId = ?";
    final String[] whereArgs = { userId, data.getProviderId(), data.getProviderUserId() };
    db.update("UserConnection", values, whereClause, whereArgs);
    db.close();
}

30. SQLiteUsersConnectionRepositoryTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    // creates the database, if it does not exist
    repositoryHelper = new SQLiteConnectionRepositoryHelper(getContext());
    // clear out any existing connections in the database
    SQLiteDatabase db = repositoryHelper.getWritableDatabase();
    db.delete("UserConnection", null, null);
    db.close();
    connectionFactoryRegistry = new ConnectionFactoryRegistry();
    connectionFactory = new TestFacebookConnectionFactory();
    connectionFactoryRegistry.addConnectionFactory(connectionFactory);
    // generates a random 8-byte salt that is then hex-encoded
    String salt = AndroidKeyGenerators.string().generateKey();
    String password = "Unit tests are cool!";
    textEncryptor = AndroidEncryptors.text(password, salt);
    usersConnectionRepository = new SQLiteUsersConnectionRepository(repositoryHelper, connectionFactoryRegistry, textEncryptor);
    connectionRepository = usersConnectionRepository.createConnectionRepository("1");
}

31. SqliteHelperTest#testUpdateWithoutExclusion()

Project: tray
Source File: SqliteHelperTest.java
View license
public void testUpdateWithoutExclusion() throws Exception {
    final SQLiteDatabase db = new MockDatabaseHelper().getReadableDatabase();
    db.delete("test", null, null);
    // insert data. This forces the update
    final ContentValues dataValues = new ContentValues();
    dataValues.put("name", "has data");
    db.insert("test", null, dataValues);
    // update without exclusion
    final ContentValues values = new ContentValues();
    values.put("name", "data");
    final int result = SqliteHelper.insertOrUpdate(db, "test", null, null, values, null);
    assertEquals(0, result);
}

32. DB#getUser()

Project: AcFun-Area63
Source File: DB.java
View license
public User getUser() {
    SQLiteDatabase db = helper.getReadableDatabase();
    Cursor query = db.rawQuery("SELECT * FROM " + DBOpenHelper.TABLE_USER, null);
    User user = null;
    if (query.moveToFirst()) {
        user = new User();
        user.id = query.getInt(query.getColumnIndex("uid"));
        user.name = query.getString(query.getColumnIndex("name"));
        user.avatar = query.getString(query.getColumnIndex("avatar"));
        user.signature = query.getString(query.getColumnIndex("signature"));
        user.cookies = query.getString(query.getColumnIndex("cookies"));
        user.savedTime = query.getLong(query.getColumnIndex("time"));
    }
    query.close();
    db.close();
    return user;
}

33. DB#getFavList()

Project: AcFun-Area63
Source File: DB.java
View license
public List<Content> getFavList() {
    SQLiteDatabase db = helper.getReadableDatabase();
    Cursor query = db.rawQuery("SELECT * FROM " + DBOpenHelper.TABLE_FAV, null);
    if (query.getCount() <= 0) {
        query.close();
        db.close();
        return null;
    }
    List<Content> cs = new ArrayList<Content>(query.getCount());
    while (query.moveToNext()) {
        Content c = new Content();
        c.aid = query.getInt(query.getColumnIndex("aid"));
        c.title = query.getString(query.getColumnIndex("title"));
        c.description = query.getString(query.getColumnIndex("description"));
        c.channelId = query.getInt(query.getColumnIndex("channelId"));
        c.stows = query.getInt(query.getColumnIndex("stows"));
        c.releaseDate = query.getLong(query.getColumnIndex("time"));
        cs.add(c);
    }
    query.close();
    db.close();
    return cs;
}

34. HistoryDatabase#save()

Project: actor-platform
Source File: HistoryDatabase.java
View license
public static void save(Context context, ArrayList<String> pathes) {
    SQLiteDatabase database = new HistoryDatabase(context).getWritableDatabase();
    for (String path : pathes) {
        ContentValues values = new ContentValues();
        values.put("path", path);
        values.put("last_selected", TimeUtils.unixtime());
        database.delete(SELECTED_HISTORY_TABLE, "path = \"" + path + "\"", null);
        database.insert(SELECTED_HISTORY_TABLE, null, values);
    }
    database.close();
}

35. SmsManager#insertPhone()

Project: alertsystem
Source File: SmsManager.java
View license
public static String insertPhone(String string) {
    SQLiteDatabase db = mAlertSystemDBHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        ContentValues cvs = new ContentValues();
        cvs.put(AlertPhoneColoumn.number, string);
        db.insert(AlertSystemDBHelper.DATEBASE_ALERT_PHONE_TABLE, null, cvs);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    return string;
}

36. TabHandler#findTab()

Project: AmazeFileManager
Source File: TabHandler.java
View license
public Tab findTab(int tabNo) {
    String query = "Select * FROM " + TABLE_TAB + " WHERE " + COLUMN_TAB_NO + "= \"" + tabNo + "\"";
    SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
    Cursor cursor = sqLiteDatabase.rawQuery(query, null);
    Tab tab = new Tab();
    if (cursor.moveToFirst()) {
        cursor.moveToFirst();
        tab.setTab((cursor.getInt(0)));
        tab.setPath(cursor.getString(1));
        tab.setHome(cursor.getString(2));
        cursor.close();
    } else {
        tab = null;
    }
    sqLiteDatabase.close();
    return tab;
}

37. TabHandler#getAllTabs()

Project: AmazeFileManager
Source File: TabHandler.java
View license
public List<Tab> getAllTabs() {
    List<Tab> tabList = new ArrayList<Tab>();
    // Select all query
    String query = "Select * FROM " + TABLE_TAB;
    SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
    Cursor cursor = sqLiteDatabase.rawQuery(query, null);
    // Looping through all rows and adding them to list
    if (cursor.getCount() > 0 && cursor.moveToFirst()) {
        do {
            Tab tab = new Tab();
            tab.setTab((cursor.getInt(0)));
            tab.setPath(cursor.getString(1));
            tab.setHome(cursor.getString(2));
            //Adding them to list
            tabList.add(tab);
        } while (cursor.moveToNext());
    }
    sqLiteDatabase.close();
    return tabList;
}

38. AndlyticsDb#saveAdmobDetails()

Project: andlytics
Source File: AndlyticsDb.java
View license
public synchronized void saveAdmobDetails(String packageName, String admobAccount, String admobSiteId, String admobAdUnitId) {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        long id = findPackageId(db, packageName);
        ContentValues values = new ContentValues();
        values.put(AppInfoTable.KEY_APP_ADMOB_ACCOUNT, admobAccount);
        values.put(AppInfoTable.KEY_APP_ADMOB_SITE_ID, admobSiteId);
        values.put(AppInfoTable.KEY_APP_ADMOB_AD_UNIT_ID, admobAdUnitId);
        db.update(AppInfoTable.DATABASE_TABLE_NAME, values, "_id = ?", new String[] { Long.toString(id) });
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}

39. AndlyticsDb#saveAdmobAdUnitId()

Project: andlytics
Source File: AndlyticsDb.java
View license
public synchronized void saveAdmobAdUnitId(String packageName, String admobAccount, String admobAdUnitId) {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        long id = findPackageId(db, packageName);
        ContentValues values = new ContentValues();
        values.put(AppInfoTable.KEY_APP_ADMOB_ACCOUNT, admobAccount);
        values.put(AppInfoTable.KEY_APP_ADMOB_AD_UNIT_ID, admobAdUnitId);
        db.update(AppInfoTable.DATABASE_TABLE_NAME, values, "_id = ?", new String[] { Long.toString(id) });
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}

40. AndlyticsDb#saveLastCommentsRemoteUpdateTime()

Project: andlytics
Source File: AndlyticsDb.java
View license
public synchronized void saveLastCommentsRemoteUpdateTime(String packageName, long updateTime) {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        long id = findPackageId(db, packageName);
        ContentValues values = new ContentValues();
        values.put(AppInfoTable.KEY_APP_LAST_COMMENTS_UPDATE, updateTime);
        db.update(AppInfoTable.DATABASE_TABLE_NAME, values, "_id = ?", new String[] { Long.toString(id) });
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}

41. FileContentProvider#delete()

Project: android
Source File: FileContentProvider.java
View license
@Override
public int delete(Uri uri, String where, String[] whereArgs) {
    //Log_OC.d(TAG, "Deleting " + uri + " at provider " + this);
    int count = 0;
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        count = delete(db, uri, where, whereArgs);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}

42. FileContentProvider#insert()

Project: android
Source File: FileContentProvider.java
View license
@Override
public Uri insert(Uri uri, ContentValues values) {
    Uri newUri = null;
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        newUri = insert(db, uri, values);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    getContext().getContentResolver().notifyChange(newUri, null);
    return newUri;
}

43. FileContentProvider#query()

Project: android
Source File: FileContentProvider.java
View license
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor result = null;
    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    db.beginTransaction();
    try {
        result = query(db, uri, projection, selection, selectionArgs, sortOrder);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    return result;
}

44. FileContentProvider#update()

Project: android
Source File: FileContentProvider.java
View license
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int count = 0;
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        count = update(db, uri, values, selection, selectionArgs);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}

45. FileContentProvider#applyBatch()

Project: android
Source File: FileContentProvider.java
View license
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    Log_OC.d("FileContentProvider", "applying batch in provider " + this + " (temporary: " + isTemporary() + ")");
    ContentProviderResult[] results = new ContentProviderResult[operations.size()];
    int i = 0;
    SQLiteDatabase db = mDbHelper.getWritableDatabase();
    // it's supposed that transactions can be nested
    db.beginTransaction();
    try {
        for (ContentProviderOperation operation : operations) {
            results[i] = operation.apply(this, results, i);
            i++;
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    Log_OC.d("FileContentProvider", "applied batch in provider " + this);
    return results;
}

46. BaseContentProvider#bulkInsert()

View license
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    String table = uri.getLastPathSegment();
    SQLiteDatabase db = mSqLiteOpenHelper.getWritableDatabase();
    int res = 0;
    db.beginTransaction();
    try {
        for (ContentValues v : values) {
            long id = db.insert(table, null, v);
            db.yieldIfContendedSafely();
            if (id != -1) {
                res++;
            }
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    String notify;
    if (res != 0 && ((notify = uri.getQueryParameter(QUERY_NOTIFY)) == null || "true".equals(notify))) {
        getContext().getContentResolver().notifyChange(uri, null);
    }
    return res;
}

47. OrmaConnection#transactionNonExclusiveSync()

Project: Android-Orma
Source File: OrmaConnection.java
View license
public void transactionNonExclusiveSync(@NonNull Runnable task) {
    SQLiteDatabase db = getReadableDatabase();
    trace("begin transaction (non exclusive)", null);
    db.beginTransactionNonExclusive();
    try {
        task.run();
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        trace("end transaction (non exclusive)", null);
    }
}

48. OrmaConnection#transactionNonExclusiveSync()

Project: Android-Orma
Source File: OrmaConnection.java
View license
@Deprecated
public void transactionNonExclusiveSync(@NonNull TransactionTask task) {
    SQLiteDatabase db = getReadableDatabase();
    trace("begin transaction (non exclusive)", null);
    db.beginTransactionNonExclusive();
    try {
        task.execute();
        db.setTransactionSuccessful();
    } catch (Exception e) {
        task.onError(e);
    } finally {
        db.endTransaction();
        trace("end transaction (non exclusive)", null);
    }
}

49. OrmaConnection#transactionSync()

Project: Android-Orma
Source File: OrmaConnection.java
View license
@WorkerThread
public void transactionSync(@NonNull Runnable task) {
    SQLiteDatabase db = getWritableDatabase();
    trace("begin transaction", null);
    db.beginTransaction();
    try {
        task.run();
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        trace("end transaction", null);
    }
}

50. OrmaConnection#transactionSync()

Project: Android-Orma
Source File: OrmaConnection.java
View license
@Deprecated
@WorkerThread
public void transactionSync(@NonNull final TransactionTask task) {
    SQLiteDatabase db = getWritableDatabase();
    trace("begin transaction", null);
    db.beginTransaction();
    try {
        task.execute();
        db.setTransactionSuccessful();
    } catch (Exception e) {
        task.onError(e);
    } finally {
        db.endTransaction();
        trace("end transaction", null);
    }
}

51. AbstractMigrationEngineTest#testTransaction()

View license
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Test
public void testTransaction() throws Exception {
    MyEngine myEngine = new MyEngine();
    final SQLiteDatabase db = SQLiteDatabase.create(null);
    db.setForeignKeyConstraintsEnabled(true);
    assertThat(DatabaseUtils.longForQuery(db, "PRAGMA foreign_keys", null), is(1L));
    myEngine.transaction(db, new Runnable() {

        @Override
        public void run() {
            assertThat(DatabaseUtils.longForQuery(db, "PRAGMA foreign_keys", null), is(0L));
        }
    });
    assertThat(DatabaseUtils.longForQuery(db, "PRAGMA foreign_keys", null), is(1L));
}

52. OrmLiteDefaultContentProvider#applyBatch()

View license
/*
     * @see android.content.ContentProvider#applyBatch(java.util.ArrayList)
     * @since 1.0.1
     */
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    ContentProviderResult[] result = null;
    SQLiteDatabase db = this.getHelper().getWritableDatabase();
    db.beginTransaction();
    try {
        result = super.applyBatch(operations);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    return result;
}

53. DataSource#updateInUseFlag()

Project: android-proxy
Source File: DataSource.java
View license
public void updateInUseFlag() {
    App.getTraceUtils().startTrace(TAG, "updateInUseFlag", Log.DEBUG, true);
    SQLiteDatabase database = DatabaseSQLiteOpenHelper.getInstance(context).getWritableDatabase();
    database.beginTransaction();
    try {
        updateStaticInUseFlag(database);
        updatePacInUseFlag(database);
        database.setTransactionSuccessful();
    } catch (Exception e) {
        Timber.e(e, "Exception during updateInUseFlag");
    } finally {
        database.endTransaction();
    }
    App.getTraceUtils().stopTrace(TAG, "updateInUseFlag", Log.DEBUG);
}

54. MySQLiteHelper#updateBook()

View license
// Updating single book
public int updateBook(Book book) {
    // 1. get reference to writable DB
    SQLiteDatabase db = this.getWritableDatabase();
    // 2. create ContentValues to add key "column"/value
    ContentValues values = new ContentValues();
    // get title 
    values.put("title", book.getTitle());
    // get author
    values.put("author", book.getAuthor());
    // 3. updating row
    int i = //table
    db.update(//table
    TABLE_BOOKS, // column/value
    values, // selections
    KEY_ID + " = ?", //selection args
    new String[] { String.valueOf(book.getId()) });
    // 4. close
    db.close();
    return i;
}

55. TopekaDatabaseHelper#updateCategory()

View license
/**
     * Updates values for a category.
     *
     * @param context The context this is running in.
     * @param category The category to update.
     */
public static void updateCategory(Context context, Category category) {
    if (mCategories != null && mCategories.contains(category)) {
        final int location = mCategories.indexOf(category);
        mCategories.remove(location);
        mCategories.add(location, category);
    }
    SQLiteDatabase writableDatabase = getWritableDatabase(context);
    ContentValues categoryValues = createContentValuesFor(category);
    writableDatabase.update(CategoryTable.NAME, categoryValues, CategoryTable.COLUMN_ID + "=?", new String[] { category.getId() });
    final List<Quiz> quizzes = category.getQuizzes();
    updateQuizzes(writableDatabase, quizzes);
}

56. TagsManager#getTags()

Project: AndroidTagGroup
Source File: TagsManager.java
View license
public String[] getTags() {
    List<String> tagList = new ArrayList<>();
    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    Cursor c = db.query(TagsTable.TABLE_NAME, new String[] { TagsTable.TAG }, null, null, null, null, null);
    while (c.moveToNext()) {
        String tag = c.getString(c.getColumnIndex(TagsTable.TAG));
        tagList.add(tag);
    }
    c.close();
    db.close();
    return tagList.toArray(new String[] {});
}

57. AppContentProvider#insert()

View license
@Nullable
@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
    AppContentProviderEndpoint endpoint = AppContentProviderEndpoint.of(uri);
    SQLiteDatabase db = writableDatabase();
    final String nullColumnHack = null;
    db.replaceOrThrow(endpoint.tables(), nullColumnHack, values);
    notifyChange(uri);
    Uri itemUri = endpoint.itemUri(values);
    if (itemUri != null) {
        notifyChange(itemUri);
    }
    return itemUri;
}

58. DBHelper#insertUser()

Project: BriskPesa
Source File: DBHelper.java
View license
public long insertUser(String phone) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put("phone", phone);
    contentValues.put("status", 1);
    long affectedColumnId = db.insert("tbl_user", null, contentValues);
    db.close();
    return affectedColumnId;
}

59. DatabaseHelper#addHistoryRecord()

Project: browser-android
Source File: DatabaseHelper.java
View license
public void addHistoryRecord(HistoryRecord historyRecord) {
    if (Settings.get().isIncognitoMode() == true) {
        return;
    }
    Log.d(TAG, "addHistoryRecord() - " + historyRecord.toString());
    int existingId = getRecentHistoryRecordId(historyRecord.getUrl());
    // If there is a history record from the last 12 hours, just update that item
    if (existingId > -1) {
        historyRecord.setId(existingId);
        updateHistoryRecord(historyRecord);
        return;
    }
    SQLiteDatabase db = getWritableDatabase();
    try {
        db.insert(TABLE_LINK_HISTORY, null, getContentValues(historyRecord));
        CrashTracking.log("DatabaseHelper.addHistoryRecord() success");
    } catch (IllegalStateException ex) {
        CrashTracking.log("DatabaseHelper.addHistoryRecord() IllegalStateException");
    }
    db.close();
}

60. DatabaseHelper#updateHistoryRecord()

Project: browser-android
Source File: DatabaseHelper.java
View license
public void updateHistoryRecord(HistoryRecord historyRecord) {
    SQLiteDatabase db = getWritableDatabase();
    try {
        ContentValues values = getContentValues(historyRecord);
        String id = String.valueOf(historyRecord.getId());
        db.update(TABLE_LINK_HISTORY, values, KEY_ID + " = ?", new String[] { id });
        CrashTracking.log("DatabaseHelper.updateHistoryRecord() success, id:" + id);
    } catch (IllegalStateException ex) {
        CrashTracking.log("DatabaseHelper.addHistoryRecord() IllegalStateException");
    }
    db.close();
}

61. DatabaseHelper#deleteHistoryRecord()

Project: browser-android
Source File: DatabaseHelper.java
View license
public boolean deleteHistoryRecord(HistoryRecord historyRecord) {
    boolean result = false;
    SQLiteDatabase db = getWritableDatabase();
    try {
        String id = String.valueOf(historyRecord.getId());
        db.delete(TABLE_LINK_HISTORY, KEY_ID + " = ?", new String[] { id });
        result = true;
        Log.d(TAG, "deleted historyRecord:" + historyRecord.toString());
        CrashTracking.log("DatabaseHelper.deleteHistoryRecord() success, id:" + id);
    } catch (IllegalStateException ex) {
        CrashTracking.log("DatabaseHelper.deleteHistoryRecord() IllegalStateException");
    }
    db.close();
    return result;
}

62. DatabaseHelper#deleteFavicon()

Project: browser-android
Source File: DatabaseHelper.java
View license
private void deleteFavicon(long id) {
    SQLiteDatabase db = getWritableDatabase();
    try {
        String idAsString = String.valueOf(id);
        db.delete(TABLE_FAVICON_CACHE, KEY_ID + " = ?", new String[] { idAsString });
        CrashTracking.log("DatabaseHelper.deleteFavicon() success, id:" + idAsString);
    } catch (IllegalStateException ex) {
        CrashTracking.log("DatabaseHelper.deleteFavicon(): IllegalStateException");
    }
    db.close();
    Log.d(TAG, "deleteFavicon() - id:" + id);
}

63. DailyModel#getDailyGsonDB()

Project: BuildingBlocks
Source File: DailyModel.java
View license
private DailyGson getDailyGsonDB(int id) {
    SQLiteDatabase database = mSQLiteHelper.getReadableDatabase();
    Cursor cursor = database.rawQuery("SELECT * FROM daily where id = ?", new String[] { id + "" });
    DailyGson dailyGson = new DailyGson();
    if (cursor.moveToFirst()) {
        dailyGson.id = cursor.getInt(cursor.getColumnIndex("id"));
        dailyGson.title = cursor.getString(cursor.getColumnIndex("title"));
        dailyGson.type = cursor.getInt(cursor.getColumnIndex("type"));
        dailyGson.image_source = cursor.getString(cursor.getColumnIndex("image_source"));
        dailyGson.image = cursor.getString(cursor.getColumnIndex("image"));
        dailyGson.share_url = cursor.getString(cursor.getColumnIndex("share_url"));
        dailyGson.ga_prefix = cursor.getInt(cursor.getColumnIndex("ga_prefix"));
        dailyGson.body = cursor.getString(cursor.getColumnIndex("body"));
        cursor.close();
        mIGsonCallBack.onGsonItemFinish(dailyGson);
        database.close();
        return dailyGson;
    }
    database.close();
    return null;
}

64. DailyModel#saveDailyStoriesDB()

Project: BuildingBlocks
Source File: DailyModel.java
View license
private void saveDailyStoriesDB(DailyResult dailyResult) {
    SQLiteDatabase database = mSQLiteHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    for (Daily story : dailyResult.stories) {
        values.put("date", dailyResult.date);
        values.put("id", story.id);
        values.put("title", story.title);
        values.put("image", story.images.get(0));
        values.put("type", story.type);
        values.put("ga_prefix", story.ga_prefix);
        database.insertWithOnConflict("dailyresult", null, values, SQLiteDatabase.CONFLICT_IGNORE);
    }
    database.close();
    Calendar calendar = Calendar.getInstance();
    try {
        calendar.setTime(Constants.simpleDateFormat.parse(dailyResult.date + ""));
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    getDailyStoriesDB(Integer.parseInt(Constants.simpleDateFormat.format(calendar.getTime())));
}

65. EmoticonDBHelper#insertEmoticonBeans()

Project: ChatKeyboard
Source File: EmoticonDBHelper.java
View license
public synchronized long insertEmoticonBeans(ContentValues[] values) {
    SQLiteDatabase db = mOpenDbHelper.getWritableDatabase();
    db.beginTransaction();
    int insertSuccessCount = values.length;
    try {
        for (ContentValues cv : values) {
            if (db.insert(TABLE_NAME_EMOTICONS, null, cv) < 0) {
                insertSuccessCount--;
            }
        }
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e("Keyboard", "insert error", e);
    } finally {
        db.endTransaction();
    }
    return insertSuccessCount;
}

66. DBManager#getAllCities()

Project: CityPicker
Source File: DBManager.java
View license
/**
     * ??????
     * @return
     */
public List<City> getAllCities() {
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
    Cursor cursor = db.rawQuery("select * from " + TABLE_NAME, null);
    List<City> result = new ArrayList<>();
    City city;
    while (cursor.moveToNext()) {
        String name = cursor.getString(cursor.getColumnIndex(NAME));
        String pinyin = cursor.getString(cursor.getColumnIndex(PINYIN));
        city = new City(name, pinyin);
        result.add(city);
    }
    cursor.close();
    db.close();
    Collections.sort(result, new CityComparator());
    return result;
}

67. DBManager#searchCity()

Project: CityPicker
Source File: DBManager.java
View license
/**
     * ??????????
     * @param keyword
     * @return
     */
public List<City> searchCity(final String keyword) {
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(DB_PATH + DB_NAME, null);
    Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + " where name like \"%" + keyword + "%\" or pinyin like \"%" + keyword + "%\"", null);
    List<City> result = new ArrayList<>();
    City city;
    while (cursor.moveToNext()) {
        String name = cursor.getString(cursor.getColumnIndex(NAME));
        String pinyin = cursor.getString(cursor.getColumnIndex(PINYIN));
        city = new City(name, pinyin);
        result.add(city);
    }
    cursor.close();
    db.close();
    Collections.sort(result, new CityComparator());
    return result;
}

68. PubkeyDatabase#findPubkeyById()

Project: connectbot
Source File: PubkeyDatabase.java
View license
/**
	 * @param hostId
	 * @return
	 */
public PubkeyBean findPubkeyById(long pubkeyId) {
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.query(TABLE_PUBKEYS, null, "_id = ?", new String[] { String.valueOf(pubkeyId) }, null, null, null);
    PubkeyBean pubkey = null;
    if (c != null) {
        if (c.moveToFirst())
            pubkey = createPubkeyBean(c);
        c.close();
    }
    db.close();
    return pubkey;
}

69. PubkeyDatabase#allValues()

Project: connectbot
Source File: PubkeyDatabase.java
View license
/**
	 * Pull all values for a given column as a list of Strings, probably for use
	 * in a ListPreference. Sorted by <code>_id</code> ascending.
	 */
public List<CharSequence> allValues(String column) {
    List<CharSequence> list = new LinkedList<CharSequence>();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.query(TABLE_PUBKEYS, new String[] { "_id", column }, null, null, null, null, "_id ASC");
    if (c != null) {
        int COL = c.getColumnIndexOrThrow(column);
        while (c.moveToNext()) list.add(c.getString(COL));
        c.close();
    }
    db.close();
    return list;
}

70. PubkeyDatabase#getNickname()

Project: connectbot
Source File: PubkeyDatabase.java
View license
public String getNickname(long id) {
    String nickname = null;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.query(TABLE_PUBKEYS, new String[] { "_id", FIELD_PUBKEY_NICKNAME }, "_id = ?", new String[] { Long.toString(id) }, null, null, null);
    if (c != null) {
        if (c.moveToFirst())
            nickname = c.getString(c.getColumnIndexOrThrow(FIELD_PUBKEY_NICKNAME));
        c.close();
    }
    db.close();
    return nickname;
}

71. PubkeyDatabase#savePubkey()

Project: connectbot
Source File: PubkeyDatabase.java
View license
/*
	public void setOnStart(long id, boolean onStart) {

		SQLiteDatabase db = this.getWritableDatabase();

		ContentValues values = new ContentValues();
		values.put(FIELD_PUBKEY_STARTUP, onStart ? 1 : 0);

		db.update(TABLE_PUBKEYS, values, "_id = ?", new String[] { Long.toString(id) });

	}

	public boolean changePassword(long id, String oldPassword, String newPassword) throws NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException {
		SQLiteDatabase db = this.getWritableDatabase();

		Cursor c = db.query(TABLE_PUBKEYS, new String[] { FIELD_PUBKEY_TYPE,
				FIELD_PUBKEY_PRIVATE, FIELD_PUBKEY_ENCRYPTED },
				"_id = ?", new String[] { String.valueOf(id) },
				null, null, null);

		if (!c.moveToFirst())
			return false;

		String keyType = c.getString(0);
		byte[] encPriv = c.getBlob(1);
		c.close();

		PrivateKey priv;
		try {
			priv = PubkeyUtils.decodePrivate(encPriv, keyType, oldPassword);
		} catch (InvalidKeyException e) {
			return false;
		} catch (BadPaddingException e) {
			return false;
		} catch (InvalidKeySpecException e) {
			return false;
		}

		ContentValues values = new ContentValues();
		values.put(FIELD_PUBKEY_PRIVATE, PubkeyUtils.getEncodedPrivate(priv, newPassword));
		values.put(FIELD_PUBKEY_ENCRYPTED, newPassword.length() > 0 ? 1 : 0);
		db.update(TABLE_PUBKEYS, values, "_id = ?", new String[] { String.valueOf(id) });

		return true;
	}
	*/
/**
	 * @param pubkey
	 */
public PubkeyBean savePubkey(PubkeyBean pubkey) {
    SQLiteDatabase db = this.getWritableDatabase();
    boolean success = false;
    ContentValues values = pubkey.getValues();
    if (pubkey.getId() > 0) {
        values.remove("_id");
        if (db.update(TABLE_PUBKEYS, values, "_id = ?", new String[] { String.valueOf(pubkey.getId()) }) > 0)
            success = true;
    }
    if (!success) {
        long id = db.insert(TABLE_PUBKEYS, null, pubkey.getValues());
        pubkey.setId(id);
    }
    db.close();
    return pubkey;
}

72. DarshakDBHelper#updateSentinelPacket()

Project: darshak
Source File: DarshakDBHelper.java
View license
public int updateSentinelPacket(SentinelPacket sentinelPacket) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues dbValues = new ContentValues();
    dbValues.put(DatabaseSchema.SentinelPacketScehama.BYTE_SEQ, sentinelPacket.getByteSequence());
    String whereClause = DatabaseSchema.SentinelPacketScehama.SCAN_TYPE + " = " + String.valueOf(sentinelPacket.getScanType());
    whereClause = whereClause.intern();
    return db.update(DatabaseSchema.SentinelPacketScehama.TABLE_NAME, dbValues, whereClause, null);
}

73. DarshakDBHelper#deleteLogEntry()

Project: darshak
Source File: DarshakDBHelper.java
View license
public void deleteLogEntry(long uid) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues dbValues = new ContentValues();
    dbValues.put(DatabaseSchema.LogEntrySchema.IS_DELETED, 1);
    String whereClause = DatabaseSchema.LogEntrySchema.UID + " = " + String.valueOf(uid);
    whereClause = whereClause.intern();
    db.update(DatabaseSchema.LogEntrySchema.TABLE_NAME, dbValues, whereClause, null);
    Log.d(LOG_TAG, "Deleted Log entry from database : " + uid);
}

74. DarshakDBHelper#consumeEventDetails()

Project: darshak
Source File: DarshakDBHelper.java
View license
private void consumeEventDetails(EventDetails eventDetails) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues dbValues = new ContentValues();
    dbValues.put(DatabaseSchema.CellularEvent.EVENT_CONSUMED, 1);
    String whereClause = DatabaseSchema.CellularEvent.EVENT_UID + " = " + String.valueOf(eventDetails.getUid());
    whereClause = whereClause.intern();
    whereClause = whereClause.intern();
    db.update(DatabaseSchema.CellularEvent.TABLE_NAME, dbValues, whereClause, null);
    Log.e(LOG_TAG, "Marked event as consumed : " + eventDetails);
}

75. EventDetailsDBHandler#getCount()

View license
public int getCount() {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    int count = 0;
    while (!c.isAfterLast()) {
        count++;
        c.moveToNext();
    }
    c.close();
    db.close();
    return count;
}

76. EventDetailsDBHandler#getEventData()

View license
public String[] getEventData(int id) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_ID + " ='" + String.valueOf(id) + "';";
    String[] eventColumnData = new String[12];
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    eventColumnData[0] = c.getString(c.getColumnIndex(COLUMN_NAME));
    eventColumnData[1] = c.getString(c.getColumnIndex(COLUMN_PLACE));
    eventColumnData[2] = c.getString(c.getColumnIndex(COLUMN_START_DATE_TIME));
    eventColumnData[3] = c.getString(c.getColumnIndex(COLUMN_END_DATE_TIME));
    eventColumnData[4] = c.getString(c.getColumnIndex(COLUMN_REPETITION));
    eventColumnData[5] = c.getString(c.getColumnIndex(COLUMN_TYPE));
    eventColumnData[6] = c.getString(c.getColumnIndex(COLUMN_COMMENTS));
    eventColumnData[7] = c.getString(c.getColumnIndex(COLUMN_REGN_PLACE));
    eventColumnData[8] = c.getString(c.getColumnIndex(COLUMN_WEBSITE));
    eventColumnData[9] = c.getString(c.getColumnIndex(COLUMN_DEADLINE_DATE_TIME));
    eventColumnData[10] = c.getString(c.getColumnIndex(COLUMN_STARTS_FROM));
    eventColumnData[11] = c.getString(c.getColumnIndex(COLUMN_ENDS_ON));
    c.close();
    db.close();
    return eventColumnData;
}

77. EventFiltersDBHandler#updateRow()

View license
public void updateRow(EventFilter eventFilter) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_FILTER_NAME + "='" + eventFilter.getFilterName() + "' AND " + COLUMN_FILTER_TYPE + "='" + eventFilter.getFilterType() + "'" + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    if (!c.isAfterLast()) {
        int id = Integer.parseInt(c.getString(c.getColumnIndex(COLUMN_ID)));
        ContentValues values = new ContentValues();
        values.put(COLUMN_FILTER_NAME, eventFilter.getFilterName());
        values.put(COLUMN_FILTER_TYPE, eventFilter.getFilterType());
        values.put(COLUMN_IS_APPLIED, eventFilter.isChecked());
        String where = COLUMN_ID + "='" + id + "'";
        db.update(TABLE_NAME, values, where, null);
    } else {
        this.insertRow(eventFilter);
    }
    db.close();
}

78. EventFiltersDBHandler#isFilterChecked()

View license
public boolean isFilterChecked(int id) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_ID + "='" + id + "';";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    boolean ans = false;
    if (!c.isAfterLast()) {
        if (c.getString(c.getColumnIndex(COLUMN_IS_APPLIED)).matches("1"))
            ans = true;
    }
    c.close();
    db.close();
    return ans;
}

79. EventFiltersDBHandler#viewTable()

View license
public String viewTable() {
    String dbString = "";
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    while (!c.isAfterLast()) {
        dbString += c.getString(c.getColumnIndex(COLUMN_ID));
        dbString += ",";
        dbString += c.getString(c.getColumnIndex(COLUMN_FILTER_NAME));
        dbString += ",";
        dbString += c.getString(c.getColumnIndex(COLUMN_FILTER_TYPE));
        dbString += ",";
        dbString += c.getString(c.getColumnIndex(COLUMN_IS_APPLIED));
        dbString += ".";
        dbString += "\n";
        c.moveToNext();
    }
    c.close();
    db.close();
    return dbString;
}

80. OnlineEventDetailsDBHandler#getObjectWith()

View license
/**
     * The SEARCH KEY VALUE SHOULD BE SUCH THAT AT MOST ONE ROW SATISFYING THAT CONDITION EXISTS
     */
public OnlineEventDetails getObjectWith(String NAME_OF_COLUMN, String Value) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + NAME_OF_COLUMN + " ='" + Value + "';";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    if (!c.isAfterLast()) {
        OnlineEventDetails ret = new OnlineEventDetails(c);
        c.close();
        db.close();
        return ret;
    }
    c.close();
    db.close();
    return null;
}

81. OnlineEventDetailsDBHandler#getAllObjectsWith()

View license
public Vector<OnlineEventDetails> getAllObjectsWith(String NAME_OF_COLUMN, String Value) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + NAME_OF_COLUMN + " ='" + Value + "';";
    Vector<OnlineEventDetails> retVector = new Vector<>();
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    while (!c.isAfterLast()) {
        OnlineEventDetails row = new OnlineEventDetails(c);
        retVector.add(row);
        c.moveToNext();
    }
    c.close();
    db.close();
    return retVector;
}

82. OnlineEventDetailsDBHandler#areObjectWith()

View license
public boolean areObjectWith(String NAME_OF_COLUMN, String Value) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + NAME_OF_COLUMN + " ='" + Value + "';";
    ;
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    if (!c.isAfterLast()) {
        c.close();
        db.close();
        return true;
    }
    c.close();
    db.close();
    return false;
}

83. OnlineEventDetailsDBHandler#getCount()

View license
public int getCount() {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    int count = 0;
    while (!c.isAfterLast()) {
        count++;
        c.moveToNext();
    }
    c.close();
    db.close();
    return count;
}

84. OnlineEventDetailsDBHandler#getSQLiteID()

View license
public int getSQLiteID(int eeVeeID) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_EEVEE_ID + " ='" + eeVeeID + "';";
    int SQLiteID = 0;
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    if (!c.isAfterLast()) {
        SQLiteID = Integer.parseInt(c.getString(c.getColumnIndex(COLUMN_ID)));
    }
    c.close();
    db.close();
    return SQLiteID;
}

85. TaskDetailsDBHandler#getCount()

View license
public int getCount() {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    int count = 0;
    while (!c.isAfterLast()) {
        count++;
        c.moveToNext();
    }
    c.close();
    db.close();
    return count;
}

86. TaskDetailsDBHandler#returnWithConstraint()

View license
public String returnWithConstraint(String SEARCH, String MATCH, String RETURN) {
    String dbString = "";
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    // The order is referred to in initializing TaskViewCompact Objects in TaskHome activity
    while (!c.isAfterLast()) {
        if (MATCH == c.getString(c.getColumnIndex(SEARCH))) {
            dbString += c.getString(c.getColumnIndex(RETURN));
            dbString += ",";
        }
        c.moveToNext();
    }
    c.close();
    db.close();
    return dbString;
}

87. TaskDetailsDBHandler#getTaskData()

View license
public String[] getTaskData(int id) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_ID + " ='" + String.valueOf(id) + "';";
    String[] taskColumnData = new String[8];
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    taskColumnData[0] = c.getString(c.getColumnIndex(COLUMN_DESCRIPTION));
    taskColumnData[1] = c.getString(c.getColumnIndex(COLUMN_TAG));
    taskColumnData[2] = c.getString(c.getColumnIndex(COLUMN_START_DATE_TIME));
    taskColumnData[3] = c.getString(c.getColumnIndex(COLUMN_END_DATE_TIME));
    taskColumnData[4] = c.getString(c.getColumnIndex(COLUMN_REPETITION));
    taskColumnData[5] = c.getString(c.getColumnIndex(COLUMN_TYPE));
    taskColumnData[6] = c.getString(c.getColumnIndex(COLUMN_STARTS_FROM));
    taskColumnData[7] = c.getString(c.getColumnIndex(COLUMN_ENDS_ON));
    c.close();
    db.close();
    return taskColumnData;
}

88. UserDetailsDBHandler#setStaticUserDetails()

View license
/**
     * As you increase no Columns this function increases
     */
public void setStaticUserDetails() {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    UserDetails.$USERNAME = c.getString(c.getColumnIndex(COLUMN_USER_NAME));
    if (c.getString(c.getColumnIndex(COLUMN_MALE)) == "1") {
        UserDetails.$IS_MALE = true;
    } else {
        UserDetails.$IS_MALE = false;
    }
    UserDetails.$USERGROUP = c.getString(c.getColumnIndex(COLUMN_SUBSCRIPTION));
    c.close();
    db.close();
}

89. UserDetailsDBHandler#getUserDetails()

View license
/**
     * returns the first row of the table
     */
public UserDetails getUserDetails() {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    if (!c.isAfterLast()) {
        UserDetails userDetails = new UserDetails(c);
        return userDetails;
    }
    c.close();
    db.close();
    return null;
}

90. UserDetailsDBHandler#deleteRow()

View license
public void deleteRow(String userName) {
    SQLiteDatabase db = getWritableDatabase();
    Cursor ptr = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + COLUMN_USER_NAME + "='" + userName + "'", null);
    if (ptr.moveToFirst()) {
        // Deleting record if found
        while (!ptr.isAfterLast()) {
            db.execSQL("DELETE FROM " + TABLE_NAME + " WHERE " + COLUMN_USER_NAME + "='" + userName + "';");
            ptr.moveToNext();
        }
        ptr.close();
    }
    db.close();
}

91. UserDetailsDBHandler#getCount()

View license
public int getCount() {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    int count = 0;
    while (!c.isAfterLast()) {
        count++;
        c.moveToNext();
    }
    c.close();
    db.close();
    return count;
}

92. WebEventDetailsDBHandler#getObjectWith()

View license
public WebEventDetails getObjectWith(String NAME_OF_COLUMN, String Value) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + NAME_OF_COLUMN + " ='" + Value + "';";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    if (!c.isAfterLast()) {
        WebEventDetails ret = new WebEventDetails(c);
        c.close();
        db.close();
        return ret;
    }
    c.close();
    db.close();
    return null;
}

93. WebEventDetailsDBHandler#areObjectWith()

View license
public boolean areObjectWith(String NAME_OF_COLUMN, String Value) {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + NAME_OF_COLUMN + " ='" + Value + "';";
    ;
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    if (!c.isAfterLast()) {
        c.close();
        db.close();
        return true;
    }
    c.close();
    db.close();
    return false;
}

94. WebEventDetailsDBHandler#getCount()

View license
public int getCount() {
    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + ";";
    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();
    int count = 0;
    while (!c.isAfterLast()) {
        count++;
        c.moveToNext();
    }
    c.close();
    db.close();
    return count;
}

95. Database#clearStatuses()

Project: fanfouapp-opensource
Source File: Database.java
View license
public long clearStatuses() {
    long result = -1;
    final SQLiteDatabase db = this.mSQLiteHelper.getWritableDatabase();
    try {
        result = db.delete(StatusInfo.TABLE_NAME, null, null);
    } catch (final Exception e) {
        e.printStackTrace();
        result = -1;
    }
    db.close();
    return result;
}

96. Database#queryUsers()

Project: fanfouapp-opensource
Source File: Database.java
View license
// select id from status order by created_at desc limit 5,3;
// ??????? limit offset,count
// ?? limit 5,3 ??????5???????3
public List<User> queryUsers(final int count, final int offset) {
    log("queryUsers() count=" + count + " offset=" + offset);
    String limit = null;
    if (count > 0) {
        if (offset > 0) {
            limit = String.valueOf(offset) + " ," + String.valueOf(count);
        } else {
            limit = String.valueOf(count);
        }
    }
    final List<User> users = new ArrayList<User>();
    final SQLiteDatabase db = this.mSQLiteHelper.getWritableDatabase();
    final Cursor c = db.query(UserInfo.TABLE_NAME, UserInfo.COLUMNS, null, null, null, null, null, limit);
    c.moveToFirst();
    while (!c.isAfterLast()) {
        final User u = User.parse(c);
        log("queryUsers() get user: id=" + u.id);
        users.add(u);
        c.moveToNext();
    }
    db.close();
    log("queryUsers() result count=" + users.size());
    return users;
}

97. FanFouProvider#bulkInsertData()

View license
private int bulkInsertData(final String table, final ContentValues[] values) {
    int numInserted = 0;
    final SQLiteDatabase db = this.dbHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        for (final ContentValues value : values) {
            final long result = db.insert(table, null, value);
            if (result > -1) {
                numInserted++;
            }
        }
        if (AppContext.DEBUG) {
            log("bulkInsertData insert rows=" + numInserted);
        }
        db.setTransactionSuccessful();
    } catch (final Exception e) {
        if (AppContext.DEBUG) {
            e.printStackTrace();
        }
    } finally {
        db.endTransaction();
    }
    return numInserted;
}

98. FanFouProvider#cleanHome()

View license
private int cleanHome(final String count) {
    String where = " " + BasicColumns.CREATED_AT + " < " + " (SELECT " + BasicColumns.CREATED_AT + " FROM " + StatusInfo.TABLE_NAME;
    where += " WHERE " + BasicColumns.TYPE + " = " + Constants.TYPE_STATUSES_HOME_TIMELINE;
    where += " ORDER BY " + BasicColumns.CREATED_AT + " DESC LIMIT 1 OFFSET " + count + " )";
    where += " AND " + BasicColumns.TYPE + " = " + Constants.TYPE_STATUSES_HOME_TIMELINE + " ";
    // log("cleanHome where: [" + where + "]");
    final SQLiteDatabase db = this.dbHelper.getWritableDatabase();
    return db.delete(StatusInfo.TABLE_NAME, where, null);
}

99. FanFouProvider#cleanMentions()

View license
private int cleanMentions(final String count) {
    String where = " " + BasicColumns.CREATED_AT + " < " + " (SELECT " + BasicColumns.CREATED_AT + " FROM " + StatusInfo.TABLE_NAME;
    where += " WHERE " + BasicColumns.TYPE + " = " + Constants.TYPE_STATUSES_MENTIONS;
    where += " ORDER BY " + BasicColumns.CREATED_AT + " DESC LIMIT 1 OFFSET " + count + " )";
    where += " AND " + BasicColumns.TYPE + " = " + Constants.TYPE_STATUSES_MENTIONS + " ";
    // log("cleanMentions where: [" + where + "]");
    final SQLiteDatabase db = this.dbHelper.getWritableDatabase();
    return db.delete(StatusInfo.TABLE_NAME, where, null);
}

100. FanFouProvider#cleanMessages()

View license
private int cleanMessages(final String count) {
    String where = " " + BasicColumns.CREATED_AT + " < " + " (SELECT " + BasicColumns.CREATED_AT + " FROM " + DirectMessageInfo.TABLE_NAME;
    where += " ORDER BY " + BasicColumns.CREATED_AT + " DESC LIMIT 1 OFFSET " + count + " )";
    // log("cleanMentions where: [" + where + "]");
    final SQLiteDatabase db = this.dbHelper.getWritableDatabase();
    return db.delete(DirectMessageInfo.TABLE_NAME, where, null);
}