Reading info from sqlite database, Syntax? How do I use it in html5 webapp?

ε祈祈猫儿з 提交于 2019-12-02 01:28:22

See the spec and this Apple tutorial. In short, you need to add data and error callbacks. Also, you should be passing an empty array (or null) because your query has no parameters.

db.transaction(function(tx) {
   tx.executeSql('SELECT * FROM Drinks', 
                 [],
                 function(tx, results)
                 {
                   // results is a http://dev.w3.org/html5/webdatabase/#sqlresultset .  
                   // It has insertId, rowsAffected, and rows, which is
                   // essentially (not exactly) an array of arrays. 
                 },
                 function(tx, error)
                 {

                 }
   );
});

It's up to you whether to use named or anonymous functions.

EDIT: I made a working demo at http://jsfiddle.net/WcV6Y/7/ . It's tested in Chrome 5.0.375.70.

try something like this

tx.executeSql('SELECT * FROM foo', [], function (tx, results) {
             var len = results.rows.length;
             for (var i = 0; i < len; ++i) {
                var obj = results.rows.item(i);
                alert(obj);
              }
          });

also see this for short tutorial http://html5doctor.com/introducing-web-sql-databases/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!