javascript - Web Sql select statement not able to extract third column -


demo

i unable retrieve third value of row showing undefined when displayed using alert box .what trying achieve insert 4 rows table , retrieve them required sorted based on column

html

<div id="status" name="status">status message</div> 

javascript

var db = opendatabase('mydb', '1.0', 'test db', 4 * 1024 * 1024); var msg; db.transaction(function (tx) {     tx.executesql('create table if not exists logs (id unique, log text,log1 text)');     tx.executesql('insert logs (id, log,log1) values (1, "foobar","sa")');     tx.executesql('insert logs (id, log,log1) values (2, "logmsg","da")');     msg = '<p>log message created , row inserted.</p>';     document.queryselector('#status').innerhtml = msg; });  db.transaction(function (tx) {     tx.executesql('select * logs', [], function (tx, results) {         var len = results.rows.length,             i;         msg = "<p>found rows: " + len + "</p>";         document.queryselector('#status').innerhtml += msg;          (i = 0; < len; i++) {             msg = "<p><b>" + results.rows.item(i).log + "</b></p>";             document.queryselector('#status').innerhtml += msg;             var book = results.rows.item(i);             console.log(book);              alert(book.log1);          }      }, null); }); 

here make similar yours, , here it's working. here ids like:

id integer primary key

so when insert, don't have use them, let web sql take care of it

tx.executesql('insert logs (log,log1) values ("logmsg","da")'); 

also, use promises (the code bellow using angularjs

self.query = function(query, bindings) {         bindings = typeof bindings !== 'undefined' ? bindings : [];         var deferred = $q.defer();          self.db.transaction(function(transaction) {             transaction.executesql(query, bindings, function(transaction, result) {                 deferred.resolve(result);             }, function(transaction, error) {                 deferred.reject(error);             });         });          return deferred.promise;     };      self.fetchall = function(result) {         var output = [];          (var = 0; < result.rows.length; i++) {             output.push(result.rows.item(i));         }          return output;     };      self.fetch = function(result) {         return result.rows.item(0);     }; 

so can use way:

return db.query('select * registro dia = ? , mes = ? , ano = ? order horario', [dia, mes, ano])         .then(function(result){             return db.fetchall(result);         }); 

i hope can directions...


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -