Search in sources :

Example 36 with SQLException

use of android.database.SQLException in project SunDay by iQuick.

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) {
            e.printStackTrace();
        } 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 37 with SQLException

use of android.database.SQLException in project 360-Engine-for-Android by 360.

the class FetchNativeContactsTest method fetchSyncNativeId.

private Integer fetchSyncNativeId(Long localDetailID) {
    Integer value = null;
    SQLiteDatabase readableDb = mDb.getReadableDatabase();
    try {
        Cursor c = readableDb.rawQuery("SELECT " + ContactDetailsTable.Field.NATIVESYNCCONTACTID + " FROM " + ContactDetailsTable.TABLE_NAME + " WHERE " + Field.DETAILLOCALID + "=" + localDetailID, null);
        if (c.moveToFirst()) {
            if (!c.isNull(0)) {
                value = c.getInt(0);
            }
        }
        c.close();
    } catch (SQLException e) {
    }
    return value;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 38 with SQLException

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

the class HistoryManager method deletePrevious.

private void deletePrevious(String text) {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    try {
        db = helper.getWritableDatabase();
        db.delete(DBHelper.TABLE_NAME, DBHelper.TEXT_COL + "=?", new String[] { text });
    } catch (SQLException sqle) {
        Log.w(TAG, sqle);
    } finally {
        close(null, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException)

Example 39 with SQLException

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

the class HistoryManager method hasHistoryItems.

public boolean hasHistoryItems() {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    Cursor cursor = null;
    try {
        db = helper.getReadableDatabase();
        cursor = db.query(DBHelper.TABLE_NAME, COUNT_COLUMN, null, null, null, null, null);
        cursor.moveToFirst();
        return cursor.getInt(0) > 0;
    } catch (SQLException sqle) {
        Log.w(TAG, sqle);
        return false;
    } finally {
        close(cursor, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 40 with SQLException

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

the class HistoryManager method trimHistory.

public void trimHistory() {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    Cursor cursor = null;
    try {
        db = helper.getWritableDatabase();
        cursor = db.query(DBHelper.TABLE_NAME, ID_COL_PROJECTION, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
        cursor.move(MAX_ITEMS);
        while (cursor.moveToNext()) {
            String id = cursor.getString(0);
            Log.i(TAG, "Deleting scan history ID " + id);
            db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + id, null);
        }
    } catch (SQLException sqle) {
        // We're seeing an error here when called in CaptureActivity.onCreate() in rare cases
        // and don't understand it. First theory is that it's transient so can be safely ignored.
        Log.w(TAG, sqle);
    // continue
    } finally {
        close(cursor, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Aggregations

SQLException (android.database.SQLException)224 ContentValues (android.content.ContentValues)114 Uri (android.net.Uri)60 Cursor (android.database.Cursor)57 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)39 SQLiteException (android.database.sqlite.SQLiteException)18 Intent (android.content.Intent)16 ArrayList (java.util.ArrayList)14 SQLiteStatement (android.database.sqlite.SQLiteStatement)13 HandlerThread (android.os.HandlerThread)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