ODBC Driver for 1010data

Build 22.0.8509

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 name, radius FROM \"tenten\".\"public\".solar WHERE orbits = ?", "sun")
defer rows.Close()
for rows.Next() {
        var (
                name string
                radius string
        )

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

Reusable Statements

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

stmt, _ := db.Prepare("SELECT name, radius FROM \"tenten\".\"public\".solar WHERE orbits = ?")
defer stmt.Close()

rows, _ := stmt.Query("sun 1")
defer rows.Close()
for rows.Next() {
        var (
                name string
                radius string
        )

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

rows, _ = stmt.Query("sun 2")
defer rows.Close()
for rows.Next() {
        var (
                name string
                radius string
        )

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

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