The following example assumes that objects SD.DbStruct, TB.Table are available. Then the particular process D2000 DBManager must be running and a database with the particular DSN name must be correctly configured in the operating system.

INT _handle
INT _retCode
INT _pageSize
INT _rowsCount
INT _numPages
INT _pgNr
TEXT _where
TEXT _orderBy 
RECORD
(SD.DbStruct) _dbPageArr
ALIAS (SD.DbStruct) _targetArr

SET _targetArr AS SV.Struktura
_pageSize := _targetArr\DIM

; open database table
PG_CONNECT TB.Table, _DB_MODIFY, _handle, _pageSize, _where, _orderBy, _rowsCount, _retCode

IF _retCode # _ERR_NOERROR THEN ; unable to connect to the database table
    END
ENDIF


; if nothing is selected => finish
IF _rowsCount = 0 THEN
    END
ENDIF


; calculate the number of pages
_numPages := _rowsCount / _pageSize
IF _numPages*_pageSize < _rowsCount THEN
    _numPages := _numPages + 1
ENDIF

; go over all pages
_pgNr := 1 ; current page

DO_LOOP
PG_READ _handle, _pgNr, _dbPageArr, _retCode
GOSUB Copy_dbPageArr ; copy page to _targetArr
_pgNr := _pgNr + 1
EXIT_LOOP _pgNr > _numPages
END_LOOP


PG_DISCONNECT _handle ; close the database table
END



; ****************************************************************
; Copying the content of local variable _dbPageArr to _targetArr
; ******************************************************************
Copy_dbPageArr:
INT _itemsToCopy
INT _i

; detect how many items are to be copied
IF
_targetArr\DIM < _dbPageArr\DIM THEN
    _itemsToCopy := _targetArr\DIM
ELSE
    _itemsToCopy := _dbPageArr\DIM
ENDIF

_i := 1
DO_LOOP
EXIT_LOOP _i > _itemsToCopy

SET _targetArr[_i] WITH _dbPageArr[_i]
_i := _i + 1
END_LOOP

WAIT ; wait for executing the last assignment into _targetArr
RETURN

Note

  • Terminating the script by the action END (or by another optional way) automatically closes all connections to the database table.

Related pages:

0 komentárov

Nie ste prihlásený. Akékoľvek zmeny, ktoré vykonáte, sa označia ako anonymné. Ak už máte svoj účet, pravdepodobne sa budete chcieť prihlásiť .