How to set the keys on a dynamic query based data-source to

Posted by cverbiest on 06-Jan-2017 07:57

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().

Posted by cverbiest on 06-Jan-2017 09:13

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().


Posted by Peter Judge on 06-Jan-2017 08:14

Carl,
 
I use something like the below …. hBuffer:keys works nicely with the :add-source-buffer method
 
 
            create data-source hABLDataSource.
            /* Create a buffer with a unique name, since we don't know where this DataSource will be used,
               nor how. So to aviod error 12298 we give the buffer a unique name */
            create buffer hBuffer for table PrimaryTable
                buffer-name substitute('&1_&2-&3',
                             PrimaryTable:name,
                             string(hABLDataSource),
                             string(int(ServiceMessageActionEnum:FetchData))).
            hABLDataSource:add-source-buffer(hBuffer, hBuffer:keys).
 
 
 

All Replies

Posted by Peter Judge on 06-Jan-2017 08:14

Carl,
 
I use something like the below …. hBuffer:keys works nicely with the :add-source-buffer method
 
 
            create data-source hABLDataSource.
            /* Create a buffer with a unique name, since we don't know where this DataSource will be used,
               nor how. So to aviod error 12298 we give the buffer a unique name */
            create buffer hBuffer for table PrimaryTable
                buffer-name substitute('&1_&2-&3',
                             PrimaryTable:name,
                             string(hABLDataSource),
                             string(int(ServiceMessageActionEnum:FetchData))).
            hABLDataSource:add-source-buffer(hBuffer, hBuffer:keys).
 
 
 

Posted by cverbiest on 06-Jan-2017 09:13

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().


This thread is closed