File: error_example_test.go

package info (click to toggle)
golang-github-denisenkom-go-mssqldb 0.0~git20170717.0.8fccfc8-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,240 kB
  • sloc: makefile: 5
file content (38 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package mssql

import "fmt"

func ExampleError_1() {
	// call a function that might return a mssql error
	err := callUsingMSSQL()

	type ErrorWithNumber interface {
		SQLErrorNumber() int32
	}

	if errorWithNumber, ok := err.(ErrorWithNumber); ok {
		if errorWithNumber.SQLErrorNumber() == 1205 {
			fmt.Println("deadlock error")
		}
	}
}

func ExampleError_2() {
	// call a function that might return a mssql error
	err := callUsingMSSQL()

	type SQLError interface {
		SQLErrorNumber() int32
		SQLErrorMessage() string
	}

	if sqlError, ok := err.(SQLError); ok {
		if sqlError.SQLErrorNumber() == 1205 {
			fmt.Println("deadlock error", sqlError.SQLErrorMessage())
		}
	}
}

func callUsingMSSQL() error {
	return nil
}