It's probably RTFM but I can't find it.
The sample code gives following error
---------------------------
Unable to get SAVE-WHERE-STRING because no KEYS phrase given in DATA-SOURCE definition and no unique index found in ANKUAFD. (11895)
---------------------------
<gripe>I don't know why OpenEdge does not find the unique index, there is one, it's just not the primary index.</gripe>
I need to set the keys property for the data-source, it works when I define it statically but I need a query and I need to set it dynamically.
The table has a non-unique primary index, it also has an unique index (please no discussion on the sense or nonsense of such a table, it's an existing table and I have to deal with the db schema as it is).
I looked at the keys attribute https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/keys-attribute.html#wwconnect_header but that is read-only.
define temp-table eANKUAFD no-undo like ankuafd before-table eANKUAFDBefore
/*
field AP-NR as integer
field FU-CODE as character
field VS-CODE-F as character
field VS-CODE as character
field DPT-CODE as character
field ATT-CODE as character
field CMP-ID as decimal
field CRE-TIME as integer
...
index ANKUAFD-ID as unique CMP-ID ascending
index ANKUAFD1 as primary AP-NR ascending FU-CODE ascending VS-CODE-F ascending VS-CODE ascending DPT-CODE ascending ATT-CODE ascending
*/
.
define dataset dsAnkuafd for eANKUAFD.
&scoped static no
&if {&static}
&then
define data-source dsrcANKUAFD for ANKUAFD .
buffer eANKUAFD:attach-data-source(data-source dsrcANKUAFD:handle, "cmp-id").
&else
define variable QueryHandle as handle no-undo.
define variable SourceHandle as handle no-undo.
create query QueryHandle.
queryhandle:add-buffer(buffer ANKUAFD:handle).
queryhandle:query-prepare("for each ankuafd no-lock").
create data-source SourceHandle .
SourceHandle:query = QueryHandle.
buffer eANKUAFD:attach-data-source(SourceHandle).
&endif
dataset dsAnkuafd:fill().
find first eANKUAFD.
buffer eANKUAFD:table-handle:tracking-changes = yes.
update eANKUAFD.cre-time.
buffer eANKUAFD:table-handle:tracking-changes = no.
find first eANKUAFDBefore.
buffer eANKUAFDBefore:save-row-changes().
Hi Peter,
thanks, it works, it is critical to have the add-source-buffer method before the assigning of the query.
If I do it after assigning the query it is silently ignored. I had tried this , but unfortunately after assigning the query.
The corrected now working code
define temp-table eANKUAFD no-undo like ankuafd before-table eANKUAFDBefore
.
define dataset dsAnkuafd for eANKUAFD.
define variable QueryHandle as handle no-undo.
define variable SourceHandle as handle no-undo.
create query QueryHandle.
queryhandle:add-buffer(buffer ANKUAFD:handle).
queryhandle:query-prepare("for each ankuafd no-lock").
create data-source SourceHandle .
SourceHandle:add-source-buffer(buffer ankuafd:handle, "cmp-id").
SourceHandle:query = QueryHandle.
buffer eANKUAFD:attach-data-source(SourceHandle).
dataset dsAnkuafd:fill().
find first eANKUAFD.
buffer eANKUAFD:table-handle:tracking-changes = yes.
update eANKUAFD.cre-time .
buffer eANKUAFD:table-handle:tracking-changes = no.
find first eANKUAFDBefore.
buffer eANKUAFDBefore:save-row-changes().
Hi Peter,
thanks, it works, it is critical to have the add-source-buffer method before the assigning of the query.
If I do it after assigning the query it is silently ignored. I had tried this , but unfortunately after assigning the query.
The corrected now working code
define temp-table eANKUAFD no-undo like ankuafd before-table eANKUAFDBefore
.
define dataset dsAnkuafd for eANKUAFD.
define variable QueryHandle as handle no-undo.
define variable SourceHandle as handle no-undo.
create query QueryHandle.
queryhandle:add-buffer(buffer ANKUAFD:handle).
queryhandle:query-prepare("for each ankuafd no-lock").
create data-source SourceHandle .
SourceHandle:add-source-buffer(buffer ankuafd:handle, "cmp-id").
SourceHandle:query = QueryHandle.
buffer eANKUAFD:attach-data-source(SourceHandle).
dataset dsAnkuafd:fill().
find first eANKUAFD.
buffer eANKUAFD:table-handle:tracking-changes = yes.
update eANKUAFD.cre-time .
buffer eANKUAFD:table-handle:tracking-changes = no.
find first eANKUAFDBefore.
buffer eANKUAFDBefore:save-row-changes().