2010年9月27日星期一

webos database

这应该并不局限于pre的webos,应该说是html5的sql教程。因为webkit比较好的支持html5,所以基于webkit浏览器的iphone,palm的pre,都应该能很好地应用sqlite数据库。下面以pre的为主。


webos里面的sqlite的db储存位置一般是在:
假如加多一个ext:,那么db会储存在:/media/internal/.app-storage
但名字都是随机的,那么他怎么联系起来的呢?原来他是将显示的名字,和真实的名字存储在/var/home/root/html5-databases/Databases.db里面(我看的是1.4.1版本)。在databases这个table里。里面的表结构如下:
运行sqlite Databases.db .schema
CREATE TABLE Databases (guid INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT, name TEXT, displayName TEXT, estimatedSize INTEGER, path TEXT);
CREATE TABLE Origins (origin TEXT UNIQUE ON CONFLICT REPLACE, quota INTEGER NOT NULL ON CONFLICT FAIL);

openDatabase( DatabaseName, DatabaseVersion, DisplayName, EstimatedSize )

这里要小心填写数据库的版本参数,如果你设置的和本地的版本不符合,操作将会失败。这个参数的原理是 有机会扩展和升级数据库,但也可能带来一大堆其他的麻烦。

执行查询
通过数据库事务(transaction)进行异步访问(asynchronous access)的接口:

transaction.executeSQL( SQLStatement, SQLParameters, ResultsetCallback, ErrorCallback )

以及我们如何使用:

db.transaction(function(tx)   {   tx.executeSql('SELECT * FROM MyTable WHERE CategoryField = ?',   [ selectedCategory ],   function (tx, rs) { displayMyResult(rs); },   function (tx, err) { displayMyError(err); } );   });

这个迷人的例子展示了如何从DB中取得数据,或者说是如何执行SQL语句,再这个例子中 displayMyResult(rs) 与 displayMyError(err) 只是个占位符,代表你对错误信息做的任何事情。

这就是它的基本知识,现在你就可以写自己的离线应用了!

1 条评论:

  1. Response to the COVID-19 바카라 사이트 pandemic has considerably impacted industrial gambling plenty of} jurisdictions around the world. The aim of this evaluation is to systematically determine and describe the survey knowledge and findings thus far inspecting the impact on individual gambling and gambling disorder. Make sure might have} the time and money for what's really important. The legislature rejects another request for an automatic accounting and reporting system.

    回复删除