connection_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2013 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. package mysql
  9. import (
  10. "database/sql/driver"
  11. "testing"
  12. )
  13. func TestInterpolateParams(t *testing.T) {
  14. mc := &mysqlConn{
  15. buf: newBuffer(nil),
  16. maxPacketAllowed: maxPacketSize,
  17. cfg: &Config{
  18. InterpolateParams: true,
  19. },
  20. }
  21. q, err := mc.interpolateParams("SELECT ?+?", []driver.Value{int64(42), "gopher"})
  22. if err != nil {
  23. t.Errorf("Expected err=nil, got %#v", err)
  24. return
  25. }
  26. expected := `SELECT 42+'gopher'`
  27. if q != expected {
  28. t.Errorf("Expected: %q\nGot: %q", expected, q)
  29. }
  30. }
  31. func TestInterpolateParamsTooManyPlaceholders(t *testing.T) {
  32. mc := &mysqlConn{
  33. buf: newBuffer(nil),
  34. maxPacketAllowed: maxPacketSize,
  35. cfg: &Config{
  36. InterpolateParams: true,
  37. },
  38. }
  39. q, err := mc.interpolateParams("SELECT ?+?", []driver.Value{int64(42)})
  40. if err != driver.ErrSkip {
  41. t.Errorf("Expected err=driver.ErrSkip, got err=%#v, q=%#v", err, q)
  42. }
  43. }