Skip to content

Commit

Permalink
hacky way of preventing warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cor committed Jul 24, 2024
1 parent f685de1 commit 7fa5137
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 20 additions & 7 deletions sql/base_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type BaseSession struct {
idxReg *IndexRegistry
viewReg *ViewRegistry
warnings []*Warning
warningLock bool
warncnt uint16
locks map[string]bool
queriedDb string
Expand Down Expand Up @@ -340,21 +341,33 @@ func (s *BaseSession) Warnings() []*Warning {
for i := 0; i < n; i++ {
warns[i] = s.warnings[n-i-1]
}

return warns
}

// LockWarnings locks the session warnings so that they can't be cleared
func (s *BaseSession) LockWarnings() {
s.warningLock = true
}

// UnlockWarnings locks the session warnings so that they can be cleared
func (s *BaseSession) UnlockWarnings() {
s.warningLock = false
}

// ClearWarnings cleans up session warnings
func (s *BaseSession) ClearWarnings() {
if s.warningLock {
return
}
cnt := uint16(len(s.warnings))
if s.warncnt == cnt {
if s.warnings != nil {
s.warnings = s.warnings[:0]
}
s.warncnt = 0
} else {
if s.warncnt != cnt {
s.warncnt = cnt
return
}
if s.warnings != nil {
s.warnings = s.warnings[:0]
}
s.warncnt = 0
}

// WarningCount returns a number of session warnings
Expand Down
4 changes: 4 additions & 0 deletions sql/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ type Session interface {
ClearWarnings()
// WarningCount returns a number of session warnings
WarningCount() uint16
// LockWarnings prevents the session warnings from being cleared.
LockWarnings()
// UnlockWarnings allows the session warnings to be cleared.
UnlockWarnings()
// AddLock adds a lock to the set of locks owned by this user which will need to be released if this session terminates
AddLock(lockName string) error
// DelLock removes a lock from the set of locks owned by this user
Expand Down

0 comments on commit 7fa5137

Please sign in to comment.