ODBC Driver for Streak

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 UserKey, Email FROM Users WHERE UserKey = ?", "agxzfm1haWxmb29nYWVyLAsSDE9yZ2FuaXphdGlvbiIJY2RhdGEuY29tDAsSBFVzZXIYgICs35ruuwkM")
defer rows.Close()
for rows.Next() {
        var (
                UserKey string
                Email string
        )

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

Reusable Statements

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

stmt, _ := db.Prepare("SELECT UserKey, Email FROM Users WHERE UserKey = ?")
defer stmt.Close()

rows, _ := stmt.Query("agxzfm1haWxmb29nYWVyLAsSDE9yZ2FuaXphdGlvbiIJY2RhdGEuY29tDAsSBFVzZXIYgICs35ruuwkM 1")
defer rows.Close()
for rows.Next() {
        var (
                UserKey string
                Email string
        )

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

rows, _ = stmt.Query("agxzfm1haWxmb29nYWVyLAsSDE9yZ2FuaXphdGlvbiIJY2RhdGEuY29tDAsSBFVzZXIYgICs35ruuwkM 2")
defer rows.Close()
for rows.Next() {
        var (
                UserKey string
                Email string
        )

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

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