List of usage examples for android.database SQLException SQLException
public SQLException(String error)
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertSource(@NonNull final Uri uri, final ContentValues initialValues) { Context context = getContext(); if (context == null) { return null; }/*from www . ja v a2s . c o m*/ if (!initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME) || TextUtils.isEmpty(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name " + initialValues); } ComponentName componentName = ComponentName .unflattenFromString(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)); } ApplicationInfo info; try { // Ensure the service is valid and extract the application info info = context.getPackageManager().getServiceInfo(componentName, 0).applicationInfo; } catch (PackageManager.NameNotFoundException e) { throw new IllegalArgumentException("Invalid component name " + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME), e); } // Make sure they are using the short string format initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); // Only Muzei can set the IS_SELECTED field if (initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED)) { if (!context.getPackageName().equals(getCallingPackage())) { Log.w(TAG, "Only Muzei can set the " + MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED + " column. Ignoring the value in " + initialValues); initialValues.remove(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED); } } // Disable network access callbacks if we're running on an API 24 device and the source app // targets API 24. This is to be consistent with the Behavior Changes in Android N if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE) && initialValues.getAsBoolean(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE)) { if (info.targetSdkVersion >= Build.VERSION_CODES.N) { Log.w(TAG, "Sources targeting API 24 cannot receive network access callbacks. Changing " + componentName + " to false for " + MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, false); } } final SQLiteDatabase db = databaseHelper.getWritableDatabase(); final long rowId = db.insert(MuzeiContract.Sources.TABLE_NAME, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, initialValues); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the source ID pattern and the new row ID appended to it. final Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, rowId); notifyChange(sourceUri); return sourceUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }
From source file:org.kontalk.provider.UsersProvider.java
@Override public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) { throw new SQLException("delete not supported."); }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
/** * ???/*from w ww .j a v a2 s . c o m*/ * * @param rowid * @param detail * @return */ public static int changeResendMsg(long rowid, ECMessage detail) { if (detail == null || TextUtils.isEmpty(detail.getMsgId()) || rowid == -1) { return -1; } String where = IMessageColumn.ID + "=" + rowid + " and " + IMessageColumn.SEND_STATUS + " = " + ECMessage.MessageStatus.FAILED.ordinal(); ContentValues values = null; try { values = new ContentValues(); values.put(IMessageColumn.MESSAGE_ID, detail.getMsgId()); values.put(IMessageColumn.SEND_STATUS, detail.getMsgStatus().ordinal()); values.put(IMessageColumn.USER_DATA, detail.getUserData()); return getInstance().sqliteDB().update(DatabaseHelper.TABLES_NAME_IM_MESSAGE, values, where, null); } catch (Exception e) { e.printStackTrace(); throw new SQLException(e.getMessage()); } finally { if (values != null) { values.clear(); values = null; } } }