18.2.4 Adding, updating, or deleting data
To use an update SQL statement to add, update, or delete data, you allocate a statement handle, preprocess the SQL statement, and then use a_rdb_SQLExecute()to execute the SQL statement, in the same manner as for a SELECT statement.
The following figure shows the procedure for data update and deletion processing.
- Note
-
You can also use a_rdb_SQLExecDirect() to both preprocess and execute an SQL statement without preprocessing the SQL statement in advance with a_rdb_SQLPrepare().
Note that using dynamic parameters requires a process of binding (association), which can be performed by using a_rdb_SQLBindParams() or a_rdb_SQLBindArrayParams(). For details about a_rdb_SQLBindParams(), see 19.4.4 a_rdb_SQLBindParams() (associate dynamic parameters). For details about a_rdb_SQLBindArrayParams(), see 19.4.2 a_rdb_SQLBindArrayParams() (bind dynamic parameters in batch mode).
The following shows an example of updating and deleting data.
- Example of updating and deleting data
-
/* Allocate a statement handle */ rtnc = a_rdb_SQLAllocStmt(hCnct, &hStmt, NULL) ; /* Prepare the INSERT statement */ rtnc = a_rdb_SQLPrepare(hCnct, hStmt, "INSERT INTO TABLE1 VALUES ('A','B','C')", NULL) ; /* Execute the SQL statement */ rtnc = a_rdb_SQLExecute(hCnct, hStmt, NULL) ; /* Execute DELETE */ rtnc = a_rdb_SQLExecDirect(hCnct, hStmt, "DELETE FROM TABLE1", NULL) ;
For details about a_rdb_SQLExecDirect(), see 19.4.8 a_rdb_SQLExecDirect() (preprocess and execute an SQL statement).