Is it possible to load / create a database in an SD card using phoneGap in Android?

How can I load an existing .db file from an SD card or create a database on an SD card using phoneGap or any plug-in that will work with the phone?

I want to save my .db file to sdcard, because the database size may increase.

+4
source share
3 answers

The same problem I encountered, but after a long thorough reading of the phonegap-cordova library, I found that it lacked the flexibility to choose a path.

The reason may be due to the cross-platform restriction, the library bound you to using the default application path, so on another platform the library could easily get the file.

but what!! there is a trick to achieve the goal ....

function onDeviceReady() { var db = window.openDatabase("test", "1.0", "Test DB", 1000000); } 

in fact, when JavaScript calls the openDatabase () function, it does the following

  • add '/ data / data / <package_name_of_your_app> /' in front of db_name
  • and add '. db ' after db_name

ie: in the above case would be:

/ data / data / <package_name_of_your_app> /test.db

therefore the trick goes here;

 function onDeviceReady() { var db = window.openDatabase("../../../../mnt/sdcard/test", "1.0", "Test DB", 1000000); } 
  • add '../../../../mnt/sdcard/' before the name db_name, do not add the extension, since the library adds `.db ', if you add any extension, then your db file will be db_name . (yourextension) .db

now what! it will be;

  • add '/ data / data / <package_name_of_your_app> /' in front of db_name
  • and add '. db ' after db_name
  • it will take your name db _ .. / .. / .. / .. / mnt / sdcard / test '

therefore the result will be:

/ data / data / <package_name_of_your_app> /../../../../mnt/SDCard/test.db

so it will return to the root of your mobile phone and then / mnt / sdcard

+4
source

Yes it is possible. along with the changes you need to specify the path to the DB file in your connection string. for a more similar code link, see here

0
source

Yes. You can, Iโ€™ll just put the link, http://gauravstomar.blogspot.se/2011/08/prepopulate-sqlite-in-phonegap.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+GauravSTomarBootstrappingIntelligence++(Gravrav+ Bootstrapping + Intelligence )

It is actually about settling. You can get something from this. For those who want to pre-fill, this is what it is.

0
source

All Articles