当前位置:网站首页>SQLite one line SQL implementation updates if there is one, inserts if there is none, multiple conditions, complex conditions
SQLite one line SQL implementation updates if there is one, inserts if there is none, multiple conditions, complex conditions
2022-06-11 05:32:00 【Trace】
SQLite a line SQL Update if there is one, insert if there is none , Multiple conditions , Complex conditions
Sample code :https://github.com/miqt/MultiProgressKV/blob/master/MultiProgressKV/src/main/java/com/miqt/multiprogresskv/DBHelper.java
For example, you want to implement the following logic
if (db has name == Xiao Ming && height == 170cm)
update ....
else
insert ....
You can refer to the following SQL:
CREATE TABLE [TABLE_NAME](
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[name] TEXT NOT NULL ,
[attr] TEXT NOT NULL ,
[value] TEXT NOT NULL );
CREATE UNIQUE INDEX [TABLE_NAME]
ON [TABLE_NAME](
[name],
[attr]);
CREATE UNIQUE INDEX [TABLE_NAME] Declared that only name, and attr The unique index is calculated only when it is repeated , This applies to scenarios like inserting a book , A book can only have one title and author , And a separate title , And the author himself , It may correspond to many books .
The following statement executes , There are updates , If nothing, the effect of inserting , following SQL Executing multiple times will only produce one row of results , And modify name, perhaps attr Any column , A new one will be inserted .
REPLACE INTO TABLE_NAME
(
name ,
attr ,
value
)
VALUES
(
'《 Journey to the west 》' ,
' author ' ,
' Wu chengen '
) ;
边栏推荐
- (15) Infrared communication
- QT Road (1) -- Introduction to pro file
- Handle double quotation mark escape in JSON string
- [opencv learning problems] 1 Namedwindow() and imshow() show two windows in the picture
- Games101 job 7-path tracing implementation process & detailed interpretation of code
- Flask develops and implements the like comment module of the online question and answer system
- Cocoapods installation error
- es-ik 安装报错
- Zed2 camera calibration -- binocular, IMU, joint calibration
- Get the third-party interface
猜你喜欢

Maximum number of points on the line ----- hash table solution

jvm调优五:jvm调优工具和调优实战

自定义View之基础篇
![[entry level basics] node basic knowledge summary](/img/91/39aff1ade1f37f54b61a454e32d487.jpg)
[entry level basics] node basic knowledge summary

Big meal count (time complexity) -- leetcode daily question

WinForm (I) introduction to WinForm and use of basic controls

(15) Infrared communication

PCB走線到底能承載多大電流

lower_ Personal understanding of bound function

Share | defend against physically realizable image classification attacks
随机推荐
ReferenceError: server is not defined
Introduction to coordinate system in navigation system
Technology | image motion drive interpretation of first order motion model
PCB走线到底能承载多大电流
Section IV: composition and materials of asphalt mixture (2) -- main materials of asphalt
Concurrent search set
[entry level basics] node basic knowledge summary
微信小程序text内置组件换行符不换行的原因-wxs处理换行符,正则加段首空格
高斯白噪声(white Gaussian noise,WGN)
Why is the smart door lock so popular? What about the smart door locks of MI family and zhiting?
Recommend a free intranet penetration open source software that can be used in the local wechat official account under test
Recherche sur l'optimisation de Spark SQL basée sur CBO pour kangourou Cloud Stack
Customize the layout of view Foundation
Share | guide language image pre training to achieve unified visual language understanding and generation
Maximum number of points on the line ----- hash table solution
智能门锁为什么会这么火,米家和智汀的智能门锁怎么样呢?
QT Road (1) -- Introduction to pro file
Common methods of tool class objectutil
Wxparse parsing iframe playing video
Multithreading tutorial (XXVI) field updater and atomic accumulator