创建与数据库表同名的缓冲区
我在很多地方都遇到过这段代码:
DEFINE BUFFER Customer FOR Customer.
我有两个问题:
这样做的目的是什么?为什么创建与表同名的缓冲区是有益的?
当编写访问该表/缓冲区的代码时,Progress 如何知道是直接访问 DB 还是通过缓冲区访问?
I've run across this code in a number of places:
DEFINE BUFFER Customer FOR Customer.
I have two questions:
What is the purpose of this? Why is it beneficial to create a buffer with the same name as the table?
When writing code to access this table/buffer, how does Progress know whether to access the DB directly or through the buffer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1:通常是为了管理缓冲区的范围。
例如,如果您有一个包含多个内部过程的过程,这些内部过程都访问同一个表,那么该表的默认缓冲区最终将作用于顶级过程块。例如 -
最终将客户缓冲区的范围限定为包含过程。如果您试图使内部过程保持松散耦合和自包含,那么您可能不希望出现这种行为。因此,您需要在每个内部过程中定义一个缓冲区。
当然,定义缓冲区还有其他原因,但是当您看到定义与表同名的缓冲区的代码时,通常与范围有关。
2:它总是通过缓冲区访问DB。每个表都有一个与表同名的默认缓冲区,因此
将查找名为 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 -
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
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.