将Web SQL数据库导出为文本文件,并使用javascript代码将其发送给Phonegap项目中的用户

Export Web SQL database to a text file and mail it to the user in Phonegap project using javascript code

本文关键字:代码 Phonegap 用户 项目 javascript 数据库 SQL Web 文件 文本      更新时间:2023-09-26

我有5个表在我的web SQL数据库。我想使用Javascript代码将这些数据导出为文本文件。

此文本文件需要存储在Phone的本地存储中。

然后这需要通过电子邮件发送使用JS代码。

请帮。

使用javascript连接websql:

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;
    }
  });
});

一旦你有了数据;或者直接使用cordova email插件发送。

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);

或将其写入文件,在写入端调用上面的方法,并带有附件

的路径