ODBC Driver for SurveyMonkey

Build 23.0.8839

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

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

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

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

rows, _ := db.Query("SELECT RespondentId, ChoiceId FROM MySurvey_Responses WHERE ChoiceText = ?", "blue")
defer rows.Close()
for rows.Next() {
        var (
                RespondentId string
                ChoiceId string
        )

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

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

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

stmt, _ := db.Prepare("SELECT RespondentId, ChoiceId FROM MySurvey_Responses WHERE ChoiceText = ?")
defer stmt.Close()

rows, _ := stmt.Query("blue 1")
defer rows.Close()
for rows.Next() {
        var (
                RespondentId string
                ChoiceId string
        )

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

rows, _ = stmt.Query("blue 2")
defer rows.Close()
for rows.Next() {
        var (
                RespondentId string
                ChoiceId string
        )

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

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