The SQLExecDirect function prepares and executes a SQL statement. The statement may include parameters.
The following code fragment illustrates how to execute a statement without parameters. The SQLExecDirect function takes a statement handle, a SQL string, and a length or termination indicator, which in this case is a null-terminated string indicator.
The procedure described in this section is straightforward but inflexible. The application cannot take any input from the user to modify the statement. For a more flexible method of constructing statements, see Executing statements with bound parameters.
Allocate a handle for the statement using SQLAllocHandle.
For example, the following statement allocates a handle of type
SQL_HANDLE_STMT with name
stmt, on a connection with handle
SQLAllocHandle( SQL_HANDLE_STMT, dbc, &stmt );
Call the SQLExecDirect function to execute the statement:
For example, the following lines declare a statement and execute it. The declaration of
deletestmt would usually occur at the beginning of the function:
SQLCHAR deletestmt[ STMT_LEN ] = "DELETE FROM Departments WHERE DepartmentID = 201"; SQLExecDirect( stmt, deletestmt, SQL_NTS) ;
For a complete sample with error checking, see samples-dir\SQLAnywhere\ODBCExecute\odbcexecute.cpp.
For more information about SQLExecDirect, see SQLExecDirect in the Microsoft ODBC Programmer's Reference.
|Envoyer votre avis sur cette page par email.||Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1|