Reputation: 812
I have 5 tables in my web SQL database. I want to export this data into a text file using Javascript code.
This text file needs to be stored in Phone's local storage.
Then this needs to be sent via email using JS code only.
Please help.
Upvotes: 0
Views: 1823
Reputation: 1759
Connect to websql using javascript:
var db = openDatabase('mydb', '1.0', 'my db', 2 * 1024 * 1024);
var data = "";
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM ' + tablename, [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++) {
data += results.rows.item(i).text;
}
});
});
Once you have the data; either directly mail it using cordova email plugin.
window.plugin.email.open({
to: Array, // email addresses for TO field
cc: Array, // email addresses for CC field
bcc: Array, // email addresses for BCC field
attachments: Array, // paths to the files you want to attach or base64 encoded data streams
subject: String, // subject of the email
body: String, // email body (could be HTML code, in this case set isHtml to true)
isHtml: Boolean, // indicats if the body is HTML or plain text
}, callback, scope);
Or write it to a file, on write end call the above method with path to attachment
Upvotes: 3