SQLite3 C++ Query near "CASE": syntax error

Using SQLite3 C++ implementation though I believe this error is more general.
I’m simply trying to do a statement that says:

“If the column ‘lastPlayed’ does not exist in the table ‘Players’, ALTER the table and add it to said table”

Here’s my query:

    query = string("CASE WHEN COL_LENGTH('Players', 'lastPlayed') IS NULL ")
    +   " BEGIN "
    +   "ALTER TABLE Players "
    +   "ADD lastPlayed DATETIME DEFAULT now"
    +   " END "

The error:

near “CASE”: syntax error

What am I doing wrong here?

Source: c++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.