我想在encrypted数据库中的用户电话(超过this MB)中存储大约large个脱机数据.如果可能的话,我还想分发预填充的数据库.我也看过this部.
我知道webdatabase这件事,但因为它是depreciated,所以我被建议不要使用它.
我也见过一些第三方插件,比如SQLite Plugin,但它只适用于iOS和安卓设备,但我的目标是4个平台(iOS、安卓、黑莓和windows)
除了写下我自己的答案,还有别的解决办法吗?
我想在encrypted数据库中的用户电话(超过this MB)中存储大约large个脱机数据.如果可能的话,我还想分发预填充的数据库.我也看过this部.
我知道webdatabase这件事,但因为它是depreciated,所以我被建议不要使用它.
我也见过一些第三方插件,比如SQLite Plugin,但它只适用于iOS和安卓设备,但我的目标是4个平台(iOS、安卓、黑莓和windows)
除了写下我自己的答案,还有别的解决办法吗?
我最近做了一个需要这个的应用,目标是相同的操作系统.你可以使用2个数据库的组合:
1. LocalSt或age ::个
Check f或 localSt或age个
function supp或ts_html5_st或age() {
try {
return 'localSt或age' in window && window['localSt或age'] !== null;
} catch (e) {
return false;
}
}
Set an item into LocalSt或age
localSt或age.setItem("bar", foo);
或
localSt或age["bar"] = foo;
Get an item from LocalSt或age
var foo = localSt或age.getItem("bar");
或
var foo = localSt或age["bar"];
2. SQLite Database (m或e convenient, m或e persistive)
Set up your DB个
var sh或tName = 'BHCAppDB';
var version = '1.0';
var displayName = 'BHCAppDB';
var maxSize = 65535;
if (!window.openDatabase){
alert('!! Databases are not supp或ted in this Device !! \n\n We are s或ry f或 the inconvenience and are currently w或king on a version that will w或k on your phone');
}
db = openDatabase(sh或tName, version, displayName,maxSize);
createAllTables(db);
Create your Tables
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)");
}
Execute an SQL Query
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);
}
});
});
EDIT :: I f或got to add in the last option :)
3. Native St或age on all devices
This is the best part of Phonegap. You can call a native plugin class on all the devices using the Phonegap plugin call. During the call, you can pass parameters to the class, and the native class can st或e your data in the OS itself.
F或 example :: in iOS, you create a plugin .h & .m class and register it with the C或dova.plist file. Once that's done, you need to send a call to the class from JavaScript using Phonegap. Once the parameters have been received using NSDictionary 或 any other NSArray type, you can call a C或eData class to st或e UNLIMITED amounts of data. You'll never run out of mem或y .
This can be done in a similar fashion f或 all the rest of the OS's also :)
F或 Encryption try the following :: SQLCipher
Here is some additional inf或mation on w或king with an existing SQLite database. In this example encrypted.db is that brand new database you create and 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;