Skip to content

Commit 59aa15b

Browse files
authored
SNOW-857631 Handle multistatement query type (#864)
1 parent 1043498 commit 59aa15b

4 files changed

+27
-7
lines changed

arrow_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ import (
1313
"time"
1414
)
1515

16+
//A test just to show Snowflake version
17+
func TestCheckVersion(t *testing.T) {
18+
conn := openConn(t)
19+
defer conn.Close()
20+
21+
rows, err := conn.QueryContext(context.Background(), "SELECT current_version()")
22+
if err != nil {
23+
t.Error(err)
24+
}
25+
defer rows.Close()
26+
27+
if !rows.Next() {
28+
t.Fatalf("failed to find any row")
29+
}
30+
var s string
31+
if err = rows.Scan(&s); err != nil {
32+
t.Fatal(err)
33+
}
34+
println(s)
35+
}
36+
1637
func TestArrowBigInt(t *testing.T) {
1738
conn := openConn(t)
1839
defer conn.Close()

connection.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ const (
3737
)
3838

3939
const (
40-
statementTypeIDMulti = int64(0x1000)
40+
statementTypeIDSelect = int64(0x1000)
4141
statementTypeIDDml = int64(0x3000)
4242
statementTypeIDMultiTableInsert = statementTypeIDDml + int64(0x500)
43+
statementTypeIDMultistatement = int64(0xA000)
4344
)
4445

4546
const (

connection_util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ func updateRows(data execResponseData) (int64, error) {
213213
// Note that the statement type code is also equivalent to type INSERT, so an
214214
// additional check of the name is required
215215
func isMultiStmt(data *execResponseData) bool {
216-
return data.StatementTypeID == statementTypeIDMulti &&
217-
data.RowType[0].Name == "multiple statement execution"
216+
var isMultistatementByReturningSelect = data.StatementTypeID == statementTypeIDSelect && data.RowType[0].Name == "multiple statement execution"
217+
return isMultistatementByReturningSelect || data.StatementTypeID == statementTypeIDMultistatement
218218
}
219219

220220
func getResumeQueryID(ctx context.Context) (string, error) {

multistatement_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ func TestMultiStatementExecuteNoResultSet(t *testing.T) {
2323
"commit;"
2424

2525
runDBTest(t, func(dbt *DBTest) {
26-
dbt.mustExec("drop table if exists test_multi_statement_txn")
27-
dbt.mustExec(`create or replace table test_multi_statement_txn(
28-
c1 number, c2 string) as select 10, 'z'`)
29-
defer dbt.mustExec("drop table if exists test_multi_statement_txn")
26+
dbt.mustExec(`create or replace table test_multi_statement_txn(c1 number, c2 string) as select 10, 'z'`)
3027

3128
res := dbt.mustExecContext(ctx, multiStmtQuery)
3229
count, err := res.RowsAffected()
@@ -48,6 +45,7 @@ func TestMultiStatementQueryResultSet(t *testing.T) {
4845

4946
var v1, v2, v3 int64
5047
var v4 string
48+
5149
runDBTest(t, func(dbt *DBTest) {
5250
rows := dbt.mustQueryContext(ctx, multiStmtQuery)
5351
defer rows.Close()

0 commit comments

Comments
 (0)