Project: titanium
Issue TIMOB-20443: Custom Database Path (Android) Does Not Create New DB with Ti.Database.open
In iOS I can open (or create if doesn't exist) a database in the applicationDataDirectory and it works fine: {code:java} db = Ti.Database.open(Ti.Filesystem.applicationDataDirectory+filename); {code} However in Android I get errors. It doesn't seem like it will even try to create a database. {code:java} 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: android.database.sqlite.SQLiteConnection.nativeOpen(Native Method) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:318) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:228) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:512) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:891) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:861) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696) [ERROR] : SQLiteDatabase: android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671) [ERROR] : SQLiteDatabase: ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:66) [ERROR] : SQLiteDatabase: org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method) [ERROR] : SQLiteDatabase: org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62) [ERROR] : SQLiteDatabase: org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908) [ERROR] : SQLiteDatabase: org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131) [ERROR] : SQLiteDatabase: org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:352) [ERROR] : SQLiteDatabase: android.os.Handler.dispatchMessage(Handler.java:98) [ERROR] : SQLiteDatabase: android.os.Looper.loop(Looper.java:145) [ERROR] : SQLiteDatabase: 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: ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:77) [WARN] : W/System.err: org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method) [WARN] : W/System.err: org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62) [WARN] : W/System.err: org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908) [WARN] : W/System.err: org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131) [WARN] : W/System.err: org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:352) [WARN] : W/System.err: android.os.Handler.dispatchMessage(Handler.java:98) [WARN] : W/System.err: android.os.Looper.loop(Looper.java:145) [WARN] : W/System.err: org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112) [ERROR] : Error opening DB: {} {code} also tried this: {code:java} 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: android.app.ContextImpl.makeFilename(ContextImpl.java:2853) [WARN] : W/System.err: android.app.ContextImpl.validateFilePath(ContextImpl.java:2837) [WARN] : W/System.err: android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1503) [WARN] : W/System.err: android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1497) [WARN] : W/System.err: android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:276) [WARN] : W/System.err: ti.modules.titanium.database.DatabaseModule.open(DatabaseModule.java:70) [WARN] : W/System.err: org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method) [WARN] : W/System.err: org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62) [WARN] : W/System.err: org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908) [WARN] : W/System.err: org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1131) [WARN] : W/System.err: org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:352) [WARN] : W/System.err: android.os.Handler.dispatchMessage(Handler.java:98) [WARN] : W/System.err: android.os.Looper.loop(Looper.java:145) [WARN] : W/System.err: org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112) [ERROR] : Error opening DB: {} {code} Neither work for Android I have created a PR and Fix for this here: https://github.com/appcelerator/titanium_mobile/pull/7607
Story points: 1