GO語言"database/sql"包中"DB.ExecContext"類型的用法及代碼示例。
用法:
func(db *DB) ExecContext(ctx context.Context, query string, args ...any)(Result, error)
ExecContext 執行查詢而不返回任何行。 args 用於查詢中的任何占位符參數。
例子:
package main
import (
"context"
"database/sql"
"log"
)
var (
ctx context.Context
db *sql.DB
)
func main() {
id := 47
result, err := db.ExecContext(ctx, "UPDATE balances SET balance = balance + 10 WHERE user_id = ?", id)
if err != nil {
log.Fatal(err)
}
rows, err := result.RowsAffected()
if err != nil {
log.Fatal(err)
}
if rows != 1 {
log.Fatalf("expected to affect 1 row, affected %d", rows)
}
}
相關用法
- GO DB.QueryRowContext用法及代碼示例
- GO DB.BeginTx用法及代碼示例
- GO DB.QueryContext用法及代碼示例
- GO DB.Prepare用法及代碼示例
- GO DB.Query用法及代碼示例
- GO DB.PingContext用法及代碼示例
- GO DecodeLastRuneInString用法及代碼示例
- GO DumpResponse用法及代碼示例
- GO Date用法及代碼示例
- GO Dial用法及代碼示例
- GO Decoder.Token用法及代碼示例
- GO Decoder.Decode用法及代碼示例
- GO DumpRequest用法及代碼示例
- GO Drawer用法及代碼示例
- GO Duration.Hours用法及代碼示例
- GO Duration.Round用法及代碼示例
- GO DecodeRuneInString用法及代碼示例
- GO DumpRequestOut用法及代碼示例
- GO DecodeRune用法及代碼示例
- GO Duration用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 DB.ExecContext。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。