ODBC Driver for Blackbaud Financial Edge NXT

Build 23.0.8839

パラメータ化されたステートメント

次のコード例は、パラメータをバインドしてパラメータ化されたステートメントを作成する方法を示します。

シングルユース ステートメント

Query とExec 関数は両方とも、クエリパラメータを値にバインドするための追加パラメータを受け入れます。

rows, _ := db.Query("SELECT AccountId, AccountNumber FROM Accounts WHERE ModifiedBy = ?", "System")
defer rows.Close()
for rows.Next() {
        var (
                AccountId string
                AccountNumber string
        )

        rows.Scan(&AccountId, &AccountNumber)
        fmt.Printf("AccountId = %s, AccountNumber = %s\n", AccountId, AccountNumber)
}

リユーザブル ステートメント

Prepare 関数は、プリペアドStmt オブジェクトを作成します。これは、複数のQuery およびExec 呼び出しで再利用できます。

stmt, _ := db.Prepare("SELECT AccountId, AccountNumber FROM Accounts WHERE ModifiedBy = ?")
defer stmt.Close()

rows, _ := stmt.Query("System 1")
defer rows.Close()
for rows.Next() {
        var (
                AccountId string
                AccountNumber string
        )

        rows1.Scan(&AccountId, &AccountNumber)
        fmt.Printf("AccountId = %s, AccountNumber = %s\n", AccountId, AccountNumber)
}

rows, _ = stmt.Query("System 2")
defer rows.Close()
for rows.Next() {
        var (
                AccountId string
                AccountNumber string
        )

        rows2.Scan(&AccountId, &AccountNumber)
        fmt.Printf("AccountId = %s, AccountNumber = %s\n", AccountId, AccountNumber)
}

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839