Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Sqlite only creates one table from script

Tags:

c++

sql

sqlite

qt

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.

like image 463
Thomas Avatar asked Jul 17 '26 12:07

Thomas


1 Answers

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.

like image 76
hmuelner Avatar answered Jul 19 '26 01:07

hmuelner