public SQLiteDatabase openWriter() { return helper.getWritableDatabase(); }
/** * Open the database when the write data. * * @return {@link SQLiteDatabase}. */ protected final SQLiteDatabase getWriter() { return liteOpenHelper.getWritableDatabase(); }
/** * Get writable database * * @param helper * @return writable database or null if it failed to create/open */ protected SQLiteDatabase getWritable(SQLiteOpenHelper helper) { try { return helper.getWritableDatabase(); } catch (SQLiteException e1) { // Make second attempt try { return helper.getWritableDatabase(); } catch (SQLiteException e2) { return null; } } }
@Override public void onDetachedFromWindow() { // clear database db.getWritableDatabase().delete(ViewProfile.TABLE, null, null); super.onDetachedFromWindow(); }
if(mOpenCounter == 1) { mDatabase = mDatabaseHelper.getWritableDatabase();
@Override public Uri insert(Uri uri, ContentValues values) { final long insertedId; switch (URI_MATCHER.match(uri)) { case URI_MATCHER_CODE_TWEETS: insertedId = sqLiteOpenHelper .getWritableDatabase() .insert( TweetsTable.TABLE, null, values ); break; default: return null; } if (insertedId != -1) { getContext().getContentResolver().notifyChange(uri, null); } return ContentUris.withAppendedId(uri, insertedId); }
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { final int numberOfRowsDeleted; switch (URI_MATCHER.match(uri)) { case URI_MATCHER_CODE_TWEETS: numberOfRowsDeleted = sqLiteOpenHelper .getWritableDatabase() .delete( TweetsTable.TABLE, selection, selectionArgs ); break; default: return 0; } if (numberOfRowsDeleted > 0) { getContext().getContentResolver().notifyChange(uri, null); } return numberOfRowsDeleted; } }
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { final int numberOfRowsAffected; switch (URI_MATCHER.match(uri)) { case URI_MATCHER_CODE_TWEETS: numberOfRowsAffected = sqLiteOpenHelper .getWritableDatabase() .update( TweetsTable.TABLE, values, selection, selectionArgs ); break; default: return 0; } if (numberOfRowsAffected > 0) { getContext().getContentResolver().notifyChange(uri, null); } return numberOfRowsAffected; }
/** * Instantiates the AndroidSqLiteDqLogStorage. */ public AndroidSqLiteDqLogStorage(Context context, String dbName, long bucketSize, int recordCount) { Log.i(TAG, "Connecting to db with name: " + dbName); dbHelper = new DataCollectionDbHelper(context, dbName); database = dbHelper.getWritableDatabase(); this.maxRecordCount = recordCount; this.maxBucketSize = bucketSize; truncateIfBucketSizeIncompatible(); retrieveConsumedSizeAndVolume(); if (totalRecordCount > 0) { retrieveBucketId(); resetBucketsState(); } }
public Hosts(Context context, String name) { helper = new MSQLiteBuilder() .version(VERSION_1) .createTable(TABLE_HOSTS) .insertColumn(TABLE_HOSTS, COLUMN_HOST, String.class) .insertColumn(TABLE_HOSTS, COLUMN_IP, String.class) .build(context, name, DB_VERSION); db = helper.getWritableDatabase(); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
/** * Tests to ensure that inserts into your database results in automatically * incrementing row IDs. * @throws Exception in case the constructor hasn't been implemented yet */ @Test public void autoincrement_test() throws Exception{ /* First, let's ensure we have some values in our table initially */ insert_single_record_test(); /* Use reflection to try to run the correct constructor whenever implemented */ SQLiteOpenHelper dbHelper = (SQLiteOpenHelper) mDbHelperClass.getConstructor(Context.class).newInstance(mContext); /* Use WaitlistDbHelper to get access to a writable database */ SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues testValues = new ContentValues(); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME, "test name"); testValues.put(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE, 99); /* Insert ContentValues into database and get first row ID back */ long firstRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); /* Insert ContentValues into database and get another row ID back */ long secondRowId = database.insert( WaitlistContract.WaitlistEntry.TABLE_NAME, null, testValues); assertEquals("ID Autoincrement test failed!", firstRowId + 1, secondRowId); }
public CookieDatabase(Context context, String name) { helper = new MSQLiteBuilder() .version(VERSION_1) .createTable(TABLE_COOKIE) .insertColumn(TABLE_COOKIE, COLUMN_NAME, String.class) .insertColumn(TABLE_COOKIE, COLUMN_VALUE, String.class) .insertColumn(TABLE_COOKIE, COLUMN_EXPIRES_AT, long.class) .insertColumn(TABLE_COOKIE, COLUMN_DOMAIN, String.class) .insertColumn(TABLE_COOKIE, COLUMN_PATH, String.class) .insertColumn(TABLE_COOKIE, COLUMN_SECURE, boolean.class) .insertColumn(TABLE_COOKIE, COLUMN_HTTP_ONLY, boolean.class) .insertColumn(TABLE_COOKIE, COLUMN_PERSISTENT, boolean.class) .insertColumn(TABLE_COOKIE, COLUMN_HOST_ONLY, boolean.class) .build(context, name, DB_VERSION); db = helper.getWritableDatabase(); }