@Override public void onCreate(final SQLiteDatabase sqLiteDatabase) { throw new SQLException(); }
public String queryString(String query) throws SQLException { Cursor cursor = null; try { cursor = mDatabase.query(query, null); if (!cursor.moveToNext()) { throw new SQLException("No result for query: " + query); } return cursor.getString(0); } finally { if (cursor != null) { cursor.close(); } } }
@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); }
@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); }
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { // Get access to the task database (to write new data to) final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase(); // Write URI matching code to identify the match for the tasks directory int match = sUriMatcher.match(uri); Uri returnUri; // URI to be returned switch (match) { case TASKS: // Insert new values into the database // Inserting values into tasks table long id = db.insert(TABLE_NAME, null, values); if ( id > 0 ) { returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id); } else { throw new android.database.SQLException("Failed to insert row into " + uri); } break; // Set the value for the returnedUri and write the default case for unknown URI's // Default case throws an UnsupportedOperationException default: throw new UnsupportedOperationException("Unknown uri: " + uri); } // Notify the resolver if the uri has been changed, and return the newly inserted URI getContext().getContentResolver().notifyChange(uri, null); // Return constructed uri (this points to the newly inserted row of data) return returnUri; }
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { // Get access to the task database (to write new data to) final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase(); // Write URI matching code to identify the match for the tasks directory int match = sUriMatcher.match(uri); Uri returnUri; // URI to be returned switch (match) { case TASKS: // Insert new values into the database // Inserting values into tasks table long id = db.insert(TABLE_NAME, null, values); if ( id > 0 ) { returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id); } else { throw new android.database.SQLException("Failed to insert row into " + uri); } break; // Set the value for the returnedUri and write the default case for unknown URI's // Default case throws an UnsupportedOperationException default: throw new UnsupportedOperationException("Unknown uri: " + uri); } // Notify the resolver if the uri has been changed, and return the newly inserted URI getContext().getContentResolver().notifyChange(uri, null); // Return constructed uri (this points to the newly inserted row of data) return returnUri; }
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { // COMPLETED (1) Get access to the task database (to write new data to) final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase(); // COMPLETED (2) Write URI matching code to identify the match for the tasks directory int match = sUriMatcher.match(uri); Uri returnUri; // URI to be returned switch (match) { case TASKS: // COMPLETED (3) Insert new values into the database // Inserting values into tasks table long id = db.insert(TABLE_NAME, null, values); if ( id > 0 ) { returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id); } else { throw new android.database.SQLException("Failed to insert row into " + uri); } break; // COMPLETED (4) Set the value for the returnedUri and write the default case for unknown URI's // Default case throws an UnsupportedOperationException default: throw new UnsupportedOperationException("Unknown uri: " + uri); } // COMPLETED (5) Notify the resolver if the uri has been changed, and return the newly inserted URI getContext().getContentResolver().notifyChange(uri, null); // Return constructed uri (this points to the newly inserted row of data) return returnUri; }
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { // Get access to the task database (to write new data to) final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase(); // Write URI matching code to identify the match for the tasks directory int match = sUriMatcher.match(uri); Uri returnUri; // URI to be returned switch (match) { case TASKS: // Insert new values into the database // Inserting values into tasks table long id = db.insert(TABLE_NAME, null, values); if ( id > 0 ) { returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id); } else { throw new android.database.SQLException("Failed to insert row into " + uri); } break; // Set the value for the returnedUri and write the default case for unknown URI's // Default case throws an UnsupportedOperationException default: throw new UnsupportedOperationException("Unknown uri: " + uri); } // Notify the resolver if the uri has been changed, and return the newly inserted URI getContext().getContentResolver().notifyChange(uri, null); // Return constructed uri (this points to the newly inserted row of data) return returnUri; }
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { // Get access to the task database (to write new data to) final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase(); // Write URI matching code to identify the match for the tasks directory int match = sUriMatcher.match(uri); Uri returnUri; // URI to be returned switch (match) { case TASKS: // Insert new values into the database // Inserting values into tasks table long id = db.insert(TABLE_NAME, null, values); if ( id > 0 ) { returnUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, id); } else { throw new android.database.SQLException("Failed to insert row into " + uri); } break; // Set the value for the returnedUri and write the default case for unknown URI's // Default case throws an UnsupportedOperationException default: throw new UnsupportedOperationException("Unknown uri: " + uri); } // Notify the resolver if the uri has been changed, and return the newly inserted URI getContext().getContentResolver().notifyChange(uri, null); // Return constructed uri (this points to the newly inserted row of data) return returnUri; }
private void store(JobRequest request) { ContentValues contentValues = request.toContentValues(); SQLiteDatabase database = null; try { database = getDatabase(); /* * It could happen that a conflict with the job ID occurs, when a job was cancelled (cancelAndEdit()) * the builder object scheduled twice. In this case the last call wins and the value in the database * will be overwritten. */ if (database.insertWithOnConflict(JOB_TABLE_NAME, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE) < 0) { throw new SQLException("Couldn't insert job request into database"); } } finally { closeDatabase(database); } }
@Override public Uri insert(Uri uri, ContentValues values) { long row = db.insert(JIGSAW_TABLE, "", values); if (row > 0) { Uri newUri = ContentUris.withAppendedId(CONTENT_URI, row); getContext().getContentResolver().notifyChange(newUri, null); return newUri; } throw new SQLException("Fail to add a new record into " + uri); }
@Override public Uri insert(Uri uri, ContentValues values) { long row = mDB.insert(TABLE, "", values); if(row > 0) { // Record added Uri newUri = ContentUris.withAppendedId(CONTENT_URI, row); getContext().getContentResolver().notifyChange(newUri, null); return newUri; } throw new SQLException("Divanotes: Fail to add a new record into " + uri); }
@Override public Uri insert(Uri uri, ContentValues values) { boolean isPrefrences = URI_MATCHER.match(uri) == PREFERENCES; if (!isPrefrences) throw new IllegalArgumentException("Unknown URI " + uri); SQLiteDatabase db = mDbHelper.getWritableDatabase(); long rowId = db.insert(TB_NAME, null, values); if (rowId > 0) { Uri noteUri = ContentUris.withAppendedId(CONTENT_URI, rowId); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
@Override public Uri insert(Uri uri, ContentValues values) { boolean isPrefrences = URI_MATCHER.match(uri) == SESSIONS; if (!isPrefrences) throw new IllegalArgumentException("Unknown URI " + uri); SQLiteDatabase db = mDbHelper.getWritableDatabase(); long rowId = db.insert(TB_NAME, COL_VALUE, values); if (rowId > 0) { Uri noteUri = ContentUris.withAppendedId(CONTENT_URI, rowId); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
@Override public Uri insert(Uri uri, ContentValues contentValues) { // Validate the requested uri if (sUriMatcher.match(uri) != VOICENOTES) { throw new IllegalArgumentException("Unknown URI " + uri); } SQLiteDatabase db = mOpenHelper.getWritableDatabase(); long rowId = db.insert(VOICE_NOTES_TABLE_NAME, VoiceNote.DATA_URI, contentValues); if (rowId > 0) { Uri noteUri = ContentUris.withAppendedId(VoiceNote.CONTENT_URI, rowId); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
public static long insert(MyContext myContext, String tableName, ContentValues values) { SQLiteDatabase db = myContext.getDatabase(); if (db == null || values.size() == 0) return -1; long rowId = db.insert(tableName, null, values); if (rowId == -1) { throw new SQLException("Failed to insert " + values); } return rowId; }
@Implementation public long insertOrThrow(String table, String nullColumnHack, ContentValues values) throws android.database.SQLException { if (throwOnInsert) throw new android.database.SQLException(); return insertWithOnConflict(table, nullColumnHack, values, SQLiteDatabase.CONFLICT_NONE); }
@Override public Uri insert(Uri uri, ContentValues contentValues) { final String tableName = getTableNameFromUri(uri); if (contentValues == null) contentValues = new ContentValues(); SQLiteDatabase db = OrgDatabase.getInstance().getWritableDatabase(); long rowId = 0; try { rowId = db.insert(tableName, null, contentValues); } catch (Exception e) { e.printStackTrace(); } if (rowId > 0) { Uri noteUri = ContentUris.withAppendedId(uri, rowId); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } else throw new SQLException("Failed to insert row into " + uri); }
@Implementation public void execSQL(String sql) throws android.database.SQLException { if (!isOpen()) { throw new IllegalStateException("database not open"); } try { String scrubbedSql= DatabaseConfig.getScrubSQL(sql); connection.createStatement().execute(scrubbedSql); } catch (java.sql.SQLException e) { android.database.SQLException ase = new android.database.SQLException(); ase.initCause(e); throw ase; } }
private void store(JobRequest request) { ContentValues contentValues = request.toContentValues(); SQLiteDatabase database = null; try { database = getDatabase(); /* * It could happen that a conflict with the job ID occurs, when a job was cancelled (cancelAndEdit()) * the builder object scheduled twice. In this case the last call wins and the value in the database * will be overwritten. */ if (database.insertWithOnConflict(JOB_TABLE_NAME, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE) < 0) { throw new SQLException("Couldn't insert job request into database"); } } finally { closeDatabase(database); } }