0

I am using c++ QSQLDatabase (SQLITE driver) to interact with an sqlite3 database. The c++ code uses queries that have the database's name before the table name like this :

SELECT * 
FROM database_name.table_name ...

But the query is rejected with an error:

no such table : database_name.table_name

No way to change the query formats, is there any way in QSQLDatabase / SQLITE to make these kind of queries valid (without changing the queries)

Thank you for your help

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mike
  • 1
  • 1

1 Answers1

1

database_name is what SQLite calls a schema name. It starts with two - main, which is the originally opened database, and temp, where temporary tables, indexes, etc. are stored. You can't change the initial database being called main, but you can ATTACH new databases with arbitrary names (And possibly using a throw away in-memory database or unnamed temporary db as the initial one if you're only going to use fully qualified schema-name.table-name notation):

ATTACH 'another_database.db' AS database_name;
SELECT * FROM database_name.table_name;
Shawn
  • 47,241
  • 3
  • 26
  • 60