A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

53 lines
1.3 KiB

  1. // +build !sqlite,!wflib
  2. /*
  3. * Copyright © 2019-2020 A Bunch Tell LLC.
  4. *
  5. * This file is part of WriteFreely.
  6. *
  7. * WriteFreely is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License, included
  9. * in the LICENSE file in this source code package.
  10. */
  11. package writefreely
  12. import (
  13. "github.com/go-sql-driver/mysql"
  14. "github.com/writeas/web-core/log"
  15. )
  16. func (db *datastore) isDuplicateKeyErr(err error) bool {
  17. if db.driverName == driverMySQL {
  18. if mysqlErr, ok := err.(*mysql.MySQLError); ok {
  19. return mysqlErr.Number == mySQLErrDuplicateKey
  20. }
  21. } else {
  22. log.Error("isDuplicateKeyErr: failed check for unrecognized driver '%s'", db.driverName)
  23. }
  24. return false
  25. }
  26. func (db *datastore) isIgnorableError(err error) bool {
  27. if db.driverName == driverMySQL {
  28. if mysqlErr, ok := err.(*mysql.MySQLError); ok {
  29. return mysqlErr.Number == mySQLErrCollationMix
  30. }
  31. } else {
  32. log.Error("isIgnorableError: failed check for unrecognized driver '%s'", db.driverName)
  33. }
  34. return false
  35. }
  36. func (db *datastore) isHighLoadError(err error) bool {
  37. if db.driverName == driverMySQL {
  38. if mysqlErr, ok := err.(*mysql.MySQLError); ok {
  39. return mysqlErr.Number == mySQLErrMaxUserConns || mysqlErr.Number == mySQLErrTooManyConns
  40. }
  41. }
  42. return false
  43. }