Add prepared statement tests.
Project: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/commit/af32e42c Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/tree/af32e42c Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/diff/af32e42c Branch: refs/heads/master Commit: af32e42c049fa02a41635a1e14f0351d821f4989 Parents: a87e02f Author: Francis Chuang <[email protected]> Authored: Mon Aug 22 19:38:52 2016 +1000 Committer: Julian Hyde <[email protected]> Committed: Thu Aug 10 18:47:08 2017 -0700 ---------------------------------------------------------------------- driver_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/af32e42c/driver_test.go ---------------------------------------------------------------------- diff --git a/driver_test.go b/driver_test.go index babc1c5..f1cb982 100644 --- a/driver_test.go +++ b/driver_test.go @@ -631,6 +631,50 @@ func TestRollingBackTransactions(t *testing.T) { }) } +func TestPreparedStatements(t *testing.T) { + + runTests(t, dsn, func(dbt *DBTest) { + + // Create and seed table + dbt.mustExec(`CREATE TABLE ` + dbt.tableName + ` ( + int INTEGER PRIMARY KEY + ) TRANSACTIONAL=true`) + + stmt, err := dbt.db.Prepare(`UPSERT INTO ` + dbt.tableName + ` VALUES(?)`) + + if err != nil { + dbt.Fatal(err) + } + + totalRows := 6 + + for i := 1; i <= totalRows; i++ { + _, err := stmt.Exec(i) + + if err != nil { + dbt.Fatal(err) + } + } + + queryStmt, err := dbt.db.Prepare(`SELECT * FROM ` + dbt.tableName + ` WHERE int = ?`) + + var res int + + for i := 1; i <= totalRows; i++ { + + err := queryStmt.QueryRow(i).Scan(&res) + + if err != nil { + dbt.Fatal(err) + } + + if res != i { + dbt.Fatalf("Unexpected query result. Expected %d, got %d.", i, res) + } + } + }) +} + func TestFetchingMoreRows(t *testing.T) { query := "?maxRowsTotal=-1&frameMaxSize=1"
