ODBC Driver for YouTube Analytics

Build 22.0.8479

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

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

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

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

rows, _ := db.Query("SELECT Snippet_Title, ContentDetails_ItemType FROM Groups WHERE Id = ?", "S")
defer rows.Close()
for rows.Next() {
        var (
                Snippet_Title string
                ContentDetails_ItemType string
        )

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

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

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

stmt, _ := db.Prepare("SELECT Snippet_Title, ContentDetails_ItemType FROM Groups WHERE Id = ?")
defer stmt.Close()

rows, _ := stmt.Query("S 1")
defer rows.Close()
for rows.Next() {
        var (
                Snippet_Title string
                ContentDetails_ItemType string
        )

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

rows, _ = stmt.Query("S 2")
defer rows.Close()
for rows.Next() {
        var (
                Snippet_Title string
                ContentDetails_ItemType string
        )

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

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479