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.

64 lines
1.3 KiB

  1. // +build go1.9
  2. package mssql
  3. import (
  4. "database/sql"
  5. "database/sql/driver"
  6. "fmt"
  7. // "github.com/cockroachdb/apd"
  8. )
  9. // Type alias provided for compibility.
  10. //
  11. // Deprecated: users should transition to the new names when possible.
  12. type MssqlDriver = Driver
  13. type MssqlBulk = Bulk
  14. type MssqlBulkOptions = BulkOptions
  15. type MssqlConn = Conn
  16. type MssqlResult = Result
  17. type MssqlRows = Rows
  18. type MssqlStmt = Stmt
  19. var _ driver.NamedValueChecker = &Conn{}
  20. func (c *Conn) CheckNamedValue(nv *driver.NamedValue) error {
  21. switch v := nv.Value.(type) {
  22. case sql.Out:
  23. if c.outs == nil {
  24. c.outs = make(map[string]interface{})
  25. }
  26. c.outs[nv.Name] = v.Dest
  27. // Unwrap the Out value and check the inner value.
  28. lnv := *nv
  29. lnv.Value = v.Dest
  30. err := c.CheckNamedValue(&lnv)
  31. if err != nil {
  32. if err != driver.ErrSkip {
  33. return err
  34. }
  35. lnv.Value, err = driver.DefaultParameterConverter.ConvertValue(lnv.Value)
  36. if err != nil {
  37. return err
  38. }
  39. }
  40. nv.Value = sql.Out{Dest: lnv.Value}
  41. return nil
  42. // case *apd.Decimal:
  43. // return nil
  44. default:
  45. return driver.ErrSkip
  46. }
  47. }
  48. func (s *Stmt) makeParamExtra(val driver.Value) (res Param, err error) {
  49. switch val := val.(type) {
  50. case sql.Out:
  51. res, err = s.makeParam(val.Dest)
  52. res.Flags = fByRevValue
  53. default:
  54. err = fmt.Errorf("mssql: unknown type for %T", val)
  55. }
  56. return
  57. }