Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: ignore no affected rows error for snowflake execute (#3855)

Danny Xu796a1a786541
diff --git a/plugin/db/clickhouse/clickhouse.go b/plugin/db/clickhouse/clickhouse.go
index 0fdba02709..6a79f96bb9 100644
--- a/plugin/db/clickhouse/clickhouse.go
+++ b/plugin/db/clickhouse/clickhouse.go
@@ -122,17 +122,19 @@ func (driver *Driver) Execute(ctx context.Context, statement string, _ bool) (in
}
defer tx.Rollback()
- totalRowsEffected := int64(0)
+ totalRowsAffected := int64(0)
f := func(stmt string) error {
sqlResult, err := tx.ExecContext(ctx, stmt)
if err != nil {
return err
}
- rowsEffected, err := sqlResult.RowsAffected()
+ rowsAffected, err := sqlResult.RowsAffected()
if err != nil {
- return err
+ // Since we cannot differentiate DDL and DML yet, we have to ignore the error.
+ log.Debug("rowsAffected returns error", zap.Error(err))
+ } else {
+ totalRowsAffected += rowsAffected
}
- totalRowsEffected += rowsEffected
return nil
}
diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.go
index bc70de4539..10f8b06e6b 100644
--- a/plugin/db/mysql/mysql.go
+++ b/plugin/db/mysql/mysql.go
@@ -12,8 +12,10 @@ import (
"github.com/go-sql-driver/mysql"
"github.com/pkg/errors"
"go.uber.org/multierr"
+ "go.uber.org/zap"
"github.com/bytebase/bytebase/common"
+ "github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/db"
"github.com/bytebase/bytebase/plugin/db/util"
bbparser "github.com/bytebase/bytebase/plugin/parser"
@@ -185,12 +187,14 @@ func (driver *Driver) Execute(ctx context.Context, statement string, _ bool) (in
if err := tx.Commit(); err != nil {
return 0, err
}
- rowsEffected, err := sqlResult.RowsAffected()
+ rowsAffected, err := sqlResult.RowsAffected()
if err != nil {
- return 0, err
+ // Since we cannot differentiate DDL and DML yet, we have to ignore the error.
+ log.Debug("rowsAffected returns error", zap.Error(err))
+ return 0, nil
}
- return rowsEffected, nil
+ return rowsAffected, nil
}
// GetMigrationConnID gets the ID of the connection executing migrations.
diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.go
index 4e780a9ed4..a0123f3f91 100644
--- a/plugin/db/pg/pg.go
+++ b/plugin/db/pg/pg.go
@@ -235,7 +235,7 @@ func (driver *Driver) Execute(ctx context.Context, statement string, createDatab
connected := false
var remainingStmts []string
- totalRowsEffected := int64(0)
+ totalRowsAffected := int64(0)
f := func(stmt string) error {
// We don't use transaction for creating / altering databases in Postgres.
// We will execute the statement directly before "\\connect" statement.
@@ -285,11 +285,13 @@ func (driver *Driver) Execute(ctx context.Context, statement string, createDatab
if err != nil {
return err
}
- rowsEffected, err := sqlResult.RowsAffected()
+ rowsAffected, err := sqlResult.RowsAffected()
if err != nil {
- return err
+ // Since we cannot differentiate DDL and DML yet, we have to ignore the error.
+ log.Debug("rowsAffected returns error", zap.Error(err))
+ } else {
+ totalRowsAffected += rowsAffected
}
- totalRowsEffected += rowsEffected
}
} else {
if isSuperuserStatement(stmt) {
@@ -336,13 +338,14 @@ func (driver *Driver) Execute(ctx context.Context, statement string, createDatab
if err := tx.Commit(); err != nil {
return 0, err
}
- rowsEffected, err := sqlResult.RowsAffected()
+ rowsAffected, err := sqlResult.RowsAffected()
if err != nil {
- return 0, err
+ // Since we cannot differentiate DDL and DML yet, we have to ignore the error.
+ log.Debug("rowsAffected returns error", zap.Error(err))
+ } else {
+ totalRowsAffected += rowsAffected
}
- totalRowsEffected += rowsEffected
-
- return totalRowsEffected, nil
+ return totalRowsAffected, nil
}
func isSuperuserStatement(stmt string) bool {
diff --git a/plugin/db/snowflake/snowflake.go b/plugin/db/snowflake/snowflake.go
index 3905420b3b..dc75e4463a 100644
--- a/plugin/db/snowflake/snowflake.go
+++ b/plugin/db/snowflake/snowflake.go
@@ -253,11 +253,13 @@ func (driver *Driver) Execute(ctx context.Context, statement string, _ bool) (in
return 0, err
}
- rowsEffected, err := result.RowsAffected()
+ rowsAffected, err := result.RowsAffected()
+ // Since we cannot differentiate DDL and DML yet, we have to ignore the error.
if err != nil {
- return 0, err
+ log.Debug("rowsAffected returns error", zap.Error(err))
+ return 0, nil
}
- return rowsEffected, nil
+ return rowsAffected, nil
}
// Query queries a SQL statement.
diff --git a/plugin/db/sqlite/sqlite.go b/plugin/db/sqlite/sqlite.go
index b742d1ff97..c5329e8caa 100644
--- a/plugin/db/sqlite/sqlite.go
+++ b/plugin/db/sqlite/sqlite.go
@@ -12,7 +12,9 @@ import (
// Import sqlite3 driver.
_ "github.com/mattn/go-sqlite3"
"github.com/pkg/errors"
+ "go.uber.org/zap"
+ "github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/db"
"github.com/bytebase/bytebase/plugin/db/util"
)
@@ -168,12 +170,14 @@ func (driver *Driver) Execute(ctx context.Context, statement string, _ bool) (in
if err := tx.Commit(); err != nil {
return 0, err
}
- rowsEffected, err := sqlResult.RowsAffected()
+ rowsAffected, err := sqlResult.RowsAffected()
if err != nil {
- return 0, err
+ // Since we cannot differentiate DDL and DML yet, we have to ignore the error.
+ log.Debug("rowsAffected returns error", zap.Error(err))
+ return 0, nil
}
- return rowsEffected, nil
+ return rowsAffected, nil
}
// Query queries a SQL statement.