0

Im using HTML5SQL.js in Google Chrome but I only get this error:

Uncaught TypeError: Cannot read property 'sql' of undefined

Please take a look at this script that I'm using: http://jsfiddle.net/mporras/Cx3x5/

2 Answers 2

1

Like it says in the guide on htm5sql.com, there are several ways to give html5sql.js sql statements and your error is caused by mixing a couple different ways.

Like xdazz mentioned in his answer, the first argument to html5sql.process can just be a string with one or more sql statements. You can also pass in an array of sql statement strings or sql statement objects. The advantage of using sql statement objects is you can define the data array and specify individual success callbacks.

So essentially you could do this:

$(function() {
   html5sql.openDatabase("demo", "Demo Database", 5 * 1024 * 1024);

   html5sql.process(
       [
            "DROP TABLE IF EXISTS speedtest;",
            "CREATE TABLE speedtest (id INTEGER PRIMARY KEY, label TEXT);",
           {
              sql: "INSERT INTO speedtest VALUES (?, ?);",
              data: [1,'1'],
              success: function(transaction, results) {
                   console.info('Success Inserting First Record');
              }
           },
           {
              sql: "INSERT INTO speedtest VALUES (?, ?);",
              data: [2,'2'],
              success: function(transaction, results) {
                 console.info('Success Inserting Second Record');
              }
           }
       ],
       function() {
          console.log("Final Sucess Callback");
       },
       function(error, failingQuery) {
          console.error("Error: " + error.message);
       }
   );
});

A demo of this can be found in this jsfiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. Actually, I was waiting for your very answer, it's just that I didn't have a way to send you a "private message". This totally fixed it for me. Please continue documenting your guide, it still misses some things like how to catch the results from a SQL query.
0

The html5sql.process function signature is html5sql.process(SQL, finalSuccessCallback, errorCallback), so try the way below, and here is the demo.

$(function() {
    html5sql.openDatabase("demo", "Demo Database", 5 * 1024 * 1024);

    var st = "DROP TABLE IF EXISTS speedtest; CREATE TABLE speedtest (id INTEGER PRIMARY KEY, label TEXT); INSERT INTO speedtest VALUES (1, '1');INSERT INTO speedtest VALUES (2, '2');";

    html5sql.process( 
      st,
      function(transaction, results) {
         console.info('Success');
      },
      function(error, failingQuery) {
         console.error("Error: " + error.message);
      });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.