Uh oh!
There was an error while loading. Please reload this page.
forked from alexbrainman/odbc
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
Latest commit
74 lines (65 loc) · 1.59 KB
/
Copy patherror.go
File metadata and controls
74 lines (65 loc) · 1.59 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package odbc
import (
"database/sql/driver"
"fmt"
"strings"
"unsafe"
"github.com/sqlpipe/odbc/api"
)
funcIsError(ret api.SQLRETURN) bool {
return!(ret==api.SQL_SUCCESS||ret==api.SQL_SUCCESS_WITH_INFO)
}
typeDiagRecordstruct {
Statestring
NativeErrorint
Messagestring
}
func (r*DiagRecord) String() string {
returnfmt.Sprintf("{%s} %s", r.State, r.Message)
}
typeErrorstruct {
APINamestring
Diag []DiagRecord
}
func (e*Error) Error() string {
ss:=make([]string, len(e.Diag))
fori, r:=rangee.Diag {
ss[i] =r.String()
}
returne.APIName+": "+strings.Join(ss, "\n")
}
funcNewError(apiNamestring, handleinterface{}) error {
h, ht, herr:=ToHandleAndType(handle)
ifherr!=nil {
returnherr
}
err:=&Error{APIName: apiName}
varne api.SQLINTEGER
state:=make([]uint16, 6)
msg:=make([]uint16, api.SQL_MAX_MESSAGE_LENGTH)
fori:=1; ; i++ {
ret:=api.SQLGetDiagRec(ht, h, api.SQLSMALLINT(i),
(*api.SQLWCHAR)(unsafe.Pointer(&state[0])), &ne,
(*api.SQLWCHAR)(unsafe.Pointer(&msg[0])),
api.SQLSMALLINT(len(msg)), nil)
ifret==api.SQL_NO_DATA {
break
}
ifIsError(ret) {
returnfmt.Errorf("SQLGetDiagRec failed: ret=%d", ret)
}
r:=DiagRecord{
State: api.UTF16ToString(state),
NativeError: int(ne),
Message: api.UTF16ToString(msg),
}
ifr.State=="08S01" {
returndriver.ErrBadConn
}
err.Diag=append(err.Diag, r)
}
returnerr
}