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.
 
 
 
 
 

54 lines
1.3 KiB

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