Running SQL Statements
To help users interact with the database, the ODBC provides APIs for executing SQL statements, as shown in Table 1.
Function |
API |
---|---|
Set statement attributes. |
|
Prepare an SQL statement for execution. |
|
Run a prepared SQL statement. |
|
Bind the parameter marker of an SQL statement to a buffer. |
|
Run an SQL statement directly. |

- ODBC connects applications to the database and delivers the SQL statements sent by an application to the database. It does not parse the SQL syntax. Therefore, when confidential information (such as a plaintext password) is written into the SQL statement sent by an application, the confidential information is exposed in the driver log.
- If an execution request (not in a transaction block) received in the database contains multiple statements, the request is packed into a transaction. If one of the statements fails, the entire request will be rolled back.
// Set statement attributes. SQLSetStmtAttr(V_OD_hstmt, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER *)3, 0); // Allocate a statement handle. SQLAllocHandle(SQL_HANDLE_STMT, V_OD_hdbc, &V_OD_hstmt); // Run an SQL statement directly. SQLExecDirect(V_OD_hstmt, "drop table IF EXISTS customer_t1", SQL_NTS); SQLExecDirect(V_OD_hstmt, "CREATE TABLE customer_t1(c_customer_sk INTEGER, c_customer_name VARCHAR(32));", SQL_NTS); SQLExecDirect(V_OD_hstmt, "insert into customer_t1 values(25, 'li')", SQL_NTS); // Prepare for execution. SQLPrepare(V_OD_hstmt, "insert into customer_t1 values(?)", SQL_NTS); // Add parameters. SQLBindParameter(V_OD_hstmt,1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &value, 0, NULL); // Run the prepared statement. SQLExecute(V_OD_hstmt); SQLExecDirect(V_OD_hstmt, "select c_customer_sk from customer_t1", SQL_NTS);
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot