Reputation: 2959
I have the following script that I am using in a QString in qt and supplying to a QSqlQuery to create tables in a Sqlite database.
The Script.
CREATE TABLE accounts
(
A_Id INTEGER PRIMARY KEY,
Account_Name TEXT,
Account_Date TEXT
);
CREATE TABLE statements
(
S_Id INTEGER PRIMARY KEY,
Statement_Name TEXT
);
CREATE TABLE transactions
(
T_Id INTEGER PRIMARY KEY,
A_Id INTEGER,
S_Id INTEGER,
Amount REAL,
Transaction_Date TEXT,
FOREIGN KEY(A_Id) REFERENCES accounts(A_Id),
FOREIGN KEY(S_Id) REFERENCES statements(S_Id)
);
However when the scripts runs only the first table gets created in the database.
Thanks for any help.
Upvotes: 3
Views: 2639
Reputation: 361
Maybe this help you:
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("your_nameDB.db");
QSqlQuery query(db);
query.exec("CREATE TABLE Accounts"
"(A_Id INTEGER PRIMARY KEY, Account_Name TEXT,Account_Date TEXT)");
Upvotes: 1
Reputation: 8221
QSqlQuery forwards the statement to the SQlite driver where the query-strings is analysed by sqlite3_prepare(...). The documentation says that "These routines only compile the first statement in zSql". Conclusion: This is a "feature" of SQLite.
Upvotes: 3