0

I am trying to prepare a SQL statement using QT's built-in Sqlite engine.

The following statement:

UPDATE collections SET collection_type=:v1 WHERE 
(collections.collection_name = 'asfg')

fails in QSqlQuery's prepare statement (prepare returns false).

QSqlError err = db.lastError(); gives no error message...

However if I execute the same statement (by replacing :v1 with a number) in the sqlite prompt it succeeds.

What am I doing wrongly?

Edit:

What I was doing wrongly was to not to have checked the database structure. The table was missing. Too bad I can't downvote my own post :(

0

1 Answer 1

2

Replace :v1 with ? and then use

query.addBindValue(v1);

v1 is variable containing value.

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

6 Comments

The colon instead of a question mark is a valid placeholder in SQLite, and seems valid in QSqlQuery, too. However this wouldn't make the prepare statement fail.
And ?v1 is not a valid placeholder.
@Murphy please don't make any more changes to my post. Your edits was invalid.
@CL Indeed, it isn't; mea culpa. "?" and addBindValue(v1) should work together, and ":v1" and bindValue(":v1", v1) should, too, but obviously you're not supposed to mix them.
@CL previous version is not what I wrote. That was invalid edit. Now it fixed.
|

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.