Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-857631 Handle multistatement query type #864

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions arrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ import (
"time"
)

//A test just to show Snowflake version
func TestCheckVersion(t *testing.T) {
conn := openConn(t)
defer conn.Close()

rows, err := conn.QueryContext(context.Background(), "SELECT current_version()")
if err != nil {
t.Error(err)
}
defer rows.Close()

if !rows.Next() {
t.Fatalf("failed to find any row")
}
var s string
if err = rows.Scan(&s); err != nil {
t.Fatal(err)
}
println(s)
}

func TestArrowBigInt(t *testing.T) {
conn := openConn(t)
defer conn.Close()
Expand Down
3 changes: 2 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ const (
)

const (
statementTypeIDMulti = int64(0x1000)
statementTypeIDSelect = int64(0x1000)
statementTypeIDDml = int64(0x3000)
statementTypeIDMultiTableInsert = statementTypeIDDml + int64(0x500)
statementTypeIDMultistatement = int64(0xA000)
)

const (
Expand Down
4 changes: 2 additions & 2 deletions connection_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ func updateRows(data execResponseData) (int64, error) {
// Note that the statement type code is also equivalent to type INSERT, so an
// additional check of the name is required
func isMultiStmt(data *execResponseData) bool {
return data.StatementTypeID == statementTypeIDMulti &&
data.RowType[0].Name == "multiple statement execution"
var isMultistatementByReturningSelect = data.StatementTypeID == statementTypeIDSelect && data.RowType[0].Name == "multiple statement execution"
return isMultistatementByReturningSelect || data.StatementTypeID == statementTypeIDMultistatement
}

func getResumeQueryID(ctx context.Context) (string, error) {
Expand Down
6 changes: 2 additions & 4 deletions multistatement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ func TestMultiStatementExecuteNoResultSet(t *testing.T) {
"commit;"

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

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

var v1, v2, v3 int64
var v4 string

runDBTest(t, func(dbt *DBTest) {
rows := dbt.mustQueryContext(ctx, multiStmtQuery)
defer rows.Close()
Expand Down
Loading