Update flushSQL()

bug fix, optimization, refactoring