error.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package mssql
  2. import (
  3. "fmt"
  4. )
  5. // Error represents an SQL Server error. This
  6. // type includes methods for reading the contents
  7. // of the struct, which allows calling programs
  8. // to check for specific error conditions without
  9. // having to import this package directly.
  10. type Error struct {
  11. Number int32
  12. State uint8
  13. Class uint8
  14. Message string
  15. ServerName string
  16. ProcName string
  17. LineNo int32
  18. }
  19. func (e Error) Error() string {
  20. return "mssql: " + e.Message
  21. }
  22. // SQLErrorNumber returns the SQL Server error number.
  23. func (e Error) SQLErrorNumber() int32 {
  24. return e.Number
  25. }
  26. func (e Error) SQLErrorState() uint8 {
  27. return e.State
  28. }
  29. func (e Error) SQLErrorClass() uint8 {
  30. return e.Class
  31. }
  32. func (e Error) SQLErrorMessage() string {
  33. return e.Message
  34. }
  35. func (e Error) SQLErrorServerName() string {
  36. return e.ServerName
  37. }
  38. func (e Error) SQLErrorProcName() string {
  39. return e.ProcName
  40. }
  41. func (e Error) SQLErrorLineNo() int32 {
  42. return e.LineNo
  43. }
  44. type StreamError struct {
  45. Message string
  46. }
  47. func (e StreamError) Error() string {
  48. return e.Message
  49. }
  50. func streamErrorf(format string, v ...interface{}) StreamError {
  51. return StreamError{"Invalid TDS stream: " + fmt.Sprintf(format, v...)}
  52. }
  53. func badStreamPanic(err error) {
  54. panic(err)
  55. }
  56. func badStreamPanicf(format string, v ...interface{}) {
  57. panic(streamErrorf(format, v...))
  58. }