Search in sources :

Example 16 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project weex-example by KalicyZhou.

the class HistoryManager method deletePrevious.

private void deletePrevious(String text) {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    try {
        db = helper.getWritableDatabase();
        db.delete(DBHelper.TABLE_NAME, DBHelper.TEXT_COL + "=?", new String[] { text });
    } finally {
        close(null, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 17 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project weex-example by KalicyZhou.

the class HistoryManager method deleteHistoryItem.

public void deleteHistoryItem(int number) {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    Cursor cursor = null;
    try {
        db = helper.getWritableDatabase();
        cursor = db.query(DBHelper.TABLE_NAME, ID_COL_PROJECTION, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
        cursor.move(number + 1);
        db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + cursor.getString(0), null);
    } finally {
        close(cursor, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 18 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project mobile-center-sdk-android by Microsoft.

the class DatabaseManagerTest method getDatabaseException.

@Test(expected = RuntimeException.class)
public void getDatabaseException() {
    /* Mocking instances. */
    Context contextMock = mock(Context.class);
    SQLiteOpenHelper helperMock = mock(SQLiteOpenHelper.class);
    when(helperMock.getWritableDatabase()).thenThrow(new RuntimeException()).thenThrow(new RuntimeException());
    /* Instantiate real instance for DatabaseManager. */
    DatabaseManager databaseManager = new DatabaseManager(contextMock, "database", "table", 1, null, null);
    databaseManager.setSQLiteOpenHelper(helperMock);
    /* Get database. */
    databaseManager.getDatabase();
}
Also used : Context(android.content.Context) SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project zxing by zxing.

the class HistoryManager method addHistoryItem.

public void addHistoryItem(Result result, ResultHandler handler) {
    // considered secure.
    if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) || handler.areContentsSecure() || !enableHistory) {
        return;
    }
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
    if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
        deletePrevious(result.getText());
    }
    ContentValues values = new ContentValues();
    values.put(DBHelper.TEXT_COL, result.getText());
    values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
    values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
    values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    try {
        db = helper.getWritableDatabase();
        // Insert the new entry into the DB.
        db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
    } finally {
        close(null, db);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SharedPreferences(android.content.SharedPreferences) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 20 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project zxing by zxing.

the class HistoryManager method deletePrevious.

private void deletePrevious(String text) {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    try {
        db = helper.getWritableDatabase();
        db.delete(DBHelper.TABLE_NAME, DBHelper.TEXT_COL + "=?", new String[] { text });
    } catch (SQLException sqle) {
        Log.w(TAG, sqle);
    } finally {
        close(null, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException)

Aggregations

SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)46 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)36 Cursor (android.database.Cursor)21 Test (org.junit.Test)14 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)9 ContentValues (android.content.ContentValues)7 Result (com.google.zxing.Result)6 SQLException (android.database.SQLException)5 SharedPreferences (android.content.SharedPreferences)3 DateFormat (java.text.DateFormat)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 SQLiteException (android.database.sqlite.SQLiteException)2 Changes (com.pushtorefresh.storio.sqlite.Changes)2 RawQuery (com.pushtorefresh.storio.sqlite.queries.RawQuery)2 Date (java.util.Date)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 TypeMappingFinder (com.pushtorefresh.storio.TypeMappingFinder)1 InsertQuery (com.pushtorefresh.storio.sqlite.queries.InsertQuery)1 Serializable (java.io.Serializable)1