创建与数据库表同名的缓冲区

发布于 2024-10-27 11:15:57 字数 226 浏览 3 评论 0原文

我在很多地方都遇到过这段代码:

DEFINE BUFFER Customer FOR Customer. 

我有两个问题:

  1. 这样做的目的是什么?为什么创建与表同名的缓冲区是有益的?

  2. 当编写访问该表/缓冲区的代码时,Progress 如何知道是直接访问 DB 还是通过缓冲区访问?

I've run across this code in a number of places:

DEFINE BUFFER Customer FOR Customer. 

I have two questions:

  1. What is the purpose of this? Why is it beneficial to create a buffer with the same name as the table?

  2. When writing code to access this table/buffer, how does Progress know whether to access the DB directly or through the buffer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千里故人稀 2024-11-03 11:15:57

1:通常是为了管理缓冲区的范围。

例如,如果您有一个包含多个内部过程的过程,这些内部过程都访问同一个表,那么该表的默认缓冲区最终将作用于顶级过程块。例如 -

procedure p1:
    find first customer no-lock.
end.

procedure p2:
    find last customer no-lock.
end.

最终将客户缓冲区的范围限定为包含过程。如果您试图使内部过程保持松散耦合和自包含,那么您可能不希望出现这种行为。因此,您需要在每个内部过程中定义一个缓冲区。

当然,定义缓冲区还有其他原因,但是当您看到定义与表同名的缓冲区的代码时,通常与范围有关。

2:它总是通过缓冲区访问DB。每个表都有一个与表同名的默认缓冲区,因此

find first <buffername>.

将查找名为 buffername 的缓冲区,该缓冲区可能是显式定义的缓冲区或隐式默认缓冲区。优先级将转到明确定义的缓冲区(如果存在)。

1: It's usually done to manage the scope of the buffers.

If you have, for example, a procedure with a number of internal procedures which all access the same table, then the default buffer for that table will end up scoped to the top level procedure block. For example -

procedure p1:
    find first customer no-lock.
end.

procedure p2:
    find last customer no-lock.
end.

would end up scoping the customer buffer to the containing procedure. If you're trying to keep your internal procedures loosely coupled and self contained, then you might not want this behaviour. So you'd define a buffer within each of the internal procedures.

Obv there are other reasons to define buffers, but when you see code that defines a buffer with the same name as the table, it's usually about scope.

2: It always access the DB through a buffer. Every table has a default buffer with the same name as the table, so

find first <buffername>.

will look for a buffer named buffername which may be an explicitly defined buffer or an implicit default buffer. Precedence will go to an explicitly defined buffer if one exists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文