我正在嘗試使用 KMM,但我對 SQLDelight 有疑問。這是AppDatabase.sq檔案的代碼示例。
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;
當我運行我收到的應用程式時:
android.database.sqlite.SQLiteException: no such table: Settings (code 1 SQLITE_ERROR): , while compiling: SELECT version FROM Settings.
如果我使用Android Studio的App Inspection打開應用程式創建的資料庫,似乎只存在表和其他與我的表無關的自動生成的表。Data
我的 2 個問題(請參閱 SQL 代碼中的注釋以獲取數字參考)是:
- 我如何
Settings從.sq檔案中創建這個表 ( )? - 如何在不從實際代碼呼叫任何函式的情況下將新值插入到我的表中?
如果您需要整個專案
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/534401.html
上一篇:如何在某個片段上隱藏漢堡包圖示?
