diff --git a/transaction.go b/transaction.go index 204d9624c..154faa227 100644 --- a/transaction.go +++ b/transaction.go @@ -4,6 +4,7 @@ package gosnowflake import ( "database/sql/driver" + "errors" ) type snowflakeTx struct { @@ -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) { @@ -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 }