Search in sources :

Example 21 with SQLException

use of android.database.SQLException in project androrm by androrm.

the class DataField method exec.

protected boolean exec(Context context, Class<? extends Model> model, String sql) {
    DatabaseAdapter adapter = DatabaseAdapter.getInstance(context);
    adapter.open();
    try {
        adapter.exec(sql);
    } catch (SQLException e) {
        adapter.close();
        return false;
    }
    adapter.close();
    return true;
}
Also used : SQLException(android.database.SQLException) DatabaseAdapter(com.orm.androrm.DatabaseAdapter)

Example 22 with SQLException

use of android.database.SQLException in project sqlbrite by square.

the class BriteDatabaseTest method executeInsertThrowsAndDoesNotTrigger.

@Test
public void executeInsertThrowsAndDoesNotTrigger() {
    SQLiteStatement statement = real.compileStatement("INSERT INTO " + TABLE_EMPLOYEE + " (" + TestDb.EmployeeTable.NAME + ", " + TestDb.EmployeeTable.USERNAME + ") " + "VALUES ('Alice Allison', 'alice')");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).skip(// Skip initial
    1).subscribe(o);
    try {
        db.executeInsert(TABLE_EMPLOYEE, statement);
        fail();
    } catch (SQLException ignored) {
    }
    o.assertNoMoreEvents();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException) Test(org.junit.Test)

Example 23 with SQLException

use of android.database.SQLException in project sqlbrite by square.

the class BriteDatabaseTest method executeUpdateDeleteThrowsAndDoesNotTrigger.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteThrowsAndDoesNotTrigger() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.USERNAME + " = 'alice'");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).skip(// Skip initial
    1).subscribe(o);
    try {
        db.executeUpdateDelete(TABLE_EMPLOYEE, statement);
        fail();
    } catch (SQLException ignored) {
    }
    o.assertNoMoreEvents();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 24 with SQLException

use of android.database.SQLException in project 9GAG by stormzhang.

the class DataProvider method insert.

@Override
public Uri insert(Uri uri, ContentValues values) {
    synchronized (DBLock) {
        String table = matchTable(uri);
        SQLiteDatabase db = getDBHelper().getWritableDatabase();
        long rowId = 0;
        db.beginTransaction();
        try {
            rowId = db.insert(table, null, values);
            db.setTransactionSuccessful();
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        } finally {
            db.endTransaction();
        }
        if (rowId > 0) {
            Uri returnUri = ContentUris.withAppendedId(uri, rowId);
            getContext().getContentResolver().notifyChange(uri, null);
            return returnUri;
        }
        throw new SQLException("Failed to insert row into " + uri);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) Uri(android.net.Uri) SQLException(android.database.SQLException)

Example 25 with SQLException

use of android.database.SQLException in project FBReaderJ by geometer.

the class SQLiteConfig method requestAllValuesForGroup.

@Override
public synchronized List<String> requestAllValuesForGroup(String group) {
    try {
        final List<String> pairs = new LinkedList<String>();
        final Cursor cursor = myDatabase.rawQuery("SELECT name,value FROM config WHERE groupName = ?", new String[] { group });
        while (cursor.moveToNext()) {
            pairs.add(cursor.getString(0) + "\000" + cursor.getString(1));
        }
        cursor.close();
        return pairs;
    } catch (SQLException e) {
        return Collections.emptyList();
    }
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Aggregations

SQLException (android.database.SQLException)154 Cursor (android.database.Cursor)51 ContentValues (android.content.ContentValues)50 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)31 Uri (android.net.Uri)30 SQLiteStatement (android.database.sqlite.SQLiteStatement)13 ArrayList (java.util.ArrayList)10 DatabaseUtils (android.database.DatabaseUtils)8 Gson (com.google.gson.Gson)8 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)7 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)6 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 IOException (java.io.IOException)5 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)4 Test (org.junit.Test)4 Activity (android.app.Activity)3 ContentResolver (android.content.ContentResolver)3 Context (android.content.Context)3 LayoutInflater (android.view.LayoutInflater)3