在phonegap应用程序中导出sqlite数据库 [英] Export sqlite db in phonegap app

查看:179
本文介绍了在phonegap应用程序中导出sqlite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序使用cordova(phonegap)和他自己的sqlite DB(我的意思是我们没有安装一个外部sqlite)。

We have an app using cordova (phonegap) and his own sqlite DB (I mean we didn't install an external sqlite).

我们需要备份DB到SD存储器,但是我们有问题将sqlite文件从phonegap导出到SD。

We need to backup the DB into the SD memory but we have problems to export the sqlite file from phonegap to SD.

有人可以帮助我们吗?

推荐答案

这是听起来不错的Cordova 3.5和org.apache.cordova.file 1.2.1

This sounds good with Cordova 3.5 and org.apache.cordova.file 1.2.1

不同的路径。

window.resolveLocalFileSystemURL("file:///data/data/my-app-name/databases/name-of.db", function(fs) {
                var parent = "file://mnt/external_sd/";
                var newName = "mybackup.db";
                window.resolveLocalFileSystemURL(parent, function(directoryEntry) {
                    fs.copyTo(directoryEntry, newName, function() {
                        alert("Backup ok");
                    }, failFiles);
                });
            }, failFiles);

function failFiles(error) {        
  if (error.code == FileError.NOT_FOUND_ERR) alert("Message : NOT_FOUND_ERR" )
  else if (error.code == FileError.SECURITY_ERR) alert("Message : SECURITY_ERR" )
  else if (error.code == FileError.ABORT_ERR) alert("Message : ABORT_ERR" )
  else if (error.code == FileError.NOT_READABLE_ERR) alert("Message : NOT_READABLE_ERR" )
  else if (error.code == FileError.ENCODING_ERR) alert("Message : ENCODING_ERR" )
  else if (error.code == FileError.NO_MODIFICATION_ALLOWED_ERR) alert("Message : NO_MODIFICATION_ALLOWED_ERR" )
  else if (error.code == FileError.INVALID_STATE_ERR) alert("Message : INVALID_STATE_ERR" )
  else if (error.code == FileError.SYNTAX_ERR) alert("Message : SYNTAX_ERR" )
  else if (error.code == FileError.INVALID_MODIFICATION_ERR) alert("Message :  INVALID_MODIFICATION_ERR" )
  else if (error.code == FileError.QUOTA_EXCEEDED_ERR) alert("Message : QUOTA_EXCEEDED_ERR" )
  else if (error.code == FileError.PATH_EXISTS_ERR) alert("Message : PATH_EXISTS_ERR" )  
}  

这篇关于在phonegap应用程序中导出sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆