-
Notifications
You must be signed in to change notification settings - Fork 0
/
rows_windows.go
48 lines (43 loc) · 1.05 KB
/
rows_windows.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
package dmdb
import (
"database/sql/driver"
"github.com/axgle/mahonia"
)
type Rows struct {
r driver.Rows
}
// 字符串解码函数,处理中文乱码
func convertToString(src string, srcCode string, tagCode string) string {
srcCoder := mahonia.NewDecoder(srcCode)
srcResult := srcCoder.ConvertString(src)
tagCoder := mahonia.NewDecoder(tagCode)
_, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
result := string(cdata)
return result
}
func (r *Rows) Columns() []string {
return r.r.Columns()
}
func (r *Rows) Next(dest []driver.Value) error {
if err := r.r.Next(dest); err != nil {
return err
}
//转换gbk==>utf8
for i, v := range dest {
switch tv := v.(type) {
case []byte:
dest[i] = convertToString(string(tv), "gbk", "utf-8")
}
}
return nil
}
func (r *Rows) Close() error {
return r.r.Close()
}
//ColumnTypeDatabaseTypeName 附加的
func (r *Rows) ColumnTypeDatabaseTypeName(index int) string {
if tr, ok := r.r.(driver.RowsColumnTypeDatabaseTypeName); ok {
return tr.ColumnTypeDatabaseTypeName(index)
}
return ""
}