-
Notifications
You must be signed in to change notification settings - Fork 0
/
cursor.go
59 lines (51 loc) · 1.4 KB
/
cursor.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
package flexmy
import (
"time"
"git.eaciitapp.com/sebar/dbflex/drivers/rdbms"
"github.com/eaciit/toolkit"
)
// Cursor represent cursor object. Inherits Cursor object of rdbms drivers and implementation of dbflex.ICursor
type Cursor struct {
rdbms.Cursor
}
func (c *Cursor) Serialize(dest interface{}) error {
var err error
m := toolkit.M{}
toolkit.Serde(dest, &m, "")
columnNames := c.ColumnNames()
//sqlTypes := c.ColumnTypes()
//fmt.Println("\n[debug] values:", toolkit.JsonString(c.values))
//fmt.Println("\n[debug] values Ptr:", toolkit.JsonString(c.valuesPtr))
for idx, value := range c.Values() {
name := columnNames[idx]
//ft := sqlTypes[idx]
v := string(value.([]byte))
if v == "0" {
m.Set(name, 0)
} else if v == "" {
m.Set(name, "")
} else {
if f := toolkit.ToFloat64(v, 4, toolkit.RoundingAuto); f != 0 {
m.Set(name, f)
} else if dt, err := time.Parse(time.RFC3339, v); err == nil {
m.Set(name, dt)
} else if dt = toolkit.String2Date(v, rdbms.TimeFormat()); dt.Year() > 1900 {
m.Set(name, dt)
} else {
m.Set(name, v)
}
}
//dbflex.Logger().Debugf("%s (%s) = %s\n", name, ft, v)
/*
} else {
m.Set(name, value)
dbflex.Logger().Debugf("%s [%s] = %v\n", name, ft, value)
}
*/
}
err = toolkit.Serde(m, dest, "")
if err != nil {
return toolkit.Error(err.Error() + toolkit.Sprintf(" object: %s", toolkit.JsonString(m)))
}
return nil
}