SQLException instead of creating new database

152 views
Skip to first unread message

LJB

unread,
Apr 29, 2014, 12:51:12 AM4/29/14
to sqlc...@googlegroups.com
Hi all,

I've converted my Android SQLite databases to SQLcipher with version 2.2.2 and all worked well. Thanks. I also successfully last year updated to 3.0.2.
However, I've just installed the new Ubuntu 14.04 on a new SSD with all the stuff need to continue with my project. I've imported my project from the old hard drive with ADT and copied the latest version 3.1.0 into the project. Now when I run my android application I get a SQLException when I call the getReadableDatabase() which should force the call of onCreate() in my SQLiteOpenHelper obj. I did uninstall the application from my test phone per advise from other threads. I also reverted back to 3.0.2 with the same result. This seems to have started once I deleted the database files which was created using 2.2.2, but I am not sure.

Please help! Thx
LJB


The exception simply state "not an error", but yet I never get a new database created. Here is the android exception dump:
:
04-28 15:22:29.366: I/Database(27099): JNI_OnLoad called
04-28 15:22:29.366: I/Database(27099): JNI_OnLoad register methods
04-28 15:22:29.421: E/SQLiteOpenHelper(27099): Couldn't open /data/data/com.a.b/files/x.db for writing (will try read-only):
04-28 15:22:29.421: E/SQLiteOpenHelper(27099): net.sqlcipher.database.SQLiteException: not an error
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1942)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:907)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:197)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at net.sqlcipher.database.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:184)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at com.modp.payup2.dbHandler.getSize(dbHandler.java:105)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at com.modp.payup2.MainActivity.onCreate(MainActivity.java:762)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.app.Activity.performCreate(Activity.java:5206)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.app.ActivityThread.access$700(ActivityThread.java:140)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.os.Looper.loop(Looper.java:137)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at android.app.ActivityThread.main(ActivityThread.java:4921)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at java.lang.reflect.Method.invokeNative(Native Method)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at java.lang.reflect.Method.invoke(Method.java:511)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
04-28 15:22:29.421: E/SQLiteOpenHelper(27099):     at dalvik.system.NativeStart.main(Native Method)

Main Activity code:

        :
        SQLiteDatabase.loadLibs(this);
       
        // Open encrypted transaction database with ID
        try {
            // Access database just to be sure
            dbHandler dbh = new dbHandler(this, key);
            dbh.getSize(); // This will call getReadableDatabase() and force creation if not yet exist
            :
        } catch (SQLiteException e) { <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< THIS EXCEPTION OCCUR ON CALL TO getReadableDatabase() in getSize()
            Log.e(TAG, "Failed to access database. " + e.getMessage());
            return;
        }

SQLiteOpenHelper:
    :
    private static final int     DATABASE_VERSION = 2;
    private String                key = null;
    private dbHandler          dbh = new dbHandler();
    static String                 DATABASE_NAME = "x.db";
   
    public dbHandlerTransaction(Context context, String key) {
        super(context, context.getFilesDir().getAbsolutePath() + "/" + DATABASE_NAME, null, DATABASE_VERSION);
        this.key = key;
    }
 
   public int getSize() {
           SQLiteDatabase db = this.getReadableDatabase(this.key);
           :
           :
           db.close();
           return size;
    }




LJB

unread,
Apr 29, 2014, 6:09:16 AM4/29/14
to sqlc...@googlegroups.com
Just want to add that if I change the code to using SQLite then everything works as it should - that is if the database does not exist the onCreate() is called.
My permissions is also correct on the app.

LJB

Nick Parker

unread,
Apr 29, 2014, 9:08:51 AM4/29/14
to sqlc...@googlegroups.com
Hello LJB,

This error is likely due to the application not properly including
either the native .so files, or the icudt46.zip file within the assets
directory. Could you verify your application has been properly
configured via the steps defined within the Android integration article
here [1]?

[1] http://sqlcipher.net/sqlcipher-for-android/
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "SQLCipher Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlcipher+...@googlegroups.com
> <mailto:sqlcipher+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
Nick Parker

signature.asc

LJB

unread,
Apr 29, 2014, 10:18:34 AM4/29/14
to sqlc...@googlegroups.com
Hi Nic,

You were right. It seem the ICU file in our SVN was corrupted. I previously checked it by opening the ZIP and verifying the date of the DAT file with the one in v3.1.0. I now did a SHA1SUM check and found it different. I copied and committed the version from the v3.1.0 release.

All seems back to normal. Thanks for your help. Sorry for the stupid mistake.
LJB

Nick Parker

unread,
Apr 29, 2014, 10:26:34 AM4/29/14
to sqlc...@googlegroups.com
Hi LJB,

Glad to hear the issue is resolved.
signature.asc
Reply all
Reply to author
Forward
0 new messages