Creating a Buffer with the Same Name as the Database Table

倾然丶 夕夏残阳落幕 提交于 2020-01-03 14:28:21

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5487889/creating-a-buffer-with-the-same-name-as-the-database-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!