SQLite Insert Multiple Records into table

本文解决了一个关于SQLite不支持多行插入的问题,通过使用UNION ALL的方法实现了一次性插入多条记录,有效提高了数据处理效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The SQLite does not support below insert SQL statement:

INERT INTO table(col1, col2, ..., coln) VALUES (1v1, 1v2, ..., 1vn), (2v1, 2v2, ..., 2vn), (3v1, 3v2, ..., 3vn), ..., (nv1, nv2, ..., nvn);



This is the solution:

INSERT INTO table(col1, col2, ..., coln)

SELECT 1v1, 1v2, ..., 1vn UNION ALL SELECT 2v1, 2v2, ..., 2vn UNION ALL SELECT 3v1, 3v2, ..., 3vn ... UNION ALL SELECT nv1, nv2, ..., nvn;



Recently, I handled a project that every 50 millisecond or 20 millisecond the main process would receive a message to insert a record into DB.

It is strange that the DB function was called successfully, but the messages of main process were blocked, which lead the main window blocked.

It took me much time to find the reason. but i got nothing.

Then I thought maybe something was being blocked in SQLite Lib, when "insert operating" so frequently executed.


Why not insert multiple records into the DB one time??


So, I write a thread to handle it. insert records to DB every 5 second.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值