2

I have a local SQL Database and I need to export this in any file and import when it's needed.

EDIT : I don't wanna use webservice because I wanna to do an app without connection but with export/import database when the device is connected function. As backup...make sense?

Its possible?

Here is my code

function initDatabase() {
try {
    if (!window.openDatabase) {
        alert('Databases are not supported in this browser.');
    } else {
        var shortName = 'DB';
        var version = '1.0';
        var displayName = ' Database';
        var maxSize = 100000; //  bytes
        DB = openDatabase(shortName, version, displayName, maxSize);
        createTables();
        selectAll();
    }
} catch(e) {

    if (e == 2) {
        // Version number mismatch.
        console.log("Invalid database version.");
    } else {
        console.log("Unknown error "+e+".");
    }
    return;
}
}
  • Hmm... I've never exported/imported with javascript. There is a new File API in HTML5 that sounds promising which has decent support: http://caniuse.com/fileapi Otherwise, what I typically do in these scenarios is communicate back and forth with a web service, but that would require server-side programming. – Mister Epic Aug 09 '13 at 13:43
  • I wanna to do an app without connection but with export/import database when the device is connected function. As backup...make sense? – Programador Mobile Aug 09 '13 at 14:40
  • Browser-based javascript is deliberately prevented from accessing the local file system as a rule. You can use [`data:` URIs](http://stackoverflow.com/a/7588465/438971) to achieve a download equivalent in the browser. If you retrieved the data from the PhoneGap database that you're presumably using, then you could export as CSV as above. – Orbling Aug 09 '13 at 15:09
  • how can I export as csv? I'm using appmobi – Programador Mobile Aug 09 '13 at 15:49

0 Answers0