【问题标题】:Static vs dynamic queries in OpenEdgeOpenEdge 中的静态与动态查询
【发布时间】:2013-08-18 12:55:45
【问题描述】:

问题很常见,让我们看看 OpenEdge 在代码可读性、灵活性和性能方面的优缺点。

静态查询:

+   readability: convenient `buffer.field` notation
+   performance: higher (supposedly, need comments)
-/+ "global scope" allows to handle all previously used buffers, but could lead
                 to ambiguousness, so you'll have to clarify it with a table
                 name (table.field instead of field)
-   flexibility: you cannot alternate predicate-expression much,
                 even IF function is not recommended (can affect performance)      

动态查询:

+   flexibility: you can build predicate-expression completely runtime
+   flexibility: you can work with each field not specifying its name,
                 f.e. you can process all fields of certain record in cycle
+   flexibility: are reusable (need comments on this point)
+/- "local scope" allows to use only buffers specified in `SET-BUFFERS` method
-   readability: a little more code to write
-   performance: slightly slower (not sure)

欢迎补充和更正。以及任何相关阅读的链接。

【问题讨论】:

  • 这其实不是问题吧?
  • @Jensd 我改变了配方

标签: progress-4gl openedge progress-db


【解决方案1】:

静态查询的过滤条件可以像这样“即时”更改:

DEFINE QUERY q-name FOR table-name.
DEFINE VARIABLE h-qry   AS HANDLE      NO-UNDO.
h-qry = QUERY q-name:HANDLE.
h-qry:QUERY-PREPARE("for each table-name where table-name.field-name = 1").

从这里查询被视为与任何普通静态查询相同。

可读性:"buffer-handle:buffer-field("field-name"):buffer-value" 结构指的是动态缓冲区 - 在动态查询中使用静态缓冲区是完全可以接受的(通过 BUFFER 表名: HANDLE),因此动态查询缓冲区可以与静态缓冲区一起使用,并且并不总是需要使用它的句柄取消引用字段。

性能:上次我做了一个比较,对于相同的查询条件,动态查询比静态查询慢。好处是它们比静态查询更灵活。

可重用性:一旦设置了动态查询的缓冲区结构,AFAIK,就无法更改。不过,可以使用与静态查询相同的新过滤条件重新打开它。

【讨论】:

  • 谢谢。没有注意到使用动态查询和静态缓冲区的可能性。很有用!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-07
相关资源
最近更新 更多