This page is part of the book SQL-99 Complete, Really, by Peter Gulutzan & Trudy Pelzer. The authors have graciously allowed us to reproduce the contents of the book here. Because the book is about the SQL-99 standard, the contents of this and other pages in the book may not directly apply to MariaDB. Use the navigation bar to navigate the book.

Function Prototype:

SQLRETURN SQLExecute(
  SQLHSTMT hstmt                        /* 32-bit input */
  );

Job:

Execute a prepared SQL statement. You must do an SQLPrepare first.

Algorithm:

If (SQLPrepare has not been performed for this stmt)
  return error: HY010 CLI-specific condition-function sequence error
If (there is an open Cursor associated with this stmt)
  /* This would happen if you don't close the Cursor after the last
      execution of a SELECT statement; see SQLCloseCursor */
  return error: 24000 Invalid Cursor state -
If (there are input parameters)
  Get parameter addresses and do appropriate "casting" (described in our chapter on SQL/CLI desc functions)
Execute the prepared statement. It is now the "executed statement".
If (the statement was SELECT)
  Set up a Cursor (described in our chapter on SQL/CLI Cursor functions)
  Change the row descriptors (described in our chapter on SQL/CLI desc functions)
If (there are output parameters)
  Get parameter addresses and do appropriate "casting"
Change the Diagnostics Area

Because there are many possible SQL statements, the range of possible problem conditions is wide see especially the SQLSTATE errors in class 22000 (data exception) and class 23000 (integrity constraint violation) in Chapter 47 "SQL/CLI: Diagnostic Functions". Watch also for warnings and even "No data" conditions (for example, execution of "UPDATE Table_1 SET column_1 = 0;" will result in SQLSTATE 02000 "Data not found" if there are no rows in TABLE_1).

Notes:

  • Calls to SQLExecute always follow calls to SQLPrepare (for the same stmt), but other function calls may intervene.

Example:

In this example we prepare and execute two SQL statements. We use two different stmts, so that we can get all the preparing done before we start executing.

#include "sqlcli.h"
...
SQLHSTMT hstmt1, hstmt2;
...
SQLPrepare(hstmt1,"INSERT INTO t VALUES (1)",SQL_NTS);
SQLPrepare(hstmt2,"INSERT INTO t VALUES (2)",SQL_NTS);
...
SQLExecute(hstmt1);
SQLExecute(hstmt2);

ODBC: The SQLExecute function has been around since ODBC 1.0.

Comments

Comments loading...