Search in sources :

Example 21 with SQLiteOpenHelper

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

the class HistoryManager method clearHistory.

void clearHistory() {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    try {
        db = helper.getWritableDatabase();
        db.delete(DBHelper.TABLE_NAME, null, null);
    } finally {
        close(null, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 22 with SQLiteOpenHelper

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

the class HistoryManager method buildHistoryItems.

public List<HistoryItem> buildHistoryItems() {
    SQLiteOpenHelper helper = new DBHelper(activity);
    List<HistoryItem> items = new ArrayList<>();
    SQLiteDatabase db = null;
    Cursor cursor = null;
    try {
        db = helper.getReadableDatabase();
        cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
        while (cursor.moveToNext()) {
            String text = cursor.getString(0);
            String display = cursor.getString(1);
            String format = cursor.getString(2);
            long timestamp = cursor.getLong(3);
            String details = cursor.getString(4);
            Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
            items.add(new HistoryItem(result, display, details));
        }
    } finally {
        close(cursor, db);
    }
    return items;
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Result(com.google.zxing.Result)

Example 23 with SQLiteOpenHelper

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

the class HistoryManager method hasHistoryItems.

public boolean hasHistoryItems() {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    Cursor cursor = null;
    try {
        db = helper.getReadableDatabase();
        cursor = db.query(DBHelper.TABLE_NAME, COUNT_COLUMN, null, null, null, null, null);
        cursor.moveToFirst();
        return cursor.getInt(0) > 0;
    } finally {
        close(cursor, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 24 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 25 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)

Aggregations

SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)49 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)38 Cursor (android.database.Cursor)21 Test (org.junit.Test)16 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)9 ContentValues (android.content.ContentValues)8 Result (com.google.zxing.Result)6 Context (android.content.Context)5 SQLException (android.database.SQLException)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 SharedPreferences (android.content.SharedPreferences)3 DateFormat (java.text.DateFormat)3 ArrayList (java.util.ArrayList)3 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 Stream (com.annimon.stream.Stream)1 TypeMappingFinder (com.pushtorefresh.storio.TypeMappingFinder)1 InsertQuery (com.pushtorefresh.storio.sqlite.queries.InsertQuery)1