Search in sources :

Example 81 with SQLException

use of android.database.SQLException in project WordPress-Android by wordpress-mobile.

the class ReaderTagTable method setRecommendedTags.

public static void setRecommendedTags(ReaderTagList tagList) {
    if (tagList == null) {
        return;
    }
    SQLiteDatabase db = ReaderDatabase.getWritableDb();
    SQLiteStatement stmt = db.compileStatement("INSERT INTO tbl_tags_recommended (tag_slug, tag_display_name, tag_title, tag_type, endpoint) VALUES (?1,?2,?3,?4,?5)");
    db.beginTransaction();
    try {
        try {
            // first delete all recommended tags
            db.execSQL("DELETE FROM tbl_tags_recommended");
            // then insert the passed ones
            for (ReaderTag tag : tagList) {
                stmt.bindString(1, tag.getTagSlug());
                stmt.bindString(2, tag.getTagDisplayName());
                stmt.bindString(3, tag.getTagTitle());
                stmt.bindLong(4, tag.tagType.toInt());
                stmt.bindString(5, tag.getEndpoint());
                stmt.execute();
            }
            db.setTransactionSuccessful();
        } catch (SQLException e) {
            AppLog.e(T.READER, e);
        }
    } finally {
        SqlUtils.closeStatement(stmt);
        db.endTransaction();
    }
}
Also used : ReaderTag(org.wordpress.android.models.ReaderTag) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException)

Example 82 with SQLException

use of android.database.SQLException in project persistence by casidiablo.

the class BaseContentProvider method insert.

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    int id = sUriMatcher.match(uri);
    if (!TABLE_NAME_IDS.containsKey(id)) {
        throw new IllegalArgumentException("Unknown URI " + uri + "; id " + id + "; " + TABLE_NAME_IDS);
    }
    if (initialValues == null) {
        initialValues = new ContentValues();
    }
    String tableName = TABLE_NAME_IDS.get(id);
    long rowId = getDatabase().insert(tableName, null, initialValues);
    if (rowId > 0) {
        Uri CONTENT_URI = Uri.parse(String.format("content://%s/%s", getAuthority(), tableName));
        Uri beanUri = ContentUris.withAppendedId(CONTENT_URI, rowId);
        getContext().getContentResolver().notifyChange(beanUri, null);
        return beanUri;
    }
    throw new SQLException("Failed to insert row into " + uri);
}
Also used : SQLException(android.database.SQLException) Uri(android.net.Uri)

Example 83 with SQLException

use of android.database.SQLException in project cw-omnibus by commonsguy.

the class Provider method insert.

@Override
public Uri insert(Uri url, ContentValues initialValues) {
    long rowID = db.getWritableDatabase().insert(TABLE, Constants.TITLE, initialValues);
    if (rowID > 0) {
        Uri uri = ContentUris.withAppendedId(Provider.Constants.CONTENT_URI, rowID);
        getContext().getContentResolver().notifyChange(uri, null);
        return (uri);
    }
    throw new SQLException("Failed to insert row into " + url);
}
Also used : SQLException(android.database.SQLException) Uri(android.net.Uri)

Example 84 with SQLException

use of android.database.SQLException in project fresco by facebook.

the class MediaVariationsIndexDatabase method getCachedVariantsSync.

@VisibleForTesting
protected MediaVariations getCachedVariantsSync(String mediaId, MediaVariations.Builder mediaVariationsBuilder) {
    synchronized (MediaVariationsIndexDatabase.class) {
        SQLiteDatabase db = mDbHelper.getWritableDatabase();
        Cursor c = null;
        try {
            String selection = IndexEntry.COLUMN_NAME_MEDIA_ID + " = ?";
            String[] selectionArgs = { mediaId };
            c = db.query(IndexEntry.TABLE_NAME, PROJECTION, selection, selectionArgs, // groupBy
            null, // having
            null, // orderBy
            null);
            if (c.getCount() == 0) {
                return mediaVariationsBuilder.build();
            }
            final int columnIndexCacheKey = c.getColumnIndexOrThrow(IndexEntry.COLUMN_NAME_CACHE_KEY);
            final int columnIndexWidth = c.getColumnIndexOrThrow(IndexEntry.COLUMN_NAME_WIDTH);
            final int columnIndexHeight = c.getColumnIndexOrThrow(IndexEntry.COLUMN_NAME_HEIGHT);
            final int columnIndexCacheChoice = c.getColumnIndexOrThrow(IndexEntry.COLUMN_NAME_CACHE_CHOICE);
            while (c.moveToNext()) {
                String cacheChoiceStr = c.getString(columnIndexCacheChoice);
                mediaVariationsBuilder.addVariant(Uri.parse(c.getString(columnIndexCacheKey)), c.getInt(columnIndexWidth), c.getInt(columnIndexHeight), TextUtils.isEmpty(cacheChoiceStr) ? null : ImageRequest.CacheChoice.valueOf(cacheChoiceStr));
            }
            return mediaVariationsBuilder.build();
        } catch (SQLException x) {
            FLog.e(TAG, x, "Error reading for %s", mediaId);
            throw x;
        } finally {
            if (c != null) {
                c.close();
            }
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) Cursor(android.database.Cursor) VisibleForTesting(com.facebook.common.internal.VisibleForTesting)

Example 85 with SQLException

use of android.database.SQLException in project KJFrameForAndroid by kymjs.

the class KJDB method dropDb.

/**
     * 删除所有数据表
     */
public void dropDb() {
    Cursor cursor = db.rawQuery("SELECT name FROM sqlite_master WHERE type ='table'", null);
    if (cursor != null) {
        while (cursor.moveToNext()) {
            // table sqlite_sequence may not be dropped
            try {
                db.execSQL("DROP TABLE " + cursor.getString(0));
            } catch (SQLException e) {
                KJLoger.debug(getClass().getName() + e.getMessage());
            }
        }
    }
    if (cursor != null) {
        cursor.close();
        cursor = null;
    }
}
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