[TIMOB-20443] Custom Database Path (Android) Does Not Create New DB with Ti.Database.open
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-03-28T21:03:16.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.4.0, Release 5.2.2 |
Components | Android |
Labels | Android |
Reporter | Ryan Gartin |
Assignee | Ashraf Abu |
Created | 2016-01-04T03:28:31.000+0000 |
Updated | 2016-03-29T18:48:52.000+0000 |
Description
In iOS I can open (or create if doesn't exist) a database in the applicationDataDirectory and it works fine:
db = Ti.Database.open(Ti.Filesystem.applicationDataDirectory+filename);
However in Android I get errors. It doesn't seem like it will even try to create a database.
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,"1554006938");
db = Ti.Database.open(file);
error log:
[DEBUG] : TiDatabase: (KrollRuntimeThread) [12816,20327] Opening database from filesystem: /data/data/com.abc.abc/app_appdata/1554006938
[ERROR] : SQLiteLog: (14) cannot open file at line 32470 of [9491ba7d73]
[ERROR] : SQLiteLog: (14) os_unix.c:32470: (2) open(/data/data/com.abc.abc/app_appdata/1554006938) -
[ERROR] : SQLiteDatabase: Failed to open database '/data/data/com.abc.abc/app_appdata/1554006938'.
[ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:318)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:228)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:512)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:891)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:861)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
[ERROR] : SQLiteDatabase: at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671)
[ERROR] : SQLiteDatabase: at ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:66)
[ERROR] : SQLiteDatabase: at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] : SQLiteDatabase: at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[ERROR] : SQLiteDatabase: at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908)
[ERROR] : SQLiteDatabase: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131)
[ERROR] : SQLiteDatabase: at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:352)
[ERROR] : SQLiteDatabase: at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] : SQLiteDatabase: at android.os.Looper.loop(Looper.java:145)
[ERROR] : SQLiteDatabase: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[WARN] : W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String ti.modules.titanium.database.TiDatabaseProxy.getName()' on a null object reference
[WARN] : W/System.err: at ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:77)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131)
[WARN] : W/System.err: at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:352)
[WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] : W/System.err: at android.os.Looper.loop(Looper.java:145)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[ERROR] : Error opening DB: {}
also tried this:
db = Ti.Database.open(Ti.Filesystem.applicationDataDirectory+"-1501149833");
error log:
[WARN] : W/System.err: java.lang.IllegalArgumentException: File appdata-private://-1501149833 contains a path separator
[WARN] : W/System.err: at android.app.ContextImpl.makeFilename(ContextImpl.java:2853)
[WARN] : W/System.err: at android.app.ContextImpl.validateFilePath(ContextImpl.java:2837)
[WARN] : W/System.err: at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1503)
[WARN] : W/System.err: at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1497)
[WARN] : W/System.err: at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:276)
[WARN] : W/System.err: at ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:70)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131)
[WARN] : W/System.err: at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:352)
[WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] : W/System.err: at android.os.Looper.loop(Looper.java:145)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[ERROR] : Error opening DB: {}
Neither work for Android
I have created a PR and Fix for this here:
https://github.com/appcelerator/titanium_mobile/pull/7607
Seems like both tickets were closed as duplicate. Reopening this.
PR https://github.com/appcelerator/titanium_mobile/pull/7607 reviewed and merged.
Reopening issue for the 5.2.2 backport: https://github.com/appcelerator/titanium_mobile/pull/7891
Verified the fix. A database is opened if exists or created & opened if does not exists. Closing. Environment: Appc Studio : 4.5.0.201602170831 Ti SDK : 5.2.2.v20160328141205, 5.4.0.v20160329102039 Ti CLI : 5.0.6 Alloy : 1.8.2 MAC El Capitan : 10.11.13 Appc NPM : 4.2.4 Appc CLI : 5.2.1 Node: 4.2.2 Nexus 6 - Android 6.0