QSqlTableModel with SQLITE on multiple databases
-
Hello,
I'm using SQLITE with multiple databases so to reference a table usually [databasename].[tablename] is to be used. When using sqlite3 I additionally need to use ' characters to enclose the table names, e.g. 'testdb.users'. While trying to do:
QSqlTableModel model = new QSqlTableModel (this, myDatabase);
model->setTable ("testdb.users");
model->setEditStrategy (QSqlTableModel::OnManualSubmit);
if (model->select ())the select call returns false. I also tried:
model->setTable "'testdb.users'"
with the same result. -
Hi and welcome to devnet,
How are you creating these databases ?
-
Can you provide a minimal code sample that shows how you initialise your database ?
-
Hi,
I don't see much from that but here is a very shortened exampe:// attach different database
if (dbName.compare (currentDbName) != 0)
{
QString qs = QString ("attach database '%1' as '%1').arg
(dbName);
QSqlQuery q (qs);
// Error procressing}
// create a table
QString qs = QString ("create table if not exist '%1' (id int "
"primary ke, name varchar(256))")
.arg (getTableName (dbname, tableName));
// getTable name delivers a QString like "myDatabase.maTable".
QSqlQuer q (qs);
// Error processing// insert values
QString qs = QString ("insert into '%1' (%2) values (%3)")
.arg (getTableName (dbName, tableName))
.arg (headers.join (", "))
arg (values.join (", "));
// headers and values are QStringLists of equal size taht contain // the table headers to be filled with values
// error processing -
Please reread the original posting. I never stated that multiple databases reside in a single file but in different ones.
If you don't have any experiance with that matter why do you replay?