Skip to content

Commit

Permalink
Merge pull request petoju#12 from petoju/feature/fix-missing-grants
Browse files Browse the repository at this point in the history
Return no grants (with no error) when there is no such grant
  • Loading branch information
petoju authored Jun 7, 2022
2 parents 450d2d4 + 8665c12 commit f54602b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mysql/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
cleartextPasswords = "cleartext"
nativePasswords = "native"
unknownVarErrCode = 1193

mySQLErrorNoSuchGrant = 1133
)

type MySQLConfiguration struct {
Expand Down
5 changes: 5 additions & 0 deletions mysql/resource_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ func showUserGrants(db *sql.DB, user string) ([]*MySQLGrant, error) {
sql := fmt.Sprintf("SHOW GRANTS FOR %s", user)
rows, err := db.Query(sql)

if driverErr, ok := err.(*mysql.MySQLError); ok {
if driverErr.Number == mySQLErrorNoSuchGrant {
return []*MySQLGrant{}, nil
}
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f54602b

Please sign in to comment.