Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 2361|回复: 1

SQLITE多条记录更新的问题

[复制链接]

该用户从未签到

发表于 2012-12-25 22:52:33 | 显示全部楼层 |阅读模式
翻译点资料:
为什么仅第1条记录被更新?
With Query Do
Begin
  SQL.Clear;
  SQL.Add('Update MyTable Set MyField = 2;');
  SQL.Add('Update MyTable Set MyField = 1;');
  ExecSQL
End;

BigChimp的回答:
SQLite不支持多条记录更新.可以这样用:
Code: [Select]
Update MyTable set MyField=:MyFieldPar;), then run the update statements in a loop (e.g. something like, untested,
Code: [Select]
Query.ParamByName('MyFieldPar').AsInteger:=2;
Query.ExecSQL;
Query.ParamByName('MyFieldPar').AsInteger:=1;
Query.ExecSQL

来自http://www.lazarus.freepascal.org/index.php/topic,19007.msg107801.html#msg107801
回复

使用道具 举报

该用户从未签到

发表于 2012-12-25 23:08:05 | 显示全部楼层
如果在SQLite中需要循环插入较多条记录时,使用beginTransaction()方法开启一个事务,提交事务用endTransaction() 方法,该方法提交事务时会检查事务的标志是否为成功,如果为成功则提交事务,否则回滚事务,这样会获得最快的插入速度。
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2026-7-25 02:59 , Processed in 0.027482 second(s), 11 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表