0

I see the statement in executeSql like below:

addTodo: function (text) {
        app.db.transaction(function (tx) {
            var ts = new Date();
            tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (?,?)", [text, ts], app.onSuccess, app.onError);
        });
    },

My question is: what does the " VALUES (?,?) " mean?

2 Answers 2

1

That's a prepared statement, which you should use to prevent SQL Injection attacks. E.g.

var text = "foo";
var ts = "bar";
tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (?,?)", [text, ts]);

is the same as:

tx.executeSql("INSERT INTO todo(todo, added_on) VALUES ('foo','bar')");
Sign up to request clarification or add additional context in comments.

Comments

1

Those are parameters that will be properly prepared and substituted by the array argument following the SQL statement.

So

tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (?,?)", ['do this', '10/05/2014']);

will result in

INSERT INTO todo(todo, added_on) VALUES ('do this', '10/05/2014')

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.