[AC-552] Custom Database path - isn't created if non-existent (Android)
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2016-01-04T05:07:52.000+0000 |
Affected Version/s | Appcelerator Studio 4.5.0 |
Fix Version/s | n/a |
Components | Appcelerator Modules |
Labels | android, database |
Reporter | Ryan Gartin |
Assignee | Ashraf Abu |
Created | 2016-01-02T04:10:43.000+0000 |
Updated | 2016-01-04T05:07: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
Darn, this should be a TI-MOB. Ooops! Created pull request for a fix, https://github.com/appcelerator/titanium_mobile/pull/7607.
Mods please delete.
[~nitrag] Noted. This ticket is a duplicate of TC-5819. Closing this ticket.