无法查看 SQLite 数据库。您必须编写一些代码从应用程序中提取 SQLite 数据库,然后需要使用 DB Browser for SQLite 来查看它
要从您的应用程序中提取数据库,请查看以下代码:
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (fileSystem) {
$log.log('resolveLocalFileSystemURL - externalRootDirectory success: ', fileSystem);
//var mainDir = 'Backup';
var mainDir = 'MyAppDB/' + 'Backup' + '';
$log.log('Main dir', mainDir);
fileSystem.getDirectory(mainDir, {create: true, exclusive: false}, function (dir) {
$log.log('getDirectory success: ', dir);
});
});
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (fileSystem) {
$log.log('resolveLocalFileSystemURL - externalRootDirectory success: ', fileSystem);
var mainDir = 'MyAppDB/' + 'Backup' + '';
$log.log('Main dir', mainDir);
fileSystem.getDirectory(mainDir, {create: true, exclusive: false}, function (dir) {
$log.log('getDirectory success: ', dir);
var URI_DB = cordova.file.applicationStorageDirectory + 'databases/';
var ROOT_DIR = 'file://mnt/sdcard/';
var PARENT_DIR = ROOT_DIR + mainDir + '/';
var NAME_DB = 'DB.db';
var NEW_NAME_BACKUP = today.toString() + '_' + 'MYApp.db';
$log.log('parent directory', PARENT_DIR);
$log.log('backup name', NEW_NAME_BACKUP);
window.resolveLocalFileSystemURL(URI_DB + NAME_DB, function (fs) {
window.resolveLocalFileSystemURL(PARENT_DIR, function (directoryEntry) {
fs.copyTo(directoryEntry, NEW_NAME_BACKUP, function () {
$log.log('The database backup was successful.');
localforage.setItem('dbbackup', today);
q.resolve('success');
});
}, failFiles);
});
});
});
return q.promise;
失败案例:
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');
}
你还需要安装文件插件。