Testing database on Android: ProviderTestCase2 or RenamingDelegatingContext?

后端 未结 5 2044
[愿得一人]
[愿得一人] 2020-12-13 04:14

I\'ve implemented access to a database using SQLiteOpenHelper from the android.database package within some classes (with pattern DAO).

I wrote some jun

5条回答
  •  再見小時候
    2020-12-13 04:49

    private static String db_path = "/data/data/android.testdb/mydb";
    private SQLiteDatabase sqliteDatabase = null;
    private Cursor cursor = null;
    private String[] fields;
    
    /*
     * (non-Javadoc)
     * 
     * @see dinota.data.sqlite.IDataContext#getSQLiteDatabase()
     */
    public SQLiteDatabase getSQLiteDatabase() {
        try {
    
            sqliteDatabase = SQLiteDatabase.openDatabase(db_path, null,
                    SQLiteDatabase.OPEN_READWRITE);
            sqliteDatabase.setVersion(1);
            sqliteDatabase.setLocale(Locale.getDefault());
            sqliteDatabase.setLockingEnabled(true);
            return sqliteDatabase;
        } catch (Exception e) {
            return null;
        }
    
    }
    

    if you give the exact location of the sqlite db(in my case it's db_path), using the above method you can find-out whether it returns an sqlitedatabase or not.

提交回复
热议问题