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

后端 未结 2 1564
一生所求
一生所求 2021-01-22 15:02

I have a webapp that I\'m building, and have just started with SQLite. I have been able to create my form, open the database I created, create the table, and fields i need, and

相关标签:
2条回答
  • 2021-01-22 15:41

    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.

    0 讨论(0)
  • 2021-01-22 16:01

    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/

    0 讨论(0)
提交回复
热议问题