ODBC Driver for SAP BusinessObjects BI

Build 21.0.7930

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 StoreName, Column1 FROM MyCustomReport WHERE Column2 = ?", "Bob")
defer rows.Close()
for rows.Next() {
        var (
                StoreName string
                Column1 string
        )

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

Reusable Statements

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

stmt, _ := db.Prepare("SELECT StoreName, Column1 FROM MyCustomReport WHERE Column2 = ?")
defer stmt.Close()

rows, _ := stmt.Query("Bob 1")
defer rows.Close()
for rows.Next() {
        var (
                StoreName string
                Column1 string
        )

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

rows, _ = stmt.Query("Bob 2")
defer rows.Close()
for rows.Next() {
        var (
                StoreName string
                Column1 string
        )

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

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930