添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
  • 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?

  • 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.
    procedure p2:
        find last customer no-lock.
    

    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.

    One of the big advantages that this technique has is that it prevents accidental side effects, particularly record-locks, from impacting the main procedure or other internal procedures. – Tom Bascom Mar 31, 2011 at 10:15 Thanks for the comments Gordon - that was a great explanation. I understand the logic behind this, but I don't agree with the naming convention. To me, a buffer should still be prefixed with a "b-" or something else to explicity define that you're referencing the buffer. Using the DB table name as the buffer name only seems to make the code more confusing than it needs to be. – pmartin Apr 1, 2011 at 16:09

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.