Java Code Examples for net.sqlcipher.database.SQLiteDatabase#insertOrThrow()

The following examples show how to use net.sqlcipher.database.SQLiteDatabase#insertOrThrow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: commcare-android   File: SqlStorage.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int add(Externalizable e) {
    SQLiteDatabase db;
    db = helper.getHandle();
    int i = -1;
    db.beginTransaction();
    try {
        long ret = db.insertOrThrow(table, DatabaseHelper.DATA_COL, helper.getContentValues(e));

        if (ret > Integer.MAX_VALUE) {
            throw new RuntimeException("Waaaaaaaaaay too many values");
        }

        i = (int)ret;

        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }

    return i;
}
 
Example 2
Source Project: commcare-android   File: SqlStorage.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void write(Persistable p) {
    if (p.getID() != -1) {
        update(p.getID(), p);
        return;
    }
    SQLiteDatabase db = helper.getHandle();
    db.beginTransaction();
    try {
        long ret = db.insertOrThrow(table, DatabaseHelper.DATA_COL, helper.getContentValues(p));

        if (ret > Integer.MAX_VALUE) {
            throw new RuntimeException("Waaaaaaaaaay too many values");
        }
        // won't effect already stored obj id, which is set when reading out of db.
        // rather, needed in case persistable object is used after being written to storage.
        p.setID((int)ret);

        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
 
Example 3
protected static void setFileAsOrphan(SQLiteDatabase db, String filename) {
    db.beginTransaction();
    try {
        ContentValues cv = new ContentValues();
        cv.put(DatabaseHelper.FILE_COL, filename);
        db.insertOrThrow(DbUtil.orphanFileTableName, DatabaseHelper.FILE_COL, cv);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}