本站源代码
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.

53 lines
1.1KB

  1. // +build go1.10
  2. package mssql
  3. import (
  4. "context"
  5. "database/sql/driver"
  6. "errors"
  7. )
  8. var _ driver.Connector = &Connector{}
  9. var _ driver.SessionResetter = &Conn{}
  10. func (c *Conn) ResetSession(ctx context.Context) error {
  11. if !c.connectionGood {
  12. return driver.ErrBadConn
  13. }
  14. c.resetSession = true
  15. if c.connector == nil || len(c.connector.SessionInitSQL) == 0 {
  16. return nil
  17. }
  18. s, err := c.prepareContext(ctx, c.connector.SessionInitSQL)
  19. if err != nil {
  20. return driver.ErrBadConn
  21. }
  22. _, err = s.exec(ctx, nil)
  23. if err != nil {
  24. return driver.ErrBadConn
  25. }
  26. return nil
  27. }
  28. // Connect to the server and return a TDS connection.
  29. func (c *Connector) Connect(ctx context.Context) (driver.Conn, error) {
  30. conn, err := c.driver.connect(ctx, c, c.params)
  31. if err == nil {
  32. err = conn.ResetSession(ctx)
  33. }
  34. return conn, err
  35. }
  36. // Driver underlying the Connector.
  37. func (c *Connector) Driver() driver.Driver {
  38. return c.driver
  39. }
  40. func (r *Result) LastInsertId() (int64, error) {
  41. return -1, errors.New("LastInsertId is not supported. Please use the OUTPUT clause or add `select ID = convert(bigint, SCOPE_IDENTITY())` to the end of your query.")
  42. }
上海开阖软件有限公司 沪ICP备12045867号-1