utils_go18.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // +build go1.8
  9. package mysql
  10. import (
  11. "crypto/tls"
  12. "database/sql"
  13. "database/sql/driver"
  14. "errors"
  15. )
  16. func cloneTLSConfig(c *tls.Config) *tls.Config {
  17. return c.Clone()
  18. }
  19. func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) {
  20. dargs := make([]driver.Value, len(named))
  21. for n, param := range named {
  22. if len(param.Name) > 0 {
  23. // TODO: support the use of Named Parameters #561
  24. return nil, errors.New("mysql: driver does not support the use of Named Parameters")
  25. }
  26. dargs[n] = param.Value
  27. }
  28. return dargs, nil
  29. }
  30. func mapIsolationLevel(level driver.IsolationLevel) (string, error) {
  31. switch sql.IsolationLevel(level) {
  32. case sql.LevelRepeatableRead:
  33. return "REPEATABLE READ", nil
  34. case sql.LevelReadCommitted:
  35. return "READ COMMITTED", nil
  36. case sql.LevelReadUncommitted:
  37. return "READ UNCOMMITTED", nil
  38. case sql.LevelSerializable:
  39. return "SERIALIZABLE", nil
  40. default:
  41. return "", errors.New("mysql: unsupported isolation level: " + string(level))
  42. }
  43. }