domonica domonica - 3 months ago 18
C++ Question

Sqlite 'Unrecognized token: ":" C++

I'm not sure what to do with this as I can't remove the colon from my SQL string.
Basically I am trying to execute an SQL string in Sqlite using the below code.

string database_name = "C:/Programs_C++/Project/Databases/dbase.db";

string exec_string = "SELECT * FROM " + database_name + " WHERE type='table'";

dbase_return=sqlite3_open_v2(database_name.c_str(),&db_handle,SQLITE_OPEN_READWRITE,NULL);

//But I get the error: unrecognized token: ":" ?


How do I get around this? Thanks

Answer

It looks like you have URI filenames switched on - this can be done at compile time or runtime (probably compile time for you if you didn't know about it).

If URI filenames are switched on, you need to change your filename to something like:

file:///C:/Programs_C++/Project/Databases/dbase.db

Edit: If you want to switch it off, I don't think you can do it for this one call (as the call takes a flag as part of the parameters which can only switch it on). Instead you can disable it globally by calling

sqlite3_config(SQLITE_CONFIG_URI, 0)

which tells sqlite to disable the URI filename convention globally. Note: you only need to call this once and it is not thread safe, so probably just put this at the start of your program.

However, it might be worth investigating if URI filenames are useful to you before switching them off entirely.

Comments