問題描述
我正在使用 flex 開發我的第一個桌面應用程序,并且我也是第一次使用 sqlite.
I'm using flex to develop my first desktop app and I'm working with sqlite for the first time as well.
我正在創建我的數據庫和所有表,我還想將幾行數據添加到幾個表中,以便用戶在首次安裝時可以使用一些數據.
I'm creating my database and all the tables and I would also like to add a few rows of data into a couple of the tables so that the users have some data to work with on first install.
我遇到的唯一問題是每次運行程序時它都會一遍又一遍地插入相同的數據.
The only problem I'm having is every time I run the program it keeps inserting the same data over and over again.
我只是想知道是否可以執行 - INSERT INTO IF NOT EXISTS.或其他類型的工作.
I'm just wondering if its possible to do a - INSERT INTO IF NOT EXISTS. or some other kind of work around.
謝謝!
推薦答案
感謝您的洞察力,但我仍然沒有任何運氣.
Thanks for the insight but I'm still not having any luck.
這是我的代碼
stmt.text = "CREATE TABLE IF NOT EXISTS tbl_breed ("+" breed_id INTEGER PRIMARY KEY AUTOINCREMENT, "+" breed_breed TEXT)";
stmt.execute();
stmt.text = "INSERT OR IGNORE INTO tbl_breed (breed_breed)"+" VALUES ('Test')";
stmt.execute();
好的,我解決了這個問題 - 我猜你必須對主鍵進行硬編碼,這就是我所做的
Ok so I fixed the problem - I guess you have to hard code primary key here's what i did
stmt.text = "CREATE TABLE IF NOT EXISTS tbl_breed ("+" breed_id INTEGER PRIMARY KEY AUTOINCREMENT, "+" breed_breed TEXT)";
stmt.execute();
stmt.text = "INSERT OR IGNORE INTO tbl_breed (breed_id,breed_breed)"+" VALUES ('1','test')";
stmt.execute();
這篇關于sqlite &flex - 如果不存在則插入?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!