SQL().GET(&time.Time)的问题 #1107

Closed
opened 2018-09-30 08:11:36 +00:00 by usernameisnull · 1 comment
usernameisnull commented 2018-09-30 08:11:36 +00:00 (Migrated from github.com)
sql := "SELECT create_date From client WHERE report_id = ?"
var MaxDate time.Time
result,err:=conn.SQL(sql, 98977).Get(&MaxDate)
fmt.Println(result,err,MaxDate)

错误

panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

goroutine 1 [running]:
reflect.valueInterface(0x7bcc80, 0xc04216f380, 0x36, 0x4c1c01, 0x7c5b20, 0x7bcc80)
	G:/Go/src/reflect/value.go:942 +0x1e4
reflect.Value.Interface(0x7bcc80, 0xc04216f380, 0x36, 0x7bcc80, 0xc04216f380)
	G:/Go/src/reflect/value.go:931 +0x4b
github.com/go-xorm/xorm.(*Engine).mapType(0xc0421b6340, 0x8395a0, 0xc04216f380, 0x199, 0x839500, 0x199, 0xc04206fc08)
	E:/gopath/src/github.com/go-xorm/xorm/engine.go:1003 +0xc07
github.com/go-xorm/xorm.(*Engine).autoMapType(0xc0421b6340, 0x8395a0, 0xc04216f380, 0x199, 0x0, 0x0, 0x0)
	E:/gopath/src/github.com/go-xorm/xorm/engine.go:817 +0x189
github.com/go-xorm/xorm.(*Statement).setRefBean(0xc04209b618, 0x83a920, 0xc04216f380, 0x8395a0, 0xc04216f380)
	E:/gopath/src/github.com/go-xorm/xorm/statement.go:218 +0x70
github.com/go-xorm/xorm.(*Session).get(0xc04209b600, 0x83a920, 0xc04216f380, 0x1, 0x1, 0xc04209b600)
	E:/gopath/src/github.com/go-xorm/xorm/session_get.go:35 +0xbd3
github.com/go-xorm/xorm.(*Session).Get(0xc04209b600, 0x83a920, 0xc04216f380, 0xc042168f00, 0x0, 0x0)
	E:/gopath/src/github.com/go-xorm/xorm/session_get.go:23 +0x6c
```go sql := "SELECT create_date From client WHERE report_id = ?" var MaxDate time.Time result,err:=conn.SQL(sql, 98977).Get(&MaxDate) fmt.Println(result,err,MaxDate) ``` 错误 ```log panic: reflect.Value.Interface: cannot return value obtained from unexported field or method goroutine 1 [running]: reflect.valueInterface(0x7bcc80, 0xc04216f380, 0x36, 0x4c1c01, 0x7c5b20, 0x7bcc80) G:/Go/src/reflect/value.go:942 +0x1e4 reflect.Value.Interface(0x7bcc80, 0xc04216f380, 0x36, 0x7bcc80, 0xc04216f380) G:/Go/src/reflect/value.go:931 +0x4b github.com/go-xorm/xorm.(*Engine).mapType(0xc0421b6340, 0x8395a0, 0xc04216f380, 0x199, 0x839500, 0x199, 0xc04206fc08) E:/gopath/src/github.com/go-xorm/xorm/engine.go:1003 +0xc07 github.com/go-xorm/xorm.(*Engine).autoMapType(0xc0421b6340, 0x8395a0, 0xc04216f380, 0x199, 0x0, 0x0, 0x0) E:/gopath/src/github.com/go-xorm/xorm/engine.go:817 +0x189 github.com/go-xorm/xorm.(*Statement).setRefBean(0xc04209b618, 0x83a920, 0xc04216f380, 0x8395a0, 0xc04216f380) E:/gopath/src/github.com/go-xorm/xorm/statement.go:218 +0x70 github.com/go-xorm/xorm.(*Session).get(0xc04209b600, 0x83a920, 0xc04216f380, 0x1, 0x1, 0xc04209b600) E:/gopath/src/github.com/go-xorm/xorm/session_get.go:35 +0xbd3 github.com/go-xorm/xorm.(*Session).Get(0xc04209b600, 0x83a920, 0xc04216f380, 0xc042168f00, 0x0, 0x0) E:/gopath/src/github.com/go-xorm/xorm/session_get.go:23 +0x6c ```
Member

感谢反馈,目前来说可以尝试用一个struct包一下这个结果,或是直接以string形式读出,再做转换。time.Time的直接读取问题我们将会尽快解决,也欢迎您直接提出PR。

感谢反馈,目前来说可以尝试用一个``struct``包一下这个结果,或是直接以``string``形式读出,再做转换。``time.Time``的直接读取问题我们将会尽快解决,也欢迎您直接提出PR。
lunny added this to the 1.1.1 milestone 2020-03-04 02:23:03 +00:00
lunny modified the milestone from 1.1.1 to 1.2.0 2021-06-12 03:59:38 +00:00
lunny referenced this issue from a commit 2021-07-11 01:30:34 +00:00
lunny closed this issue 2021-07-11 01:30:34 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1107
No description provided.