Prabakaran Raja
Prabakaran Raja

Reputation: 720

How the result set passed in JavaScript?

I have a code that is working fine. I just copied from the internet.

  db.transaction(function (tx, rs) {
   tx.executeSql("SELECT * FROM persons", [],
         function(tx, rs) {
          callback(rs);
         },
         function(){alert("Failed to fetch data");});
   });
}

here, the rs specifies the result set. I just wanna know, whether any variable given as the second parameter ( function(tx, rs) ) will be taken as a result set?

If not, where will we get the result set of the given query.

Thanks in advance

Upvotes: 1

Views: 172

Answers (1)

Paul Roub
Paul Roub

Reputation: 36438

This should be writen as:

db.transaction(function (tx) {
   tx.executeSql("SELECT * FROM persons", [],
         function(tx, rs) {
          callback(rs);
         },
         function(){alert("Failed to fetch data");});
   });
}

the rs parameter in your transaction-handler function doesn't actually exist. db.transaction creates a transaction object, and passes it into the handler function. In this case, the handler is calling executeSql on the transaction object; the function that handles the results of executeSql does take a result-set parameter.

You don't set, pass, or create the rs parameter - it's created based on the results of the SQL query.

Upvotes: 2

Related Questions