MCPcopy Index your code
hub / github.com/bytebase/bytebase / executeInAutoCommitMode

Method executeInAutoCommitMode

backend/plugin/db/redshift/redshift.go:291–319  ·  view source on GitHub ↗

executeInAutoCommitMode executes statements sequentially in auto-commit mode

(ctx context.Context, commands []base.Statement, opts db.ExecuteOptions)

Source from the content-addressed store, hash-verified

289
290// executeInAutoCommitMode executes statements sequentially in auto-commit mode
291func (d *Driver) executeInAutoCommitMode(ctx context.Context, commands []base.Statement, opts db.ExecuteOptions) (int64, error) {
292 totalRowsAffected := int64(0)
293
294 for i, command := range commands {
295 opts.LogCommandExecute(command.Range, command.Text)
296 // Log the query statement in char code to see if there are some control characters that cause issues.
297 var charCode []rune
298 for _, r := range command.Text {
299 charCode = append(charCode, r)
300 }
301 slog.Debug("executing command", slog.Any("command", charCode), slog.Int("index", i))
302 sqlResult, err := d.db.ExecContext(ctx, command.Text)
303 if err != nil {
304 opts.LogCommandResponse(0, nil, err.Error())
305 // In auto-commit mode, we stop at the first error
306 // The database is left in a partially migrated state
307 return totalRowsAffected, err
308 }
309 rowsAffected, err := sqlResult.RowsAffected()
310 if err != nil {
311 // Since we cannot differentiate DDL and DML yet, we have to ignore the error.
312 slog.Debug("rowsAffected returns error", log.BBError(err))
313 }
314 opts.LogCommandResponse(rowsAffected, nil, "")
315 totalRowsAffected += rowsAffected
316 }
317
318 return totalRowsAffected, nil
319}
320
321func getDatabaseInCreateDatabaseStatement(createDatabaseStatement string) (string, error) {
322 raw := strings.TrimRight(createDatabaseStatement, ";")

Callers 1

ExecuteMethod · 0.95

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

BBErrorFunction · 0.92
LogCommandExecuteMethod · 0.80
DebugMethod · 0.80
LogCommandResponseMethod · 0.80
IntMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected