forked from marcboeker/go-duckdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement_test.go
53 lines (46 loc) · 965 Bytes
/
statement_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package duckdb
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestPrepareQuery(t *testing.T) {
db := openDB(t)
defer db.Close()
createTable(db, t)
stmt, err := db.Prepare("SELECT * FROM foo WHERE baz=?")
require.NoError(t, err)
defer stmt.Close()
rows, err := stmt.Query(0)
require.NoError(t, err)
defer rows.Close()
}
func TestPrepareWithError(t *testing.T) {
db := openDB(t)
defer db.Close()
createTable(db, t)
testCases := []struct {
tpl string
err string
}{
{
tpl: "SELECT * FROM tbl WHERE baz=?",
err: "Table with name tbl does not exist",
},
{
tpl: "SELECT * FROM foo WHERE col=?",
err: `Referenced column "col" not found in FROM clause`,
},
{
tpl: "SELECT * FROM foo col=?",
err: `syntax error at or near "="`,
},
}
for _, tc := range testCases {
stmt, err := db.Prepare(tc.tpl)
if err != nil {
require.ErrorContains(t, err, tc.err)
continue
}
defer stmt.Close()
}
}