gpt4 book ai didi

delphi - 如何使用 Delphi(BDE 组件)优化更新 Postgres?

转载 作者:行者123 更新时间:2023-11-29 12:47:59 25 4
gpt4 key购买 nike

我在 Delphi 7 和 PostgreSQL 9.0 中工作,我的数据库中有五十个表。我有一种情况,我必须同时执行五十多个更新查询,每个表一个。

我有一个程序:

var
sTheQuery : string;
begin
sTheQuery :='update diary set remark = replace(remark,'+#39+'%'+#39+', '$')';
QueryImages.SQL.Clear;
QueryImages.SQL.Text:=sTheQuery;
QueryImages.ExecSQL;

sTheQuery :='update bioschema set note = replace(note,'+#39+'%'+#39+', '$')';
QueryImages.SQL.Clear;
QueryImages.SQL.Text:=sTheQuery;
QueryImages.ExecSQL;
sTheQuery :='update displaymaps set region = replace(region, '+#39+'%'+#39+', '$')';
QueryImages.SQL.Clear;
QueryImages.SQL.Text:=sTheQuery;
QueryImages.ExecSQL;
sTheQuery :='update ecosystem set description = replace(description,'+#39+'%'+#39+', '$')';
QueryImages.SQL.Clear;
QueryImages.SQL.Text:=sTheQuery;
QueryImages.ExecSQL;

.
.
// total 50 times
end;

这种方法是一种改进吗?:

    var
sTheQuery : string;
begin
sTheQuery :='update diary set remark = replace(remark,'+#39+'%'+#39+', '$');';
sTheQuery :=sTheQuery+'update bioschema set note = replace(note,'+#39+'%'+#39+', '$');';
sTheQuery :=sTheQuery+'update displaymaps set region = replace(region, '+#39+'%'+#39+', '$');';
sTheQuery :=sTheQuery+'update ecosystem set description = replace(description, '+#39+'%'+#39+', '$');';
.
.//total 50 times
.
QueryImages.SQL.Clear;
QueryImages.SQL.Text:=sTheQuery;
QueryImages.ExecSQL;
end.

最佳答案

我都不推荐。我会重构我的代码以创建一个接受查询并处理它的方法,就像这个伪代码一样:

executeQuery(String sTheQuery) {
QueryImages.SQL.Clear;
QueryImages.SQL.Text:=sTheQuery;
QueryImages.ExecSQL;
}

doit() {
executeQuery('update diary set remark = replace(remark,'+#39+'%'+#39+', '$')');
executeQuery('update bioschema set note = replace(note,'+#39+'%'+#39+', '$')');
executeQuery('update displaymaps set region = replace(region, '+#39+'%'+#39+', '$')');
executeQuery('update ecosystem set description = replace(description, '+#39+'%'+#39+', '$')');
}

这是可维护的、易于阅读和理解的,并且性能可以接受。

关于delphi - 如何使用 Delphi(BDE 组件)优化更新 Postgres?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8515831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com