forked from sijms/go-ora
/
transaction.go
34 lines (29 loc) · 884 Bytes
/
transaction.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
package go_ora
import (
"context"
"github.com/victorien-a/go-ora/v2/network"
)
type Transaction struct {
conn *Connection
ctx context.Context
}
func (tx *Transaction) Commit() error {
if tx.conn.State != Opened {
return &network.OracleError{ErrCode: 6413, ErrMsg: "ORA-06413: Connection not open"}
}
tx.conn.autoCommit = true
tx.conn.session.ResetBuffer()
tx.conn.session.StartContext(tx.ctx)
defer tx.conn.session.EndContext()
return (&simpleObject{connection: tx.conn, operationID: 0xE}).exec()
}
func (tx *Transaction) Rollback() error {
if tx.conn.State != Opened {
return &network.OracleError{ErrCode: 6413, ErrMsg: "ORA-06413: Connection not open"}
}
tx.conn.autoCommit = true
tx.conn.session.ResetBuffer()
tx.conn.session.StartContext(tx.ctx)
defer tx.conn.session.EndContext()
return (&simpleObject{connection: tx.conn, operationID: 0xF}).exec()
}