Sends a command batch to Microsoft® SQL Server™ .
RETCODE dbsqlexec ( PDBPROCESS dbproc );
SUCCEED or FAIL. The most common reason for failing is a Transact-SQL syntax error or SQL Server permission violation. Other reasons include incorrect column or table names. The dbsqlexec function also fails if previous results were not processed, if no statement was specified, or if a network connection is broken.
Note that if a series of commands is sent to SQL Server and if one or more of the commands contains syntax errors, SQL Server processes none of the commands, and dbsqlexec returns FAIL.
This function sends Transact-SQL statements, stored in the command buffer of the DBPROCESS, to SQL Server. Statements can be added to the DBPROCESS structure by calling dbcmd or dbfcmd.
The dbsqlexec function is equivalent to dbsqlsend followed by dbsqlok. However, after sending a query to SQL Server, dbsqlexec waits until it receives a response or until the time-out period has elapsed. If you prefer not to have your application wait, substitute dbsqlsend, dbdataready, and dbsqlok.
After dbsqlexec, the application must call dbresults to process the results.
This example shows the typical sequence of calls:
DBINT xvariable;
DBCHAR yvariable[10];
// Place the query into the command buffer.
dbcmd(dbproc, "SELECT x = 100, y = 'hello'");
// Send the command buffer to SQL Server.
dbsqlexec(dbproc);
// Get ready to process the results of the query.
dbresults(dbproc);
// Bind column data to program variables.
dbbind(dbproc, 1, INTBIND, (DBINT) 0, (BYTE *) &xvariable);
dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, yvariable);
// Now process each row.
while (dbnextrow(dbproc) != NO_MORE_ROWS)
{
// C-code to print or process row data
}
dbcmd | dbsettime |
dbfcmd | dbsqlok |
dbnextrow | dbsqlsend |
dbresults |