%SSC_MOVE

Fetch rows of data

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
value = %SSC_MOVE(dbchannel, dbcursor, [ncount], [row_count], [more_results][, warn])

value

This function returns SSQL_NORMAL (success), SSQL_FAILURE (failure), or SSQL_NOMORE (no more data found for current result set). (i)

dbchannel

An internal database channel previously initialized using %SSC_INIT and connected by %SSC_CONNECT. (n)

dbcursor

The ID number of an open database cursor (opened with %SSC_OPEN). This must be in the range 1 through the number specified by maxcur when the database channel was initialized (with %SSC_INIT). (n)

ncount

(optional) The number of rows to fetch. This argument defaults to 1 for databases that do not support multirow fetch. (n)

row_count

(optional) Returned number of rows actually fetched by the SQL statement associated with dbcursor. This count is valid only when value is returned as SSQL_NORMAL. (n)

more_results

(optional) When using VTX12_SQLNATIVE, if %SSC_MOVE returns SSQL_NOMORE and more_results is passed, more_results will be set if one or more result sets for the cursor have yet to be returned. See Returning multiple result sets when using VTX12_SQLNATIVE below for more information. This argument is ignored for all other drivers. (n)

warn

(optional) A variable that is set to 1 if one or more rows return a warning status (such as “data columns truncated”). (n)

Discussion

%SSC_MOVE fetches one or more rows of data into host variables defined by %SSC_DEFINE or %SSC_STRDEF. For multirow fetches, %SSC_MOVE returns SSQL_NOMORE if one or more requested rows are not fetched. (If you request a four-row fetch, for example, but %SSC_MOVE is able to fetch only three rows, %SSC_MOVE returns SSQL_NOMORE.) You can use row_count to find out how many rows were actually fetched.

Note the following:

Returning multiple result sets when using VTX12_SQLNATIVE

When using VTX12_SQLNATIVE, if %SSC_MOVE returns SSQL_NOMORE and more_results is set, this indicates that there are more result sets that can be returned for the cursor. Do one of the following to retrieve the remaining results:

if (%ssc_move(dbchn, cur1,,, more_results))		; If SSQL_NOMORE
  begin
    if (!more_results)					 ; More_results is set if another result set is pending
      exitloop		 				 ; Else exit
    if (%ssc_define(dbchn, cur1, -2, deptnum, salary))	 ; Redefine for next result set
      goto err_exit
    nextloop
  end

Note that this feature is not compatible with RO_CURSOR. You must set SSQL_RO_CURSOR to “no” for subsequent result sets to be returned. For example:

  ; After RO has been set, we have to unset SSQL_RO_CURSOR for multiple result sets:
if (%ssc_cmd(dbchn, cur1, SSQL_RO_CURSOR, "no"))
  goto err_exit

if (%ssc_cmd(dbchn, cur1, SSQL_CURSOR_TYPE,SSQL_CURSOR_FORWARD_ONLY))		; Same as default
  goto err_exit

if (%ssc_cmd(dbchn, cur1, SSQL_CMD_ODBC_CONNATTR, SSQL_COPT_SS_CURSOR_OPTIONS+" "+SSQL_COPT_CO_FIREHOSE))
  goto err_exit

Examples

The following example shows how to move column data to a Synergy DBL data area.

sqlp = "SELECT deptnum, deptname"
  &     " FROM org WHERE deptnum = :1"
sts=%ssc_open(dbchn, cur2, sqlp, SSQL_SELECT, SSQL_STANDARD, 1, deptnum)
sts=%ssc_define(dbchn, cur2, 2, deptnum, deptname)
;  Get dnum to SELECT rows
display(g_terminal, "Enter Department Number: ")
reads(g_terminal, %a(dnum))
;  Do fetch and display rows to screen one row at a time
do forever
  begin
    sts = %ssc_move(dbchn, cur2, 1)
    if (sts.eq.SSQL_FAILURE) then             ;ERROR
      goto err_exit
    else if (sts.eq.SSQL_NOMORE)              ;EOF
      exitloop
    writes(g_terminal, %string(deptnum) + ", " + deptname)
  end

For an example of a single row fetch, see exam_fetch.dbl. For an example of a multirow fetch, see exam_multirow_fetch.dbl. These example files are in the connect\synsqlx subdirectory of the main Synergy/DE installation directory.