android.database.sqlite.SQLiteDatabase

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

1. 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);
}

2. 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);
}

3. 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();
}

4. 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();
}

5. 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();
}

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. 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();
}

11. 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());
}

12. 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);
}

13. 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();
}

14. 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();
}

15. 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();
}

16. 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();
}

17. 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();
}

18. 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();
}

19. 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();
}

20. 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");
}

21. 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);
}

22. 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();
}

23. 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();
}

24. 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();
}

25. 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();
}

26. 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();
}

27. 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();
}

28. 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();
}

29. 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();
}

30. 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();
}

31. 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;
}

32. 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;
}

33. 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;
}

34. 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;
}

35. 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();
}

36. 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;
}

37. 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;
}

38. 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;
}

39. 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;
}

40. 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;
}

41. 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;
}

42. 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;
}

43. 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;
}

44. 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;
}

45. 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;
}

46. 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();
}

47. 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;
}

48. 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();
}

49. 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;
}

50. 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;
}

51. 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;
}

52. 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;
}

53. 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;
}

54. 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;
}

55. GalleryStore#setChosenUris()

Project: muzei
Source File: GalleryStore.java
View license
public synchronized void setChosenUris(List<Uri> chosenUris) {
    SQLiteDatabase db = mDatabase.getWritableDatabase();
    db.beginTransaction();
    try {
        db.delete(Tables.CHOSEN_PHOTOS, null, null);
        ContentValues values = new ContentValues();
        for (Uri uri : chosenUris) {
            values.put(MetadataCache.URI, uri.toString());
            db.insertOrThrow(Tables.CHOSEN_PHOTOS, null, values);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        db.close();
    }
}

56. GalleryStore#putCachedMetadata()

Project: muzei
Source File: GalleryStore.java
View license
public synchronized void putCachedMetadata(Uri uri, Metadata metadata) {
    SQLiteDatabase db = mDatabase.getWritableDatabase();
    db.beginTransaction();
    try {
        ContentValues values = new ContentValues();
        values.put(MetadataCache.URI, uri.toString());
        values.put(MetadataCache.DATETIME, metadata.datetime);
        values.put(MetadataCache.LOCATION, metadata.location);
        values.put(MetadataCache.VERSION, metadata.version);
        db.insertOrThrow(Tables.METADATA_CACHE, null, values);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        db.close();
    }
}

57. FileContentProvider#delete()

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;
}

58. FileContentProvider#insert()

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;
}

59. FileContentProvider#query()

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;
}

60. FileContentProvider#update()

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;
}

61. FileContentProvider#applyBatch()

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;
}

62. DataProvider#applyBatch()

Project: narrate-android
Source File: DataProvider.java
View license
/**
     * Apply the given set of {@link ContentProviderOperation}, executing inside
     * a {@link SQLiteDatabase} transaction. All changes will be rolled back if
     * any single one fails.
     */
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        final int numOperations = operations.size();
        final ContentProviderResult[] results = new ContentProviderResult[numOperations];
        for (int i = 0; i < numOperations; i++) {
            results[i] = operations.get(i).apply(this, results, i);
        }
        db.setTransactionSuccessful();
        return results;
    } finally {
        db.endTransaction();
    }
}

63. PlacesDao#addPlace()

Project: narrate-android
Source File: PlacesDao.java
View license
private static boolean addPlace(String name, double lat, double lng) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    long result = 0;
    try {
        ContentValues args = new ContentValues();
        args.put(NAME, name);
        args.put(LATITUDE, lat);
        args.put(LONGITUDE, lng);
        result = db.insert(PLACES, null, args);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        LogUtil.log("EntriesDao", "Error addEntry() - " + e);
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

64. PlacesDao#updatePlace()

Project: narrate-android
Source File: PlacesDao.java
View license
private static boolean updatePlace(String name, double lat, double lng) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    int result = 0;
    try {
        ContentValues args = new ContentValues();
        args.put(NAME, name);
        args.put(LATITUDE, lat);
        args.put(LONGITUDE, lng);
        result = db.update(PLACES, args, NAME + "=?", new String[] { name });
        db.setTransactionSuccessful();
    } catch (Exception e) {
        LogUtil.e("EntriesDao", "Error updateEntry() - " + e);
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

65. RemindersDao#deleteReminder()

Project: narrate-android
Source File: RemindersDao.java
View license
public static boolean deleteReminder(Reminder reminder) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    int result = 0;
    try {
        result = db.delete(REMINDERS, UUID + "=?", new String[] { reminder.uuid });
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
        LogUtil.e("RemindersDao", "Error deleteReminder() - " + e);
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

66. RemindersDao#addReminder()

Project: narrate-android
Source File: RemindersDao.java
View license
private static boolean addReminder(Reminder reminder) {
    LogUtil.log("RemindersDao", "addReminder()");
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    long result = 0;
    try {
        ContentValues args = toValues(reminder);
        result = db.insert(REMINDERS, null, args);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        LogUtil.e("RemindersDao", "Error addReminder() - " + e);
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

67. RemindersDao#updateReminder()

Project: narrate-android
Source File: RemindersDao.java
View license
private static boolean updateReminder(Reminder reminder) {
    LogUtil.log("RemindersDao", "updateReminder()");
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    int result = 0;
    try {
        ContentValues values = toValues(reminder);
        result = db.update(REMINDERS, values, UUID + "=?", new String[] { reminder.uuid });
        db.setTransactionSuccessful();
    } catch (Exception e) {
        LogUtil.e("RemindersDao", "Error updateReminder() - " + e);
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

68. TagsDao#addTag()

Project: narrate-android
Source File: TagsDao.java
View license
private static boolean addTag(String tag) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    long result = 0;
    try {
        ContentValues args = new ContentValues();
        args.put(TAG, tag);
        result = db.insert(TAGS, null, args);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        LogUtil.log("EntriesDao", "Error addEntry() - " + e);
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

69. TagsDao#updateTag()

Project: narrate-android
Source File: TagsDao.java
View license
private static boolean updateTag(String tag) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    int result = 0;
    try {
        ContentValues args = new ContentValues();
        args.put(TAG, tag);
        result = db.update(TAGS, args, TAG + "=?", new String[] { tag });
        db.setTransactionSuccessful();
    } catch (Exception e) {
        LogUtil.e("EntriesDao", "Error updateEntry() - " + e);
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

70. PendingSyncCall#save()

View license
public static boolean save(PendingSyncCall call) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    long result = 0;
    try {
        ContentValues args = new ContentValues();
        args.put(SERVICE, call.service.getInternalValue());
        args.put(OPERATION, call.operation.getInternalValue());
        args.put(NAME, call.name);
        args.put(TIME, call.time.getTime());
        args.put(SERVICE_FILE_ID, call.serviceFileId);
        result = db.insert(PENDING_SYNC_CALLS, null, args);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

71. PendingSyncCall#delete()

View license
public static boolean delete(SyncService service, String fileId) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    int result = 0;
    try {
        result = db.delete(PENDING_SYNC_CALLS, SERVICE + "=? AND " + SERVICE + "=?", new String[] { String.valueOf(service.ordinal()), fileId });
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

72. PendingSyncCall#delete()

View license
public static boolean delete(String name) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    int result = 0;
    try {
        result = db.delete(PENDING_SYNC_CALLS, NAME + "=?", new String[] { name });
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

73. PendingSyncCall#deleteAll()

View license
public static boolean deleteAll(SyncService service, String name) {
    SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getWritableDatabase();
    db.beginTransaction();
    int result = 0;
    try {
        result = db.delete(PENDING_SYNC_CALLS, SERVICE + "=? AND " + NAME + "=?", new String[] { String.valueOf(service.ordinal()), name });
        db.setTransactionSuccessful();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
    }
    return result > 0;
}

74. DBFreshTest#testFreshInstall()

Project: NotePad
Source File: DBFreshTest.java
View license
@SmallTest
public void testFreshInstall() {
    context.deleteDatabase(PREFIX + LegacyDBHelper.LEGACY_DATABASE_NAME);
    context.deleteDatabase(PREFIX + DatabaseHandler.DATABASE_NAME);
    final SQLiteDatabase db = new DatabaseHandler(context, PREFIX).getReadableDatabase();
    // Just open the database, there should be one list and one task present
    Cursor tlc = db.query(TaskList.TABLE_NAME, TaskList.Columns.FIELDS, null, null, null, null, null);
    assertEquals("Should be ONE list present on fresh installs", 1, tlc.getCount());
    tlc.close();
    Cursor tc = db.query(Task.TABLE_NAME, Task.Columns.FIELDS, null, null, null, null, null);
    assertEquals("Should be NO task present on fresh installs", 0, tc.getCount());
    tc.close();
    db.close();
    assertTrue("Could not delete database", context.deleteDatabase(PREFIX + LegacyDBHelper.LEGACY_DATABASE_NAME));
    assertTrue("Could not delete database", context.deleteDatabase(PREFIX + DatabaseHandler.DATABASE_NAME));
}

75. DbHelper#deleteCategory()

Project: Omni-Notes
Source File: DbHelper.java
View license
/**
     * Deletion of  a category
     *
     * @param category Category to be deleted
     * @return Number 1 if category's record has been deleted, 0 otherwise
     */
public long deleteCategory(Category category) {
    long deleted;
    SQLiteDatabase db = getDatabase(true);
    // Un-categorize notes associated with this category
    ContentValues values = new ContentValues();
    values.put(KEY_CATEGORY, "");
    // Updating row
    db.update(TABLE_NOTES, values, KEY_CATEGORY + " = ?", new String[] { String.valueOf(category.getId()) });
    // Delete category
    deleted = db.delete(TABLE_CATEGORY, KEY_CATEGORY_ID + " = ?", new String[] { String.valueOf(category.getId()) });
    return deleted;
}

76. RedditAccountManager#addAccount()

Project: RedReader
Source File: RedditAccountManager.java
View license
private synchronized void addAccount(final RedditAccount account, final SQLiteDatabase inDb) {
    final SQLiteDatabase db;
    if (inDb == null)
        db = getWritableDatabase();
    else
        db = inDb;
    final ContentValues row = new ContentValues();
    row.put(FIELD_USERNAME, account.username);
    if (account.refreshToken == null) {
        row.putNull(FIELD_REFRESH_TOKEN);
    } else {
        row.put(FIELD_REFRESH_TOKEN, account.refreshToken.token);
    }
    row.put(FIELD_PRIORITY, account.priority);
    db.insert(TABLE, null, row);
    reloadAccounts(db);
    updateNotifier.updateAllListeners();
    if (inDb == null)
        db.close();
}

77. ReminderDatabase#addReminder()

Project: Remindly
Source File: ReminderDatabase.java
View license
// Adding new Reminder
public int addReminder(Reminder reminder) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, reminder.getTitle());
    values.put(KEY_DATE, reminder.getDate());
    values.put(KEY_TIME, reminder.getTime());
    values.put(KEY_REPEAT, reminder.getRepeat());
    values.put(KEY_REPEAT_NO, reminder.getRepeatNo());
    values.put(KEY_REPEAT_TYPE, reminder.getRepeatType());
    values.put(KEY_ACTIVE, reminder.getActive());
    // Inserting Row
    long ID = db.insert(TABLE_REMINDERS, null, values);
    db.close();
    return (int) ID;
}

78. ReminderDatabase#updateReminder()

Project: Remindly
Source File: ReminderDatabase.java
View license
// Updating single Reminder
public int updateReminder(Reminder reminder) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, reminder.getTitle());
    values.put(KEY_DATE, reminder.getDate());
    values.put(KEY_TIME, reminder.getTime());
    values.put(KEY_REPEAT, reminder.getRepeat());
    values.put(KEY_REPEAT_NO, reminder.getRepeatNo());
    values.put(KEY_REPEAT_TYPE, reminder.getRepeatType());
    values.put(KEY_ACTIVE, reminder.getActive());
    // Updating row
    return db.update(TABLE_REMINDERS, values, KEY_ID + "=?", new String[] { String.valueOf(reminder.getID()) });
}

79. DatabaseHandler#getAllFriends()

Project: repay-android
Source File: DatabaseHandler.java
View license
/**
	 * @return All friends stored in the database as ArrayList
	 * @throws android.database.SQLException
	 */
public ArrayList<Friend> getAllFriends() throws SQLException, NullPointerException, CursorIndexOutOfBoundsException {
    SQLiteDatabase db = this.getReadableDatabase();
    ArrayList<Friend> friends = new ArrayList<Friend>();
    Cursor c = db.query(Names.F_TABLENAME, new String[] { Names.F_REPAYID, Names.F_LOOKUPURI, Names.F_NAME, Names.F_DEBT }, null, null, null, null, null);
    if (c != null && c.getCount() > 0) {
        c.moveToFirst();
        do {
            friends.add(new Friend(c.getString(0), c.getString(1), c.getString(2), new BigDecimal(c.getString(3))));
        } while (c.moveToNext());
    }
    db.close();
    return friends;
}

80. SQLiteContentProvider#bulkInsert()

View license
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    int numValues = values.length;
    SQLiteDatabase mDb = mOpenHelper.getWritableDatabase();
    mDb.beginTransactionWithListener(this);
    try {
        int rowsCreated = bulkInsertInTransaction(uri, values);
        if (rowsCreated != 0) {
            mNotifyChange = true;
        }
        mDb.setTransactionSuccessful();
    } finally {
        mDb.endTransaction();
    }
    onEndTransaction();
    return numValues;
}

81. ThreadDatabase#createThreadForRecipients()

Project: Silence
Source File: ThreadDatabase.java
View license
private long createThreadForRecipients(String recipients, int recipientCount, int distributionType) {
    ContentValues contentValues = new ContentValues(4);
    long date = System.currentTimeMillis();
    contentValues.put(DATE, date - date % 1000);
    contentValues.put(RECIPIENT_IDS, recipients);
    if (recipientCount > 1)
        contentValues.put(TYPE, distributionType);
    contentValues.put(MESSAGE_COUNT, 0);
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    return db.insert(TABLE_NAME, null, contentValues);
}

82. ThreadDatabase#updateThread()

Project: Silence
Source File: ThreadDatabase.java
View license
private void updateThread(long threadId, long count, String body, @Nullable Uri attachment, long date, int status, long type, boolean unarchive) {
    ContentValues contentValues = new ContentValues(6);
    contentValues.put(DATE, date - date % 1000);
    contentValues.put(MESSAGE_COUNT, count);
    contentValues.put(SNIPPET, body);
    contentValues.put(SNIPPET_URI, attachment == null ? null : attachment.toString());
    contentValues.put(SNIPPET_TYPE, type);
    contentValues.put(STATUS, status);
    if (unarchive) {
        contentValues.put(ARCHIVED, 0);
    }
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] { threadId + "" });
    notifyConversationListListeners();
}

83. ThreadDatabase#updateSnippet()

Project: Silence
Source File: ThreadDatabase.java
View license
public void updateSnippet(long threadId, String snippet, @Nullable Uri attachment, long date, long type, boolean unarchive) {
    ContentValues contentValues = new ContentValues(4);
    contentValues.put(DATE, date - date % 1000);
    contentValues.put(SNIPPET, snippet);
    contentValues.put(SNIPPET_TYPE, type);
    contentValues.put(SNIPPET_URI, attachment == null ? null : attachment.toString());
    if (unarchive) {
        contentValues.put(ARCHIVED, 0);
    }
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] { threadId + "" });
    notifyConversationListListeners();
}

84. ThreadDatabase#deleteThreads()

Project: Silence
Source File: ThreadDatabase.java
View license
private void deleteThreads(Set<Long> threadIds) {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    String where = "";
    for (long threadId : threadIds) {
        where += ID + " = '" + threadId + "' OR ";
    }
    where = where.substring(0, where.length() - 4);
    db.delete(TABLE_NAME, where, null);
    notifyConversationListListeners();
}

85. MusicAPI#setEnabled()

Project: sls
Source File: MusicAPI.java
View license
/**
	 * Enables / disables scrobbling from this API / music app.
	 * 
	 * @see MusicAppsActivity
	 * 
	 * @param ctx
	 *            context to enable database calls.
	 * @param enabled
	 *            whether this API / app should be enabled or disabled
	 */
public void setEnabled(Context ctx, boolean enabled) {
    int en = enabled ? 1 : 0;
    if (en == this.enabled)
        return;
    SQLiteDatabase db = DatabaseHelper.getDatabase(ctx.getApplicationContext());
    String update = "update music_api set enabled = " + en + " where _id = " + this.id;
    db.execSQL(update);
    this.enabled = en;
    DatabaseHelper.closeDatabase();
}

86. SessionDatabaseHelper#addSession()

View license
//CRUD Operations
public void addSession(Session session) {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        ContentValues values = new ContentValues();
        values.put(KEY_SESSION_STARTDATE, session.getStartDate());
        values.put(KEY_SESSION_ENDDATE, session.getEndDate());
        long rowId = db.insertOrThrow(TABLE_SESSIONS, null, values);
        if (// 0 > -1
        rowId > sessionId)
            sessionId = rowId;
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.d("ADD SESSION TO DB", "ERROR WHILE ADDING A SESSION TO DB");
    } finally {
        db.endTransaction();
    }
}

87. SessionDatabaseHelper#addDevice()

View license
public void addDevice(Device device) {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        ContentValues values = new ContentValues();
        values.put(KEY_DEVICE_SSID, device.getSsid());
        values.put(KEY_DEVICE_BSSID, device.getBssid());
        values.put(KEY_DEVICE_CHARACTERISTICS, device.getCharacteristics());
        values.put(KEY_DEVICE_TYPE, device.getType().toString());
        long rowId = db.insertOrThrow(TABLE_DEVICES, null, values);
        if (// 0 > -1
        rowId > deviceId)
            deviceId = rowId;
        else {
        // Error: Location already exists in DB
        }
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.d("ADD DEVICE TO DB", "ERROR WHILE ADDING A DEVICE TO DB");
    } finally {
        db.endTransaction();
    }
}

88. SessionDatabaseHelper#addLocation()

View license
public void addLocation(Location location) {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        ContentValues values = new ContentValues();
        values.put(KEY_LOCATION_DATE, location.getDate());
        values.put(KEY_LOCATION_COORDINATES, location.getCoordinatesString());
        long rowId = db.insertOrThrow(TABLE_LOCATIONS, null, values);
        if (// 0 > -1
        rowId > locationId)
            locationId = rowId;
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.d("ADD LOCATION TO DB", "ERROR WHILE ADDING A LOCATION TO DB");
    } finally {
        db.endTransaction();
    }
}

89. SessionDatabaseHelper#addAssociation()

View license
public void addAssociation() {
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        ContentValues values = new ContentValues();
        values.put(KEY_ASSOCIATION_ID_SESSION_FK, sessionId);
        values.put(KEY_ASSOCIATION_ID_DEVICE_FK, deviceId);
        values.put(KEY_ASSOCIATION_ID_LOCATION_FK, locationId);
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.d("ADD ASSOCIATION TO DB", "ERROR WHILE ADDING AN ASSOCIATION TO DB");
    } finally {
        db.endTransaction();
    }
}

90. SQLiteUsersConnectionRepository#findUserIdsWithConnection()

View license
public List<String> findUserIdsWithConnection(Connection<?> connection) {
    ConnectionKey key = connection.getKey();
    final String sql = "select userId from UserConnection where providerId = ? and providerUserId = ?";
    final String[] selectionArgs = { key.getProviderId(), key.getProviderUserId() };
    SQLiteDatabase db = repositoryHelper.getReadableDatabase();
    Cursor c = db.rawQuery(sql, selectionArgs);
    List<String> localUserIds = new ArrayList<String>();
    c.moveToFirst();
    for (int i = 0; i < c.getCount(); i++) {
        localUserIds.add(c.getString(c.getColumnIndex("userId")));
        c.moveToNext();
    }
    c.close();
    db.close();
    if (localUserIds.size() == 0 && connectionSignUp != null) {
        String newUserId = connectionSignUp.execute(connection);
        if (newUserId != null) {
            createConnectionRepository(newUserId).addConnection(connection);
            return Arrays.asList(newUserId);
        }
    }
    return localUserIds;
}

91. ContentProviderTest#givenATableWithData()

View license
private void givenATableWithData() throws IOException {
    ExtendedSQLiteOpenHelper helper = new ExtendedSQLiteOpenHelper(getContext());
    SQLiteDatabase db = helper.getWritableDatabase();
    db.execSQL("CREATE TABLE IF NOT EXISTS `" + TABLE_NAME + "` (" + "`" + COLUMN_PRIMARY_KEY + "` INTEGER PRIMARY KEY," + "`" + ANY_COLUMN + "` INTEGER UNIQUE)");
    ContentValues values = new ContentValues(2);
    values.put(COLUMN_PRIMARY_KEY, 1);
    values.put(ANY_COLUMN, 1);
    helper.getWritableDatabase().insert(TABLE_NAME, null, values);
}

92. TickmateDBImporter#canHandle()

Project: uhabits
Source File: TickmateDBImporter.java
View license
@Override
public boolean canHandle(@NonNull File file) throws IOException {
    if (!isSQLite3File(file))
        return false;
    SQLiteDatabase db = SQLiteDatabase.openDatabase(file.getPath(), null, SQLiteDatabase.OPEN_READONLY);
    Cursor c = db.rawQuery("select count(*) from SQLITE_MASTER where name=? or name=?", new String[] { "tracks", "track2groups" });
    boolean result = (c.moveToFirst() && c.getInt(0) == 2);
    c.close();
    db.close();
    return result;
}

93. ReaderUpdateService#deleteTags()

View license
private static void deleteTags(ReaderTagList tagList) {
    if (tagList == null || tagList.size() == 0) {
        return;
    }
    SQLiteDatabase db = ReaderDatabase.getWritableDb();
    db.beginTransaction();
    try {
        for (ReaderTag tag : tagList) {
            ReaderTagTable.deleteTag(tag);
            ReaderPostTable.deletePostsWithTag(tag);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}

94. ReaderTagTable#replaceFollowedTags()

View license
/*
     * similar to the above but only replaces followed tags
     */
public static void replaceFollowedTags(ReaderTagList tags) {
    if (tags == null || tags.size() == 0) {
        return;
    }
    SQLiteDatabase db = ReaderDatabase.getWritableDb();
    db.beginTransaction();
    try {
        try {
            // first delete all existing followed tags, then insert the passed ones
            String[] args = { Integer.toString(ReaderTagType.FOLLOWED.toInt()) };
            db.execSQL("DELETE FROM tbl_tags WHERE tag_type=?", args);
            addOrUpdateTags(tags);
            db.setTransactionSuccessful();
        } catch (SQLException e) {
            AppLog.e(T.READER, e);
        }
    } finally {
        db.endTransaction();
    }
}

95. ReaderTagTable#replaceTags()

View license
/*
     * replaces all tags with the passed list
     */
public static void replaceTags(ReaderTagList tags) {
    if (tags == null || tags.size() == 0) {
        return;
    }
    SQLiteDatabase db = ReaderDatabase.getWritableDb();
    db.beginTransaction();
    try {
        try {
            // first delete all existing tags, then insert the passed ones
            db.execSQL("DELETE FROM tbl_tags");
            addOrUpdateTags(tags);
            db.setTransactionSuccessful();
        } catch (SQLException e) {
            AppLog.e(T.READER, e);
        }
    } finally {
        db.endTransaction();
    }
}

96. ReaderBlogTable#setFollowedBlogs()

View license
/*
     * set followed blogs from the read/following/mine endpoint
     */
public static void setFollowedBlogs(ReaderBlogList followedBlogs) {
    SQLiteDatabase db = ReaderDatabase.getWritableDb();
    db.beginTransaction();
    try {
        // first set all existing blogs to not followed
        db.execSQL("UPDATE tbl_blog_info SET is_following=0");
        // then insert passed ones
        if (followedBlogs != null) {
            for (ReaderBlog blog : followedBlogs) {
                addOrUpdateBlog(blog);
            }
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}

97. PlayCountsHelper#getTopSongs()

Project: vanilla
Source File: PlayCountsHelper.java
View license
/**
	 * Returns a sorted array list of most often listen song ids
	 */
public ArrayList<Long> getTopSongs(int limit) {
    ArrayList<Long> payload = new ArrayList<Long>();
    SQLiteDatabase dbh = getReadableDatabase();
    Cursor cursor = dbh.rawQuery("SELECT type_id FROM " + TABLE_PLAYCOUNTS + " WHERE type=" + MediaUtils.TYPE_SONG + " AND playcount != 0 ORDER BY playcount DESC limit " + limit, null);
    while (cursor.moveToNext()) {
        payload.add(cursor.getLong(0));
    }
    cursor.close();
    dbh.close();
    return payload;
}

98. SugarTransactionHelper#doInTransaction()

Project: sugar
Source File: SugarTransactionHelper.java
View license
public static void doInTransaction(Callback callback) {
    final SQLiteDatabase database = getSugarContext().getSugarDb().getDB();
    database.beginTransaction();
    try {
        if (ManifestHelper.isDebugEnabled()) {
            Log.d(LOG_TAG, "Callback executing within transaction");
        }
        callback.manipulateInTransaction();
        database.setTransactionSuccessful();
        if (ManifestHelper.isDebugEnabled()) {
            Log.d(LOG_TAG, "Callback successfully executed within transaction");
        }
    } catch (Throwable e) {
        if (ManifestHelper.isDebugEnabled()) {
            Log.d(LOG_TAG, "Could execute callback within transaction", e);
        }
    } finally {
        database.endTransaction();
    }
}

99. SQLiteContentProvider#applyBatch()

View license
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    SQLiteDatabase mDb = mOpenHelper.getWritableDatabase();
    mDb.beginTransactionWithListener(this);
    try {
        mApplyingBatch.set(true);
        final int numOperations = operations.size();
        final ContentProviderResult[] results = new ContentProviderResult[numOperations];
        for (int i = 0; i < numOperations; i++) {
            final ContentProviderOperation operation = operations.get(i);
            if (i > 0 && operation.isYieldAllowed()) {
                mDb.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY);
            }
            results[i] = operation.apply(this, results, i);
        }
        mDb.setTransactionSuccessful();
        return results;
    } finally {
        mApplyingBatch.set(false);
        mDb.endTransaction();
        onEndTransaction();
    }
}

100. APODContentProvider#applyBatch()

Project: stetho
Source File: APODContentProvider.java
View license
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    db.beginTransaction();
    try {
        ContentProviderResult[] results = super.applyBatch(operations);
        db.setTransactionSuccessful();
        return results;
    } finally {
        db.endTransaction();
        notifyChange();
    }
}