sqlite &flex - 如果不存在则插入?

sqlite amp; flex - insert into if not exists?(sqlite amp;flex - 如果不存在则插入?)
本文介绍了sqlite &flex - 如果不存在则插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 - 如果不存在则插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
FastAPI + Tortoise ORM + FastAPI Users (Python) - Relationship - Many To Many(FastAPI+Tortoise ORM+FastAPI用户(Python)-关系-多对多)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)