ODBC Driver for IBM Cloud Object Storage

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 Key, Etag FROM Objects WHERE Bucket = ?", "testBucket")
defer rows.Close()
for rows.Next() {
        var (
                Key string
                Etag string
        )

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

Reusable Statements

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

stmt, _ := db.Prepare("SELECT Key, Etag FROM Objects WHERE Bucket = ?")
defer stmt.Close()

rows, _ := stmt.Query("testBucket 1")
defer rows.Close()
for rows.Next() {
        var (
                Key string
                Etag string
        )

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

rows, _ = stmt.Query("testBucket 2")
defer rows.Close()
for rows.Next() {
        var (
                Key string
                Etag string
        )

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

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