type Stmt
The following table describes type Stmt.
Method |
Description |
Return Value |
(s *Stmt)Close() |
Closes a specified prepared statement. |
error |
(s *Stmt)Exec(args ...interface{}) |
Executes a prepared statement with specified parameters and returns a Result value. The Prepare-Bind-Execute (PBE) feature is supported. PBE is a method of sending and executing queries. The CN can receive PBE packets through complex query protocols to execute statements.
NOTE:
|
Result and error |
(s *Stmt)ExecContext(ctx context.Context, args ...interface{}) |
Executes a prepared statement with specified parameters in a specified context and returns a Result value. |
Result and error |
(s *Stmt)Query(args ...interface{}) |
Executes a prepared statement with specified parameters and returns *Rows as the query result. |
*Rows and error |
(s *Stmt)QueryContext(ctx context.Context, args ...interface{}) |
Executes a prepared statement with specified parameters in a specified context and returns *Rows as the query result. |
*Rows and error |
(s *Stmt)QueryRow(args ...interface{}) |
Executes a prepared statement with specified parameters and returns *Row as the result. |
*Row |
(s *Stmt)QueryRowContext (ctx context.Context, args ...interface{}) |
Executes a prepared statement with specified parameters in a specified context and returns *Row as the result. |
*Row |
Parameters
Parameter |
Description |
ctx |
Specified context. |
query |
Executed SQL statement. |
args |
Parameter that needs to be bound to the executed SQL statement. Binding by location and binding by name are supported. For details, see Examples in section "type DB." |
- The Query(), QueryContext(), QueryRow(), and QueryRowContext() APIs are usually used in query statements, such as SELECT. The Exec() API is used for executing operation statements. If query APIs are used to execute non-query statements, the execution result may be unexpected. Therefore, you are advised not to use the query APIs to execute non-query statements, such as UPDATE and INSERT.
- The result of executing a query statement using a query API needs to be obtained through the Next() API in type Rows. If the result is not obtained through the Next() API, unexpected errors may occur.
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