ODBC Driver for EpicorERP

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 CustNum, Company FROM Customers WHERE CompanyName = ?", "CompanyName")
defer rows.Close()
for rows.Next() {
        var (
                CustNum string
                Company string
        )

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

Reusable Statements

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

stmt, _ := db.Prepare("SELECT CustNum, Company FROM Customers WHERE CompanyName = ?")
defer stmt.Close()

rows, _ := stmt.Query("CompanyName 1")
defer rows.Close()
for rows.Next() {
        var (
                CustNum string
                Company string
        )

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

rows, _ = stmt.Query("CompanyName 2")
defer rows.Close()
for rows.Next() {
        var (
                CustNum string
                Company string
        )

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

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