FindAndCount函数有问题 #1483

Closed
opened 2019-11-27 07:32:08 +00:00 by cyflhn · 3 comments
type User struct{
  name string
  ....
}
engine.Sql(sql, companyId).FindAndCount(&User)

这样调用会报sql: expected 8 destination arguments in Scan, not 1
但是engine.Sql(sql, companyId).Find(&User)就不会报错
查了下源码,FindAndCount函数会在最后调用
return session.Count(reflect.New(sliceElementType).Interface())
这个函数会导致报错
另外,返回行数为什么要再次执行一次Count函数?,直接返回slice的长度不就可以了

```go type User struct{ name string .... } engine.Sql(sql, companyId).FindAndCount(&User) ``` 这样调用会报sql: expected 8 destination arguments in Scan, not 1 但是engine.Sql(sql, companyId).Find(&User)就不会报错 查了下源码,FindAndCount函数会在最后调用 return session.Count(reflect.New(sliceElementType).Interface()) 这个函数会导致报错 另外,返回行数为什么要再次执行一次Count函数?,直接返回slice的长度不就可以了
Owner

The cound is the records number ignored limit. It's not equal to length of slice. You can just use Find.

The cound is the records number ignored limit. It's not equal to length of slice. You can just use `Find`.
Author

OK. I think the comment on the function of "findandcount" should be modified. It should be the total number of the records.
By the way, this function still does not work currently.

OK. I think the comment on the function of "findandcount" should be modified. It should be the total number of the records. By the way, this function still does not work currently.
lunny added the
kind
bug
label 2020-02-29 09:27:54 +00:00
lunny added this to the 1.1.1 milestone 2020-03-06 08:56:47 +00:00
lunny added
wontfix
and removed
kind
bug
labels 2020-03-23 12:33:05 +00:00
lunny removed this from the 1.1.1 milestone 2020-03-23 12:33:09 +00:00
Owner

The usage will not be supported. engine.SQL().FindAndCount.

The usage will not be supported. `engine.SQL().FindAndCount`.
lunny closed this issue 2020-03-23 12:33:33 +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#1483
No description provided.