我想在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;

Database相关问答推荐

Oracle批量数据处理

如何在mongodb数据库中设置导入的CSV文件的字段之间的关系

将数据集上传到 Hub 时停止运行时会导致什么?

在 bindParam 中使用 LIKE 进行 MySQL PDO 查询

SQL 查询至少其中一项

PostgreSQL 嵌套 INSERTs / WITHs 用于外键插入

管理数据库中的产品计数

PostgreSQL - 按时间戳值分组?

SQL Server - 使用计数函数与相交

如何将 MySQL Workbench 连接到 Amazon RDS?

PostgreSQL - 将每个表转储到不同的文件中

将 XML 存储在数据库中是否不好?

如何从 MySQL 行中修剪前导和尾随引号?

为什么在 Hibernate 中不推荐hibernate.connection.autocommit = true?

postgreSQL 同时将列类型从 int 更改为 bigint

CouchDB、MongoDB 和 Redis 中的哪个数据库适合从 Node.js 开始?

PHP PDO: error number' 00000' when query is correct

由多个用户编辑数据库记录

我应该在哪里存储外键?

C# IEnumerator/yield struct 可能不好?