Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dheyman-1 committed May 26, 2023
1 parent ae99e8d commit 087bfd6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package gosnowflake

import (
"database/sql/driver"
"errors"
)

type snowflakeTx struct {
Expand All @@ -17,8 +18,14 @@ const (
rollback
)

func (cmd txCommand) string() string {
return [...]string{"COMMIT", "ROLLBACK"}[cmd]
func (cmd txCommand) string() (txStr string, err error) {
switch cmd {
case commit:
return "COMMIT", nil
case rollback:
return "ROLLBACK", nil
}
return "", errors.New("unsupported transaction command")
}

func (tx *snowflakeTx) Commit() (err error) {
Expand All @@ -30,10 +37,14 @@ func (tx *snowflakeTx) Rollback() (err error) {
}

func (tx *snowflakeTx) execTxCommand(command txCommand) (err error) {
txStr, err := command.string()
if err != nil {
return err
}
if tx.sc == nil || tx.sc.rest == nil {
return driver.ErrBadConn
}
_, err = tx.sc.exec(tx.sc.ctx, command.string(), false /* noResult */, false /* isInternal */, false /* describeOnly */, nil)
_, err = tx.sc.exec(tx.sc.ctx, txStr, false /* noResult */, false /* isInternal */, false /* describeOnly */, nil)
if err != nil {
return
}
Expand Down

0 comments on commit 087bfd6

Please sign in to comment.