我想将一些< strong >大量离线数据(超过100 MB)存储在用户手机中,并使用< strong >加密数据库。如果可能,我还希望预装分发数据库。我也看到过这个链接。
我知道有webdatabase这个东西,但因为它被认为是废弃的技术,建议我不要使用它。
我还看到了一些第三方插件,例如SQLite插件,但它仅适用于iOS和Android设备,而我则需要针对4个平台(ios、android、blackberry、windows)进行开发。
除了自己编写代码之外,还有其他解决方案吗?
我想将一些< strong >大量离线数据(超过100 MB)存储在用户手机中,并使用< strong >加密数据库。如果可能,我还希望预装分发数据库。我也看到过这个链接。
我知道有webdatabase这个东西,但因为它被认为是废弃的技术,建议我不要使用它。
我还看到了一些第三方插件,例如SQLite插件,但它仅适用于iOS和Android设备,而我则需要针对4个平台(ios、android、blackberry、windows)进行开发。
除了自己编写代码之外,还有其他解决方案吗?
最近我制作了一款需要使用以下两种数据库的应用程序,目标操作系统相同:
1. LocalStorage ::
检查localStorage是否可用
function supports_html5_storage() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
}
将一个项目存储到本地存储中
localStorage.setItem("bar", foo);
或者localStorage["bar"] = foo;
从本地存储中获取一个项目
var foo = localStorage.getItem("bar");
或者var foo = localStorage["bar"];
2. SQLite数据库(更方便,更持久)
设置你的数据库
var shortName = 'BHCAppDB';
var version = '1.0';
var displayName = 'BHCAppDB';
var maxSize = 65535;
if (!window.openDatabase){
alert('!! Databases are not supported in this Device !! \n\n We are sorry for the inconvenience and are currently working on a version that will work on your phone');
}
db = openDatabase(shortName, version, displayName,maxSize);
createAllTables(db);
创建您的表格
function createAllTables(db){
db.transaction(function(transaction){
transaction.executeSql("CREATE TABLE IF NOT EXISTS Profile(id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT, gender TEXT,age INTEGER)");
}
执行SQL查询
transaction(function(transaction){
var rowCount = 'SELECT * FROM Profile';
transaction.executeSql(rowCount,[],function(transaction,result){
if(result.rows.length == 0){
var sqlString = 'INSERT INTO Profile (name,gender,age) VALUES("自己","Female",18)';
transaction.executeSql(sqlString);
}
});
});
编辑::我忘记在最后一个选项中添加了:)
3. 在所有设备上使用本机存储
这是Phonegap的最佳部分。您可以使用Phonegap插件调用在所有设备上调用本机插件类。在调用期间,您可以将参数传递给类,而本机类可以将您的数据存储在操作系统本身中。
例如::在iOS中,您创建一个.plugin .h和.m类并将其注册到Cordova.plist文件中。完成后,您需要使用Phonegap从JavaScript发送对类的调用。使用NSDictionary或任何其他NSArray类型接收参数后,您可以调用CoreData类来存储无限量的数据。你永远不会用完内存。
也可以以类似的方式为所有其他操作系统执行此操作:)
要进行加密,请尝试以下方法:SQLCipher
以下是有关如何使用现有SQLite数据库的其他信息。在此示例中,encrypted.db是您创建的全新数据库和pragma。
ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'secret'; -- create a new encrypted database
CREATE TABLE encrypted.t1(a,b); -- recreate the schema in the new database (you can inspect all objects using SELECT * FROM sqlite_master)
INSERT INTO encrypted.t1 SELECT * FROM t1; -- copy data from the existing tables to the new tables in the encrypted database
DETACH DATABASE encrypted;
http://gauravstomar.blogspot.com/2011/08/prepopulate-sqlite-in-phonegap.html