-
Notifications
You must be signed in to change notification settings - Fork 350
/
godror.go
60 lines (57 loc) · 1.21 KB
/
godror.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Package godror defines and registers usql's GO DRiver for ORacle driver.
// Requires CGO. Uses Oracle's ODPI-C (instant client) library.
//
// See: https://github.com/godror/godror
// Group: all
package godror
import (
"errors"
"fmt"
"strings"
_ "github.com/godror/godror" // DRIVER
"github.com/xo/usql/drivers/oracle/orshared"
)
func init() {
orshared.Register(
"godror",
// unwrap error
func(err error) (string, string) {
if e := errors.Unwrap(err); e != nil {
err = e
}
code, msg := "", err.Error()
if e, ok := err.(interface {
Code() int
}); ok {
code = fmt.Sprintf("ORA-%05d", e.Code())
}
if e, ok := err.(interface {
Message() string
}); ok {
msg = e.Message()
}
if i := strings.LastIndex(msg, "ORA-"); msg == "" && i != -1 {
msg = msg[i:]
if j := strings.Index(msg, ":"); j != -1 {
msg = msg[j+1:]
if code == "" {
code = msg[i:j]
}
}
}
return code, strings.TrimSpace(msg)
},
// is password error
func(err error) bool {
if e := errors.Unwrap(err); e != nil {
err = e
}
if e, ok := err.(interface {
Code() int
}); ok {
return e.Code() == 1017 || e.Code() == 1005
}
return false
},
)
}