2

I'm trying to use the current date and time to do INSERT and SELECT statements, but the data is not getting inserted in WebSQL. Below is my code:

CREATION..
myDb.transaction(function(tr) {
        tr.executeSql('CREATE TABLE IF NOT EXISTS stInfo (keyNum INTEGER NOT NULL PRIMARY KEY, timestamp varchar(255) );');         
});

INSERTION
function insert() {
 var timeStamp = getCurrentDate();  returns in format YYYY-MM-DD HH:MM
myDb.transaction(function(tr) {
          tr.executeSql("INSERT INTO stInfo('keyNum','timestamp') values(215424," + timeStamp + ");");              
 });
}
1
  • Try removing the comments around keyNum and timestamp in your insert statement. That's the first thing that doesn't look right. Commented May 29, 2012 at 20:10

2 Answers 2

2

Old post, but I will answer it anyway. Easiest would be:

tr.executeSql('INSERT INTO stInfo (keyNum, timestamp) VALUES (?,?)',["215424", timestamp]);

Also, watch your double and single quotes.

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

Comments

0

Use single quotes to surround the timestamp:

tr.executeSql("INSERT INTO stInfo('keyNum','timestamp') values(215424,'" + timeStamp + "')");

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.