Home > Blockchain >  SQLDelight multiple table creation
SQLDelight multiple table creation

Time:11-15

I am experimenting with KMM but I have an issue with SQLDelight. Here is the code sample of the AppDatabase.sq file.

CREATE TABLE Data (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
content TEXT NOT NULL
);

-- ====>> Add this new table <<==== (QUESTION 1)
CREATE TABLE Settings (
version TEXT NOT NULL
);

insertItem:
INSERT INTO Data(id, content) VALUES(?,?);

removeAll:
DELETE FROM Data;

selectById:
SELECT * FROM Data WHERE id = ?;

updateById:
UPDATE Data SET content = ? WHERE id = ?;

-- ====>> I want this to be run on DB creation <<==== (QUESTION 2)
INSERT INTO Settings(version) VALUES ('1.0.0');

getVersion:
SELECT version FROM Settings;

When I run the application I receive: android.database.sqlite.SQLiteException: no such table: Settings (code 1 SQLITE_ERROR): , while compiling: SELECT version FROM Settings.

If I open the databases created by the app using the App Inspection of Android Studio it seems that only Data table exist and other autogenerated tables which have nothing to do with my tables.

My 2 questions (see comments in SQL code for number reference) are:

  1. How can I create this table (Settings) from .sq file?
  2. How can insert a new value into my table without call any function from actual code?

In case you need the whole project is compiled code

  • Related