ODBC Driver for Quandl

Build 20.0.7587

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 High, Date FROM AAPL WHERE collapse = ?", "daily")
defer rows.Close()
for rows.Next() {
        var (
                High string
                Date string
        )

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

Reusable Statements

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

stmt, _ := db.Prepare("SELECT High, Date FROM AAPL WHERE collapse = ?")
defer stmt.Close()

rows, _ := stmt.Query("daily 1")
defer rows.Close()
for rows.Next() {
        var (
                High string
                Date string
        )

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

rows, _ = stmt.Query("daily 2")
defer rows.Close()
for rows.Next() {
        var (
                High string
                Date string
        )

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

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7587