ODBC Driver for Facebook Ads

Build 22.0.8462

Parameterized Statements

The following code example shows how to bind parameters to create parameterized statements.

Single-Use Statements

The Query and Exec functions both accept additional parameters for binding query parameters to values.

rows, _ := db.Query("SELECT AccountId, Name FROM AdAccounts WHERE Name = ?", "Act Name")
defer rows.Close()
for rows.Next() {
        var (
                AccountId string
                Name string
        )

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

Reusable Statements

The Prepare function creates prepared Stmt objects, which can be re-used across multiple Query and Exec calls.

stmt, _ := db.Prepare("SELECT AccountId, Name FROM AdAccounts WHERE Name = ?")
defer stmt.Close()

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

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

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

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

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