Analyzing Commands

4D - Documentation   Français   English   German   4D ODBC, Command Theme List   4D ODBC, Command Alphabetical List   Back   Previous   Next

version 1.5


SQL statements can be classified into two different categories:

Commands that contain only one statement (one result set),

Complex commands, such as stored procedures, that are actually made up of several SQL statements (multiple result sets).

OC More results enables you to analyze an SQL command to determine if there are more result sets pending.

Your application is not required to retrieve all the results in one set before moving onto the next. When OC More results is called, the previous result set is discarded (similar to OC Cancel loading). Therefore, use this function after loading all the desired rows from the current result set.

If your application allows the user to input their own SQL statements, you may not know how many commands are in the procedure prior to calling it. You must therefore read the data source command buffer, using OC More results, to verify that execution has been completed and that no commands remain.

The following method executes an SQL Server stored procedure, returns the values of the first three columns from all result sets, and displays an alert box describing the number of results returned. Note that by using the results from OC Load row and OC More results, it is possible to develop a generic routine that retrieves the results of any command, regardless of how many rows or sets of results are generated.

   $sql:="exec sp_help titles"
   $res:=OC Set SQL in Cursor (cursor_id;$sql)
      `bind to arrays
   $res:=OC Bind (cursor_id;1;"ar1")
   $res:=OC Bind (cursor_id;2;"ar2")
   $res:=OC Bind (cursor_id;3;"ar3")
   $res:=OC Execute cursor (cursor_id)
   $count:=1
   $more:=1
   While ($more=1)
      $res:=1
      While ($res=1)
         $res:=OC Load row(cursor_id)
      End while
      $res:=OC Execute cursor (cursor_id)
      $more:=OC More results (cursor_id)
      $count:=1+$more
   End while 
   ALERT(String($count)+" set of results returned")

4D - Documentation   Français   English   German   4D ODBC, Command Theme List   4D ODBC, Command Alphabetical List   Back   Previous   Next