Problem Description
I'm trying to use Ti.Database.Install() to install on the SD card.
Following the example in:
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Database.install-method.html
the code is:
var db = Ti.Database.install("/mydb", Ti.Filesystem.externalStorageDirectory + "mydb");
Actual Results
I always get
E/TiJSError( 552): (main) [1997,4200] ----- Titanium Javascript Runtime Error -----
E/TiJSError( 552): (main) [1,4201] - In ti:/invoker.js:92,19
E/TiJSError( 552): (main) [0,4201] - Message: Uncaught Error: File appdata://mydb contains a path separator
E/TiJSError( 552): (main) [0,4201] - Source:
return delegate.apply(invoker.__thisObj__, args);
E/V8Exception( 552): Exception occurred at ti:/invoker.js:92: Uncaught Error: File appdata://mydb contains a path separator
Expected Results
The example working
Extra info
I've also tried:
var db = Ti.Database.install("/mydb", Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory + "mydb").nativePath);
which gives a similar error:
E/TiJSError( 671): (main) [1945,3930] ----- Titanium Javascript Runtime Error -----
E/TiJSError( 671): (main) [1,3931] - In ti:/invoker.js:92,19
E/TiJSError( 671): (main) [0,3931] - Message: Uncaught Error: File file:///mnt/sdcard/com.my.org.myapp/mydb contains a path separator
E/TiJSError( 671): (main) [0,3931] - Source: return delegate.apply(invoker.__thisObj__, args);
E/V8Exception( 671): Exception occurred at ti:/invoker.js:92: Uncaught Error: File file:///mnt/sdcard/com.my.org.myapp/mydb contains a path separator
I've also tried formatting the SD and recreating it from scratch. The results don't change.
Is there any way to copy/open the db on the external storage on Android?
@Marco - Why are you using a slash in the first parameter name?
the slash doesnt change anything. I tried out the same call with 'mydb' instead of '/mydb' and the error still occurs
@Neeraj: as Carter said, the initial slash doesn't change the results. I'd also like to point out that the API docs have the parameter order reversed, citing "install(String path, String dbName)" instead of "install(String dbName, String path)".
Thanks, Marco.
Workaround : Use absolute path of the SD card.
where com.app.testme is the appid. Regards, Anirudh
Does this workaround works with Ti.Database.install(dbName, path); ? I'm trying to install an already existing database from the Resources folder to the 'data' folder of the device. It works fine on iOS. But with Android, I get the same error as above following the doc. I tried the workaround, but I always get a No such file or directory error message. Here the paths I tested: /mnt/sdcard/com.company.app/mydb /mnt/sdcard/com.company.app/databases/mydb /mnt/sdcard/mydb /sdcard/com.company.app/mydb /sdcard/com.company.app/databases/mydb /sdcard/mydb I'm not familiar with the filesystem on Android though so maybe I missed something. Should I create folder first? Is com.company.app automatically created? (I ofcourse replaced com.company.app with the right app id inside the project)
Can I please champion this issue to be prioritised thanks!
I've also tried out to hard code path to DB without success. Furthermore, probably 'Resources' folder might be copied over external storage directory.
e.g.
{quote} var db = Ti.Database.install( '/testdb', '/mnt/sdcard/com.app.test/databases/testdb' ); 10-17 17:20:41.398: W/System.err(5072): java.io.FileNotFoundException: Resources/testdb {quote} Following Appcelerator docs does not seem to work this out: - http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Database-method-installInstall a Database to External Storage (Android)
{quote} The device is checked for the presence of external storage and a database, with a filename of mydb2 and located in the same directory as the the running script, is installed. {quote} {quote} if (Ti.Platform.name === 'android' && Ti.Filesystem.isExternalStoragePresent()) { var db2 = Ti.Database.install('mydb2', Ti.Filesystem.externalStorageDirectory + 'path' + Ti.Filesystem.separator + 'to' + Ti.Filesystem.separator + 'mydb2Installed'); } Unlike on iOS, no file extension is added. The file is copied to the absolute path provided. {quote}Added code to handle external directory. Also make sure that if the db doesn't exist, don't copy. https://github.com/appcelerator/titanium_mobile/pull/5347
3_2_X Backport PR: https://github.com/appcelerator/titanium_mobile/pull/5509
Verified fixed on: Mac OSX 10.9.2 Appcelerator Studio, build: 3.2.3.201403250634 Titanium SDK, build: 3.2.3.v20140326130916 CLI: 3.2.3-dev Alloy: 1.3.1 Android Device: Galaxy SIII (4.1.2, with external sdcard) Used the following code:
All three successfully save db files to sdcard. Closing.
We've just run into this bug in Ti.Database.open... with 5.5.1 SDK on Android 7.0 - just change the code above to Ti.Database.open and you get the "contains a path separator" error var db1 = Ti.Database.open(Ti.Filesystem.externalStorageDirectory + 'mydb1'); Sounds like the bug was fixed in install, but not in open. Workaround is to copy the file from externalStorageDirectory to applicationCacheDirectory and then use Ti.Database.install to re-install it so as to preserve the data.