I'm breaking my bigger problem into a few bitesize chunks to resolve. I'm practicing Javascript/SQL interactions - and failing at the third hurdle, being inserting data:
var databaseOptions = {
fileName: "sqlite_WAtest",
version: "1.0",
displayName: "SQLite WA Test",
maxSize: 1024
}; // End databaseOptions
var database = openDatabase(
databaseOptions.fileName,
databaseOptions.version,
databaseOptions.displayName,
databaseOptions.maxSize
); // End database
database.transaction(
function( transaction ){
// Create our table if it doesn't exist
transaction.executeSql(
"CREATE TABLE IF NOT EXISTS WORKOUTS (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, WOdate, WOtype);");
},function(){
alert('error Creating!');
},function(){
alert('success Creating');
}
); // end database.transaction
// Try and insert dummy info into table
database.transaction(
function( transaction ){
// Insert the data
transaction.executeSql('INSERT INTO WORKOUTS (WOdate, WOtype) VALUES ("Test 1","Test 2")');
},function(){
alert('error inserting!');
},function(){
alert('success inserting');
}
); // end database.transaction
When I load this page the alert fires saying "success creating!" - good news.
However I then get "error inserting" = not so good news.
The error is that there is no column named WOdate in the table WORKOUTS.
I've re-written the INSERT code a few times but I can't get it to work how I would expect it to. I'm tracking the table in the Safari Storage window and no data is getting into the table.
Can anyone shed some light on this?
Aucun commentaire:
Enregistrer un commentaire