SQLEXEC( ) Function

Example   See Also

Sends a SQL statement to the data source, where the statement is processed.

Syntax

SQLEXEC(nConnectionHandle, [cSQLCommand, [CursorName]])

Returns

Numeric

Arguments

nConnectionHandle

Specifies the connection handle to the data source returned by SQLCONNECT( ).

cSQLCommand

Specifies the SQL statement passed to the data source.

The SQL statement can contain a parameterized WHERE clause which creates a parameterized view. All parameters in the WHERE clause must be defined before SQLEXEC( ) is issued. For example, if the parameters are variables, the variables must be created and initialized before SQLEXEC( ) is issued.

For additional information about creating parameterized views, see Chapter 8, Creating Views, in the Programmer's Guide.

CursorName

Specifies the name of the Visual FoxPro cursor to which the result set is sent. If you don't include a cursor name, Visual FoxPro uses the default name SQLRESULT.

For multiple result sets, new cursor names are derived by appending an incremented number to the name of the first cursor.

Remarks

SQLEXEC( ) returns the number of result sets if there is more than one. SQLEXEC( ) returns 0 if it is still executing and returns 1 when it has finished executing. SQLEXEC( ) returns –1 if a connection level error occurs.

If SQLEXEC( ) is used to execute a SQL statement prepared with SQLPREPARE( ), only the connection handle argument nConnectionHandle is required. The cSQLCommand and CursorName arguments should be omitted.

If the SQL statement generates one result set, SQLEXEC( ) stores the result set to the specified Visual FoxPro cursor. If the SQL statement generates two or more result sets and SQLSETPROP( ) is set to 1 (batch mode), you can name each result set by setting the SQLSETPROP( ) BatchMode option to 0 and changing the cursor name each time you call SQLMORERESULTS( ).

SQLEXEC( ) is one of the four functions that you can execute either synchronously or asynchronously. The Asynchronous setting of SQLSETPROP( ) determines whether these functions execute synchronously or asynchronously. In asynchronous mode, you must call SQLEXEC( ) repeatedly until it returns a value other than 0 (still executing).