project BLF > class Persistence (other) > method ReadQuery

Description

Read data from the database, and return all retrieved data in a single table.

PreCondition

This method is used in query calls and should not be used anywhere else.


Parameters


icQueryNameinputcharacter
icPrepareinputcharacterFor each statement for reading the data, excluding the no-lock option (this is implied automatically), excluding break by (not allowed, only normal by is allowed).
icTablesinputcharacterComma seperated list of all database tables in the for each statement.
ihDestinationBufferinputhandleHandle to the temp-table that will receive the data.
icLastRowidinputcharacterComma seperated list of database record rowids of last record in previous ReadQuery call, contains one rowid for each table in input parameter icTables. Is empty for first call.
iiLastRownuminputinteger
iiMaxNumberinputintegerMaximum number of records (in the temp-table) to retrieve.
Zero if the amount is unlimited.
A negative value if exactly one record must be loaded (the record with rowid found in icLastRowid).
Remark: if value is +1, also one record will be returned, but this will be the record following record found with icLastRowid.
icFieldConvertinputcharacterContains the information to know in which temp-table field the database field must be loaded (as opposed to class temp-tables, the field name will be different).
Format: '<buffer>.<db-field-1>,<tt-field-1>|<buffer>.<db-field-2>,<tt-field-2>|...'
icCustomFieldsinputcharacter
ilDistinctinputlogicalLoad only distinct values ?
ilForwardReadinputlogicalIndicates query should read forward.
olEofoutputlogicalWhen iiMaxNumber > 0, this parameter will be true when the last record of the query is included in the result set, or when no record was found at all.
When iiMaxNumber <= 0, this parameter will be only true when no record was found at all.
oiReturnStatusoutputinteger


Internal usage


unused


program code (program1/other.p)

assign oiReturnStatus = -98.

/* Convert field list to old format */
do viFcCount1 = 1 to num-entries(icFieldConvert) by 2:
    assign vcFieldConvert = vcFieldConvert + "|":U
                          + entry(viFcCount1 + 1, icFieldConvert) + ",":U
                          + entry(2,entry(viFcCount1, icFieldConvert),".":U).
end.
icFieldConvert = substring(vcFieldConvert,2,-1,"CHARACTER":U).

if iiMaxNumber = ?
then iiMaxNumber = 0.
if icLastRowid = ?
then icLastRowid = "".

&if defined(DEBUGSQL) > 0 &then
run SqlDebugWrite in {&TARGETPROCEDURE} ("* ":U + program-name(1), 1).
&endif

run SqlQryOpen4GL in {&TARGETPROCEDURE} (
        icTables,
        icPrepare,
        iiMaxNumber,
        icLastRowid,
        icFieldConvert,
        icCustomFields,
        integer(ilDistinct),
        output viQryid,
        output oiReturnStatus).

if oiReturnStatus < 0
then do:
    <M-2 run SqlErrorMessage
       (input  ? (ihClass), 
        output viFcReturnSuper (oiReturnStatus)) in other>

    return.
end.

run SqlQryExecute in {&TARGETPROCEDURE}
   (viQryid, output viCols, output oiReturnStatus).
run SqlQryMoveNext in {&TARGETPROCEDURE}
   (viQryid, output viRows, output oiReturnStatus).

/* fill temp-table */
assign viFcCount2 = 0.
do while viROws = 1:

    assign viFcCount2 = viFcCount2 + 1.
    ihDestinationBuffer:buffer-create().

    do viFcCount1 = 0  to viCols - 1:
        assign vcName  = <M-3 getColumnName (input  viQryid (iiCmd), 
                    input  viFcCount1 (iiCol)) in other>.
        assign vhField = ?.
        assign vhField = ihDestinationBuffer:buffer-field(vcName) no-error.
        if vhField <> ?
        then assign vhField:buffer-value = <M-4 getColumnValue (input  viQryid (iiCmd), 
                     input  viFcCount1 (iiCol)) in other>.
    end.
    
    assign vhField = ?.
    assign vhField = ihDestinationBuffer:buffer-field("ti_Sequence":U) no-error.
    if vhField <> ?
    then assign vhField:buffer-value = viFcCount2.

    run SqlQryMoveNext in {&TARGETPROCEDURE}
       (viQryid, output viRows, output oiReturnStatus).
end.

run SqlQryDestroy in {&TARGETPROCEDURE}
   (viQryid, output oiReturnStatus).

assign oiReturnStatus = 0.