title: sqlite3 error: no such table: when checking if table exists
body: <p>I have read several posts but still cannot figure out what is wrong here. 
  I have a c++ wrapper to call the sqlite. I want to test if the table exists before it is created, by reading <a href="https://stackoverflow.com/questions/1601151/how-do-i-check-in-sqlite-whether-a-table-exists">check-in-sqlite-whether-a-table-exists</a>, I use the following sql statement to check a table exists</p>
  
  <blockquote>
    <p>"SELECT name FROM test.db WHERE type='table' AND name='table1';"</p>
  </blockquote>
  
  <p>The main code is the following: </p>
  
  <pre><code>static int callback(void *db, int argc, char **argv, char **azColName){
    for(int i=0; i&lt;argc; ++i){
      printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
    }
    return 0;
  }
  
  class SqliteAccessor {
  public:
  open(){ sqlite3_open("test.db", &amp;m_db); }
  createTable1(){
    string sql = "CREATE TABLE table1(one TEXT);";
    char *zErrMsg = 0;
    int rc = sqlite3_exec(m_db, sql.c_str(), callback, 0, &amp;zErrMsg);
    if( rc != SQLITE_OK ){
      printf("SQL error: %s", zErrMsg);
      sqlite3_free(zErrMsg);
    }
  }     
  hasTable1(){
    string sql = "SELECT name FROM test.db WHERE type='table' AND name='table1'";
    char *zErrMsg = 0;
    int rc = sqlite3_exec(m_db, sql.c_str(), callback, 0, &amp;zErrMsg);
    if( rc != SQLITE_OK ){
      printf("SQL error: %s", zErrMsg); // Error: no such table: test.db 
      sqlite3_free(zErrMsg);
    } 
  }
  private:
  sqlite3* m_db;
  }
  
  main(){
    SqliteAccessor sql;
    sql.open(); // success;
    sql.createTable1(); // success;
    sql.hasTable1(); // fail
  }
  </code></pre>
  
  <p>I also tried with cli api: </p>
  
  <pre><code>sqlite3 test.db
  sqlite&gt; create table table1(one varchar(10));
  sqlite&gt; SELECT * FROM test.db;
  Error: no such table: test.db
  sqlite&gt; SELECT name FROM test.db WHERE type='table' AND name='table1';
  Error: no such table: test.db
  // however, if I run .tables, then it is there.
  sqlite&gt; .tables
  table1
  </code></pre>
  
  <p>it is the same error, but why such error? it is the lastest sqlite amalgamation version. </p>