|
| 1 | +package net.zetetic.tests; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import net.sqlcipher.Cursor; |
| 5 | +import net.sqlcipher.database.SQLiteDatabase; |
| 6 | +import net.sqlcipher.database.SQLiteOpenHelper; |
| 7 | +import net.zetetic.ZeteticApplication; |
| 8 | + |
| 9 | +import java.io.File; |
| 10 | + |
| 11 | +public class CursorAccessTest extends SQLCipherTest { |
| 12 | + |
| 13 | + @Override |
| 14 | + public boolean execute(SQLiteDatabase database) { |
| 15 | + |
| 16 | + database.close(); |
| 17 | + ZeteticApplication.getInstance().deleteDatabaseFileAndSiblings(ZeteticApplication.DATABASE_NAME); |
| 18 | + String databasesFolderPath = ZeteticApplication.getInstance() |
| 19 | + .getDatabasePath(ZeteticApplication.DATABASE_NAME).getParent(); |
| 20 | + File databasesFolder = new File(databasesFolderPath); |
| 21 | + databasesFolder.delete(); |
| 22 | + |
| 23 | + MyHelper databaseHelper = new MyHelper(ZeteticApplication.getInstance()); |
| 24 | + |
| 25 | + SQLiteDatabase db = databaseHelper.getWritableDatabase(ZeteticApplication.DATABASE_PASSWORD); |
| 26 | + |
| 27 | + Cursor results = db.rawQuery("select * from t1", new String[]{}); |
| 28 | + results.moveToFirst(); |
| 29 | + int type_a = results.getType(0); |
| 30 | + int type_b = results.getType(1); |
| 31 | + |
| 32 | + results.close(); |
| 33 | + db.close(); |
| 34 | + |
| 35 | + return (type_a == Cursor.FIELD_TYPE_STRING) && (type_b == Cursor.FIELD_TYPE_INTEGER); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public String getName() { |
| 40 | + return "Cursor Access Test"; |
| 41 | + } |
| 42 | + |
| 43 | + private class MyHelper extends SQLiteOpenHelper { |
| 44 | + |
| 45 | + public MyHelper(Context context) { |
| 46 | + super(context, ZeteticApplication.DATABASE_NAME, null, 1); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public void onCreate(SQLiteDatabase database) { |
| 51 | + database.execSQL("create table t1(a text,b integer)"); |
| 52 | + database.execSQL("insert into t1(a,b) values(?, ?)", new Object[]{"test1", 100}); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {} |
| 57 | + } |
| 58 | +} |
0 commit comments