2

I have an internal SQLite DB under "Assets" Folder in which i have stored 100 usernames & corresponding Passwords, How do i access it via phoneGap.?
I have read

Community
  • 1
  • 1
VenomVendor
  • 15,064
  • 13
  • 65
  • 96

2 Answers2

2
/**
 * Creates / Opens a connection to DB
 */
DB.openDB = function() {
    try {
        if (!window.openDatabase) {
            //alert('Cannot open database!');
        } else {
            var shortName = 'db_name';
            var version = '1.0';
            var displayName = 'DBNAME';
            var maxSize = (DEVICE_TYPE == DEVICE_ANDROID || DEVICE_TYPE == DEVICE_ANDROID_TAB) ? 5242880 : 1000000; ////819200; //65536; // in bytes // increased to support Android//163840; // 
            this.vocabDB = window.openDatabase(shortName, version, displayName, maxSize, this.DBCreated);
            this.DBSupported = true;
        }
    } catch(e) {
        //console.log("DB Error handling code goes here.");
        //console.log(e);
        return;
    }
}
GauravSTomar
  • 604
  • 1
  • 7
  • 26
1

Well, you can do a window.openDatabase() to a database in the assets folder. You'll need to copy it to the right place so that the WebView will load it. Check out this:

http://gauravstomar.blogspot.ca/2011/08/prepopulate-sqlite-in-phonegap.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+GauravSTomarBootstrappingIntelligence+(Gaurav+S+Tomar+:+Bootstrapping+Intelligence)

post as Gaurav gives you code to do this on both Android and iOS.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • Referred that too, But will try again & again ... am in Critical Situation, based on this solution i have to decide either to Continue with PhoneGap or Native. Finding Difficult to solve each issue – VenomVendor Apr 30 '12 at 01:42