0

I'm using sqlite3 in my c++ program and am trying to run an SQL string in the sqlite3_get_table function.

Here's my sql string.

SELECT name FROM sqlite_master WHERE type='table' AND name=test_table;

I keep getting the error "no such column "test_table"" .

All I am trying to do is confirm the existence of a table in my database. That's all. Any clues as to what's wrong with my string.

1
  • 3
    Your posting is ambiguous about the use of quotes in the string. What you posted is not a valid C++ string (because the double-quotes are not escaped), nor is it a valid SQL string because it cannot start with a double-quote. Commented Jan 8, 2017 at 0:06

1 Answer 1

4

In SQLite double quotes ('"') is the identifier-escape character, so assuming this is your SQL (raw SQL, nothing to do with C++):

SELECT
    name
FROM
    sqlite_master
WHERE
    type = 'table'
    AND
    name = "test_table;"

Is equivalent to:

...
name = test_table

...which obviously isn't what you want.

You should use single-quoted strings in SQL, and the statement-terminating semicolon should go at the very end:

SELECT
    name
FROM
    sqlite_master
WHERE
    type = 'table'
    AND
    name = 'test_table';
Sign up to request clarification or add additional context in comments.

Comments

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.