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