ODBC_FETCH Function
Initiates a fetch (cursor) operation to retrieve a specified number of rows.
Restriction | See "Supported Platforms Guide" on the PV-WAVE Documentation website to check if this function is available on your operating system. |
Usage
table = ODBC_FETCH(stmt_handle, option [, start_row])
Input Parameters
stmt_handle—The statement handle returned from ODBC_PREPARE.
option—An integer representing one of the following fetching options:
1 (Fetch next)—Fetch the next cursor set from the specified starting row or else the current position.
2 (Fetch previous)—Fetch the previous result set from the specified starting row or else the current position.
3 (Fetch first)—Fetch the first cursor set.
4 (Fetch last)—Fetch the last cursor set.
5 (Next result set)—If the statement produced more than one result set (a batched command or a stored procedure) go to the next result set.
6 (Close)—Close the statement and free its resources.
start_row—Only valid for fetch next or fetch previous options, this is the starting row for the cursor. If not specified, the fetch will go from the current position of the cursor.
Returned Value
table—Either receives a PV‑WAVE table containing the results, or a count of the affected rows, or –1 for failure.
Discussion
ODBC_FETCH is used to import into a PV‑WAVE table part of a DBMS server result set which was created by a call to ODBC_PREPARE. While ODBC_SQL is used to return an entire result set, ODBC_PREPARE and ODBC_FETCH allow you to control the rate at which data is imported. Each call to ODBC_FETCH returns at most the number of rows specified by the cursor size that was determined by the call to ODBC_PREPARE.
Examples
orders_select = ODBC_PREPARE(dbase_orders, $
'SELECT * FROM[orders];', 15)
orders = ODBC_FETCH(orders_select, 3)
; orders contains rows 1-15; current position is row 16.
orders = ODBC_FETCH(orders_select, 1)
; orders contains rows 16-30; current position is row 31.
orders = ODBC_FETCH(orders_select, 2)
; orders contains rows 1-15; current position is row 16.
orders = ODBC_FETCH(orders_select, 1, 40)
; orders contains rows 40-54; current position is row 55.
orders = ODBC_FETCH(orders_select, 2, 20)
; orders contains rows 6-20; current position is row 21.
orders = ODBC_FETCH(orders_select, 4)
; orders contains last rows; current position is past EOF.
orders = ODBC_FETCH(orders_select, 1)
; orders is -1; current position is past EOF.
orders = ODBC_FETCH(orders_select, 6)
; orders is 0.
See Also