Static and dynamic queries in OpenEdge

The question is very common, let's see the pros and cons of each in OpenEdge in terms of readability, flexibility and code performance.

Static queries:

+ 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) 

Dynamic queries:

 + flexibility: you can build predicate-expression completely runtime + flexibility: you can work with each field not specifying its name, fe 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 readings.

+4
source share
1 answer

The condition of the static query condition can be changed "on the fly" as follows:

 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 request is processed in the same way as any regular static request.

readability: "buffer-handle: buffer-field (" field-name "): buffer-value" construct "refers to dynamic buffers - it is perfectly acceptable to use static buffers in dynamic queries (via name-name BUFFER: HANDLE), therefore dynamic buffers queries can be used with static buffers, and it is not always necessary to de-reference a field using its handle.

performance: the last time I did the comparison, dynamic queries were slower than static queries for the same query condition. Surface - they are more flexible than static queries.

reusability: after the dynamic request buffer structure has been configured, AFAIK cannot be changed. However, it can be reopened with a new filter condition, the same as with a static query.

+4
source

Source: https://habr.com/ru/post/1497377/


All Articles