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

Method Execute

backend/plugin/db/redshift/redshift.go:158–204  ·  view source on GitHub ↗

Execute will execute the statement. For CREATE DATABASE statement, some types of databases such as Postgres will not use transactions to execute the statement but will still use transactions to execute the rest of statements.

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

Source from the content-addressed store, hash-verified

156// Execute will execute the statement. For CREATE DATABASE statement, some types of databases such as Postgres
157// will not use transactions to execute the statement but will still use transactions to execute the rest of statements.
158func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteOptions) (int64, error) {
159 if d.datashare {
160 return 0, errors.Errorf("datashare database cannot be updated")
161 }
162 if opts.CreateDatabase {
163 if err := d.createDatabaseExecute(ctx, statement); err != nil {
164 return 0, err
165 }
166 return 0, nil
167 }
168
169 // Parse transaction mode from the script
170 config, cleanedStatement := base.ParseTransactionConfig(statement)
171 statement = cleanedStatement
172 transactionMode := config.Mode
173
174 // Apply default when transaction mode is not specified
175 if transactionMode == common.TransactionModeUnspecified {
176 transactionMode = common.GetDefaultTransactionMode()
177 }
178
179 var commands []base.Statement
180 oneshot := true
181 if len(statement) <= common.MaxSheetCheckSize {
182 singleSQLs, err := redshiftparser.SplitSQL(statement)
183 if err != nil {
184 return 0, err
185 }
186 commands = base.FilterEmptyStatements(singleSQLs)
187 if len(commands) <= common.MaximumCommands {
188 oneshot = false
189 }
190 }
191 if oneshot {
192 commands = []base.Statement{
193 {
194 Text: statement,
195 },
196 }
197 }
198
199 // Execute based on transaction mode
200 if transactionMode == common.TransactionModeOff {
201 return d.executeInAutoCommitMode(ctx, commands, opts)
202 }
203 return d.executeInTransactionMode(ctx, commands, opts)
204}
205
206func (d *Driver) createDatabaseExecute(ctx context.Context, statement string) error {
207 databaseName, err := getDatabaseInCreateDatabaseStatement(statement)

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 7

createDatabaseExecuteMethod · 0.95
ParseTransactionConfigFunction · 0.92
FilterEmptyStatementsFunction · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected