OpenEdge中的静态查询与动态查询 [英] Static vs dynamic queries in OpenEdge
问题描述
问题非常普遍,让我们从代码的可读性,灵活性和性能方面看一下OpenEdge的优缺点.
Question is very common, let's see pros and cons of each in OpenEdge in terms of code readability, flexibility and performance off course.
静态查询:
+ 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)
欢迎添加和更正.以及任何相关阅读的链接.
Additions and corrections are welcome. As well as links to any related read.
推荐答案
可以动态地更改静态查询的过滤条件,如下所示:
A static query's filter condition can be changed "on the fly" like so:
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").
从这里开始,该查询与任何普通的静态查询一样.
from here the query is treated the same as any normal static query.
可读性:"buffer-handle:buffer-field(" field-name):buffer-value"构造是指动态缓冲区-在动态查询中使用静态缓冲区是完全可以接受的(通过BUFFER表名: HANDLE),因此动态查询缓冲区可以与静态缓冲区一起使用,并且不一定总是需要使用其句柄来取消引用字段.
readability: the "buffer-handle:buffer-field("field-name"):buffer-value" construct refers to dynamic buffers - it's perfectly acceptable to use static buffers in dynamic queries (via the BUFFER table-name:HANDLE), so dynamic query buffers can be used w/static buffers and it's not always necessary to de-reference a field using it's handle.
性能:上一次进行比较时,对于相同的查询条件,动态查询的速度比静态查询慢.好处是它们比静态查询更灵活.
performance: last time I did a comparison, dynamic queries were slower than static queries for the same query condition. The upside is they're more flexible than static queries.
可重用性:设置动态查询的缓冲区结构AFAIK后,将无法对其进行更改.可以使用与静态查询相同的新过滤条件重新打开它.
reusability: Once a dynamic query's buffer structure has been set, AFAIK, it can't be changed. It can be re-opened with a new filter condition same as a static query though.
这篇关于OpenEdge中的静态查询与动态查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!