Skip to content

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

snowflake driver: execute the statement only if it has meaningful statements.

spinningbot7d9b359989bd
diff --git a/plugin/db/snowflake/snowflake.go b/plugin/db/snowflake/snowflake.go
index 9ded06413c..c9a66d6c6d 100644
--- a/plugin/db/snowflake/snowflake.go
+++ b/plugin/db/snowflake/snowflake.go
@@ -383,15 +383,6 @@ func (driver *Driver) getUserList(ctx context.Context) ([]*db.DBUser, error) {
}
func (driver *Driver) Execute(ctx context.Context, statement string) error {
- if err := driver.UseRole(ctx, sysAdminRole); err != nil {
- return nil
- }
- tx, err := driver.db.BeginTx(ctx, nil)
- if err != nil {
- return err
- }
- defer tx.Rollback()
-
count := 0
f := func(stmt string) error {
count++
@@ -402,6 +393,18 @@ func (driver *Driver) Execute(ctx context.Context, statement string) error {
return err
}
+ if count <= 0 {
+ return nil
+ }
+
+ if err := driver.UseRole(ctx, sysAdminRole); err != nil {
+ return nil
+ }
+ tx, err := driver.db.BeginTx(ctx, nil)
+ if err != nil {
+ return err
+ }
+ defer tx.Rollback()
mctx, err := snow.WithMultiStatement(ctx, count)
if err != nil {
return err
diff --git a/plugin/db/util/driverutil.go b/plugin/db/util/driverutil.go
index 344d481974..a3d777f8e7 100644
--- a/plugin/db/util/driverutil.go
+++ b/plugin/db/util/driverutil.go
@@ -71,13 +71,17 @@ func ApplyMultiStatements(sc *bufio.Scanner, f func(string) error) error {
continue
}
if execute {
- if err := f(s); err != nil {
- return fmt.Errorf("execute query %q failed: %v", s, err)
+ s = strings.Trim(s, "\n\t ")
+ if s != "" {
+ if err := f(s); err != nil {
+ return fmt.Errorf("execute query %q failed: %v", s, err)
+ }
}
s = ""
}
}
// Apply the remaining content.
+ s = strings.Trim(s, "\n\t ")
if s != "" {
if err := f(s); err != nil {
return fmt.Errorf("execute query %q failed: %v", s, err)