utils_go18.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2017 The Go-MySQL-Driver Authors. All rights reserved.
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public
  6. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  7. // You can obtain one at http://mozilla.org/MPL/2.0/.
  8. //go:build go1.8
  9. // +build go1.8
  10. package mysql
  11. import (
  12. "crypto/tls"
  13. "database/sql"
  14. "database/sql/driver"
  15. "errors"
  16. "fmt"
  17. )
  18. func cloneTLSConfig(c *tls.Config) *tls.Config {
  19. return c.Clone()
  20. }
  21. func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) {
  22. dargs := make([]driver.Value, len(named))
  23. for n, param := range named {
  24. if len(param.Name) > 0 {
  25. // TODO: support the use of Named Parameters #561
  26. return nil, errors.New("mysql: driver does not support the use of Named Parameters")
  27. }
  28. dargs[n] = param.Value
  29. }
  30. return dargs, nil
  31. }
  32. func mapIsolationLevel(level driver.IsolationLevel) (string, error) {
  33. switch sql.IsolationLevel(level) {
  34. case sql.LevelRepeatableRead:
  35. return "REPEATABLE READ", nil
  36. case sql.LevelReadCommitted:
  37. return "READ COMMITTED", nil
  38. case sql.LevelReadUncommitted:
  39. return "READ UNCOMMITTED", nil
  40. case sql.LevelSerializable:
  41. return "SERIALIZABLE", nil
  42. default:
  43. return "", fmt.Errorf("mysql: unsupported isolation level: %v", level)
  44. }
  45. }