2013-08-16 37 views
4

问题非常普遍,让我们从代码可读性,灵活性和偏离表现的角度来看OpenEdge中的每个优缺点。
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) 

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

+0

这其实不是问题吗? – Jensd

+0

@Jensd我改变了公式 – Progressive

回答

4

静态查询的过滤条件可以“飞”来改变,像这样:

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),所以动态查询缓冲区可以使用w /静态缓冲区,并不总是需要使用它的句柄去引用一个字段。

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

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

+1

谢谢。没有注意到使用动态查询和静态缓冲区的可能性。这非常有用! – Progressive