Database Toolbox    
exec

Execute SQL statement and open cursor

Syntax

Description

curs = exec(conn, 'sqlquery') executes the valid SQL statement sqlquery, against the database connection conn, and opens a cursor. Running exec returns the cursor object to the variable curs, and returns information about the cursor object. The sqlquery argument can also be a stored procedure for that database connection.

Use querytimeout to determine the maximum amount of time for which exec will try to complete the SQL statement.

You can have multiple cursors open at one time.

After opening a cursor, use fetch to import data from the cursor. Use resultset, rsmd, and statement to get properties of the cursor.

A cursor stays open until you close it using the close function. Always close a cursor after you finish using it.

Examples

Example 1 - Select All Data from Database Table

Select all data from the customers table accessed via conn. Assign the variable curs to the returned cursor object.

Example 2 - Select One Column of Data from Database Table

Select country data from the customers table accessed via conn. Assign the variable sqlquery to the SQL statement and assign curs to the returned cursor.

Example 3 - Roll Back or Commit Data Exported to Database Table

Use exec to roll back or commit data after running an insert or an update for which the AutoCommit flag is off. To roll back data for conn, type

To commit the data, type:

Example 4 - Run Stored Procedure

Execute the stored procedure sp_customer_list for the database connection conn:

See Also

close, database, fetch, insert, procedures, querytimeout, resultset, rsmd, set, update


 drivermanager exportedkeys