Index: src/org/sqlite/app/customsqlite/CustomSqlite.java ================================================================== --- src/org/sqlite/app/customsqlite/CustomSqlite.java +++ src/org/sqlite/app/customsqlite/CustomSqlite.java @@ -14,12 +14,14 @@ import java.lang.InterruptedException; import org.sqlite.database.sqlite.SQLiteDatabase; import org.sqlite.database.sqlite.SQLiteStatement; import org.sqlite.database.sqlite.SQLiteDatabaseCorruptException; +import org.sqlite.database.sqlite.SQLiteOpenHelper; import android.database.Cursor; +import android.content.Context; /* import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; */ @@ -165,11 +167,11 @@ return res; } /* - ** Check that using openSeeDatabase() creates encrypted databases. + ** If this is a SEE build, check that encrypted databases work. */ public void see_test_1() throws Exception { if( !SQLiteDatabase.hasCodec() ) return; SQLiteDatabase.deleteDatabase(DB_PATH); @@ -185,11 +187,11 @@ test_result("see_test_1.1", res, ".one.two.three"); db.close(); test_result("see_test_1.2", db_is_encrypted(), "encrypted"); - db = SQLiteDatabase.openOrCreateDatabase(DB_PATH.getPath(), null, new DoNotDeleteErrorHandler()); + db = SQLiteDatabase.openOrCreateDatabase(DB_PATH, null); db.execSQL("PRAGMA key = 'secretkey'"); res = string_from_t1_x(db); test_result("see_test_1.3", res, ".one.two.three"); db.close(); @@ -218,10 +220,51 @@ } finally { db.close(); } test_result("see_test_1.5", res, "encrypted"); } + + class MyHelper extends SQLiteOpenHelper { + public MyHelper(Context ctx){ + super(ctx, DB_PATH.getPath(), null, 1); + } + public void onConfigure(SQLiteDatabase db){ + db.execSQL("PRAGMA key = 'secret'"); + } + public void onCreate(SQLiteDatabase db){ + db.execSQL("CREATE TABLE t1(x)"); + } + public void onUpgrade(SQLiteDatabase db, int iOld, int iNew){ + } + } + + /* + ** If this is a SEE build, check that SQLiteOpenHelper still works. + */ + public void see_test_2() throws Exception { + if( !SQLiteDatabase.hasCodec() ) return; + SQLiteDatabase.deleteDatabase(DB_PATH); + + MyHelper helper = new MyHelper(this); + SQLiteDatabase db = helper.getWritableDatabase(); + db.execSQL("INSERT INTO t1 VALUES ('x'), ('y'), ('z')"); + + String res = string_from_t1_x(db); + test_result("see_test_2.1", res, ".x.y.z"); + test_result("see_test_2.2", db_is_encrypted(), "encrypted"); + + helper.close(); + helper = new MyHelper(this); + db = helper.getReadableDatabase(); + test_result("see_test_2.3", res, ".x.y.z"); + + db = helper.getWritableDatabase(); + test_result("see_test_2.4", res, ".x.y.z"); + + test_result("see_test_2.5", db_is_encrypted(), "encrypted"); + } + public void run_the_tests(View view){ System.loadLibrary("sqliteX"); DB_PATH = getApplicationContext().getDatabasePath("test.db"); DB_PATH.mkdirs(); @@ -233,10 +276,11 @@ try { report_version(); csr_test_1(); thread_test_1(); see_test_1(); + see_test_2(); myTV.append("\n" + myNErr + " errors from " + myNTest + " tests\n"); } catch(Exception e) { myTV.append("Exception: " + e.toString() + "\n"); myTV.append(android.util.Log.getStackTraceString(e) + "\n");