tags:

views:

138

answers:

1

I have this SQL statement running on my database and I'm sure it's right, but it's not making any change to the database. How can I debug it?

The query:

UPDATE task SET name=?, description=?, startDate=?, dueDate=?, complete=?, status=?, percentComplete=?, taskType=? WHERE rowId=:rowId

I conditionally bind the first 8 parameters depending on if they are null. The last parameter is bound in all cases to the current rowId (I have verified that the rowId is correct when binding it). Something like this:

int rowIdIdx = sqlite3_bind_parameter_index(stmt, ":rowId");
if (rowIdIdx > 0) {
  sqlite3_bind_int(stmt,rowIdIdx,rowId);
}

I also verified that rowIdIdx is equal to 9 when binding rowId. But when the call to sqlite_step returns (always with SQLITE_DONE), the database is never changed, and sqlite3_changes(db) always returns 0.

However, if I remove the WHERE clause, every row in the table does get updated, and sqlite3_changes(db) returns the number of rows in the table.

This is all within a framework that I have used before where the update statements work just fine. So first of all, is there anything obvious that I'm missing, and second of all, how do I even go about trying to debug this?

Edit:

After a bit of checking, if I replace :rowId with just another normal ? parameter, it works fine. But there's a reason I'm using named parameters and I can't leave it this way. WHAT'S WRONG!?

A: 

Yep, it was a PEBKAC.

Ed Marty