Java Code Examples for android.database.sqlite.SQLiteDatabase#replaceOrThrow()
The following examples show how to use
android.database.sqlite.SQLiteDatabase#replaceOrThrow() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: MediaSDK File: DefaultDownloadIndex.java License: Apache License 2.0 | 6 votes |
@Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example 2
Source Project: Telegram-FOSS File: DefaultDownloadIndex.java License: GNU General Public License v2.0 | 6 votes |
@Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example 3
Source Project: Telegram File: DefaultDownloadIndex.java License: GNU General Public License v2.0 | 6 votes |
@Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example 4
Source Project: MediaSDK File: VersionTable.java License: Apache License 2.0 | 5 votes |
/** * Sets the version of a specified instance of a specified feature. * * @param writableDatabase The database to update. * @param feature The feature. * @param instanceUid The unique identifier of the instance of the feature. * @param version The version. * @throws DatabaseIOException If an error occurs executing the SQL. */ public static void setVersion( SQLiteDatabase writableDatabase, @Feature int feature, String instanceUid, int version) throws DatabaseIOException { try { writableDatabase.execSQL(SQL_CREATE_TABLE_IF_NOT_EXISTS); ContentValues values = new ContentValues(); values.put(COLUMN_FEATURE, feature); values.put(COLUMN_INSTANCE_UID, instanceUid); values.put(COLUMN_VERSION, version); writableDatabase.replaceOrThrow(TABLE_NAME, /* nullColumnHack= */ null, values); } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example 5
Source Project: MediaSDK File: CachedContentIndex.java License: Apache License 2.0 | 5 votes |
private void addOrUpdateRow(SQLiteDatabase writableDatabase, CachedContent cachedContent) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); writeContentMetadata(cachedContent.getMetadata(), new DataOutputStream(outputStream)); byte[] data = outputStream.toByteArray(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, cachedContent.id); values.put(COLUMN_KEY, cachedContent.key); values.put(COLUMN_METADATA, data); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); }
Example 6
Source Project: MediaSDK File: CacheFileMetadataIndex.java License: Apache License 2.0 | 5 votes |
/** * Sets metadata for a given file. * * <p>This method may be slow and shouldn't normally be called on the main thread. * * @param name The name of the file. * @param length The file length. * @param lastTouchTimestamp The file last touch timestamp. * @throws DatabaseIOException If an error occurs setting the metadata. */ @WorkerThread public void set(String name, long length, long lastTouchTimestamp) throws DatabaseIOException { Assertions.checkNotNull(tableName); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_NAME, name); values.put(COLUMN_LENGTH, length); values.put(COLUMN_LAST_TOUCH_TIMESTAMP, lastTouchTimestamp); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example 7
Source Project: nextcloud-notes File: NotesDatabase.java License: GNU General Public License v3.0 | 5 votes |
public void createOrUpdateSingleNoteWidgetData(@NonNull SingleNoteWidgetData data) throws SQLException { validateAccountId(data.getAccountId()); final SQLiteDatabase db = getWritableDatabase(); final ContentValues values = new ContentValues(4); values.put(key_id, data.getAppWidgetId()); values.put(key_account_id, data.getAccountId()); values.put(key_note_id, data.getNoteId()); values.put(key_theme_mode, data.getThemeMode()); db.replaceOrThrow(table_widget_single_notes, null, values); }
Example 8
Source Project: nextcloud-notes File: NotesDatabase.java License: GNU General Public License v3.0 | 5 votes |
public void createOrUpdateNoteListWidgetData(@NonNull NoteListsWidgetData data) throws SQLException { validateAccountId(data.getAccountId()); final SQLiteDatabase db = getWritableDatabase(); final ContentValues values = new ContentValues(5); if (data.getMode() != MODE_DISPLAY_CATEGORY && data.getCategoryId() != null) { throw new UnsupportedOperationException("Cannot create a widget with a categoryId when mode is not " + MODE_DISPLAY_CATEGORY); } values.put(key_id, data.getAppWidgetId()); values.put(key_account_id, data.getAccountId()); values.put(key_category_id, data.getCategoryId()); values.put(key_theme_mode, data.getThemeMode()); values.put(key_mode, data.getMode()); db.replaceOrThrow(table_widget_note_list, null, values); }
Example 9
Source Project: Telegram-FOSS File: VersionTable.java License: GNU General Public License v2.0 | 5 votes |
/** * Sets the version of a specified instance of a specified feature. * * @param writableDatabase The database to update. * @param feature The feature. * @param instanceUid The unique identifier of the instance of the feature. * @param version The version. * @throws DatabaseIOException If an error occurs executing the SQL. */ public static void setVersion( SQLiteDatabase writableDatabase, @Feature int feature, String instanceUid, int version) throws DatabaseIOException { try { writableDatabase.execSQL(SQL_CREATE_TABLE_IF_NOT_EXISTS); ContentValues values = new ContentValues(); values.put(COLUMN_FEATURE, feature); values.put(COLUMN_INSTANCE_UID, instanceUid); values.put(COLUMN_VERSION, version); writableDatabase.replaceOrThrow(TABLE_NAME, /* nullColumnHack= */ null, values); } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example 10
Source Project: Telegram-FOSS File: CachedContentIndex.java License: GNU General Public License v2.0 | 5 votes |
private void addOrUpdateRow(SQLiteDatabase writableDatabase, CachedContent cachedContent) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); writeContentMetadata(cachedContent.getMetadata(), new DataOutputStream(outputStream)); byte[] data = outputStream.toByteArray(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, cachedContent.id); values.put(COLUMN_KEY, cachedContent.key); values.put(COLUMN_METADATA, data); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); }
Example 11
Source Project: Telegram-FOSS File: CacheFileMetadataIndex.java License: GNU General Public License v2.0 | 5 votes |
/** * Sets metadata for a given file. * * @param name The name of the file. * @param length The file length. * @param lastTouchTimestamp The file last touch timestamp. * @throws DatabaseIOException If an error occurs setting the metadata. */ public void set(String name, long length, long lastTouchTimestamp) throws DatabaseIOException { Assertions.checkNotNull(tableName); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_NAME, name); values.put(COLUMN_LENGTH, length); values.put(COLUMN_LAST_TOUCH_TIMESTAMP, lastTouchTimestamp); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example 12
Source Project: Telegram File: VersionTable.java License: GNU General Public License v2.0 | 5 votes |
/** * Sets the version of a specified instance of a specified feature. * * @param writableDatabase The database to update. * @param feature The feature. * @param instanceUid The unique identifier of the instance of the feature. * @param version The version. * @throws DatabaseIOException If an error occurs executing the SQL. */ public static void setVersion( SQLiteDatabase writableDatabase, @Feature int feature, String instanceUid, int version) throws DatabaseIOException { try { writableDatabase.execSQL(SQL_CREATE_TABLE_IF_NOT_EXISTS); ContentValues values = new ContentValues(); values.put(COLUMN_FEATURE, feature); values.put(COLUMN_INSTANCE_UID, instanceUid); values.put(COLUMN_VERSION, version); writableDatabase.replaceOrThrow(TABLE_NAME, /* nullColumnHack= */ null, values); } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example 13
Source Project: Telegram File: CachedContentIndex.java License: GNU General Public License v2.0 | 5 votes |
private void addOrUpdateRow(SQLiteDatabase writableDatabase, CachedContent cachedContent) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); writeContentMetadata(cachedContent.getMetadata(), new DataOutputStream(outputStream)); byte[] data = outputStream.toByteArray(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, cachedContent.id); values.put(COLUMN_KEY, cachedContent.key); values.put(COLUMN_METADATA, data); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); }
Example 14
Source Project: Telegram File: CacheFileMetadataIndex.java License: GNU General Public License v2.0 | 5 votes |
/** * Sets metadata for a given file. * * @param name The name of the file. * @param length The file length. * @param lastTouchTimestamp The file last touch timestamp. * @throws DatabaseIOException If an error occurs setting the metadata. */ public void set(String name, long length, long lastTouchTimestamp) throws DatabaseIOException { Assertions.checkNotNull(tableName); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(COLUMN_NAME, name); values.put(COLUMN_LENGTH, length); values.put(COLUMN_LAST_TOUCH_TIMESTAMP, lastTouchTimestamp); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLException e) { throw new DatabaseIOException(e); } }