MCPcopy Create free account
hub / github.com/bytebase/bytebase / Execute

Method Execute

backend/plugin/db/oracle/oracle.go:105–151  ·  view source on GitHub ↗

Execute executes the migration, `beforeCommitTxFunc` will be called before transaction commit and after executing `statement`. Callers can use `beforeCommitTx` to do some extra work before transaction commit, like get the transaction id. Any error returned by `beforeCommitTx` will rollback the tran

(ctx context.Context, statement string, opts db.ExecuteOptions)

Source from the content-addressed store, hash-verified

103// Callers can use `beforeCommitTx` to do some extra work before transaction commit, like get the transaction id.
104// Any error returned by `beforeCommitTx` will rollback the transaction, so it is the callers' responsibility to return nil if the error occurs in `beforeCommitTx` is not fatal.
105func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteOptions) (int64, error) {
106 if opts.CreateDatabase {
107 return 0, errors.New("create database is not supported for Oracle")
108 }
109
110 // Parse transaction mode from the script
111 config, cleanedStatement := base.ParseTransactionConfig(statement)
112 statement = cleanedStatement
113 transactionMode := config.Mode
114
115 // Apply default when transaction mode is not specified
116 if transactionMode == common.TransactionModeUnspecified {
117 transactionMode = common.GetDefaultTransactionMode()
118 }
119
120 var commands []base.Statement
121 if len(statement) <= common.MaxSheetCheckSize {
122 // Use Oracle sql parser.
123 singleSQLs, err := plsqlparser.SplitSQL(statement)
124 if err != nil {
125 return 0, errors.Wrapf(err, "failed to split sql")
126 }
127 singleSQLs = base.FilterEmptyStatements(singleSQLs)
128 if len(singleSQLs) == 0 {
129 return 0, nil
130 }
131 commands = singleSQLs
132 } else {
133 commands = []base.Statement{
134 {
135 Text: statement,
136 },
137 }
138 }
139
140 conn, err := d.db.Conn(ctx)
141 if err != nil {
142 return 0, errors.Wrapf(err, "failed to get connection")
143 }
144 defer conn.Close()
145
146 // Execute based on transaction mode
147 if transactionMode == common.TransactionModeOff {
148 return d.executeInAutoCommitMode(ctx, conn, commands, opts)
149 }
150 return d.executeInTransactionMode(ctx, conn, commands, opts)
151}
152
153// executeInTransactionMode executes statements within a single transaction
154func (*Driver) executeInTransactionMode(ctx context.Context, conn *sql.Conn, commands []base.Statement, opts db.ExecuteOptions) (int64, error) {

Callers

nothing calls this directly

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 6

ParseTransactionConfigFunction · 0.92
FilterEmptyStatementsFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected