-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the bug that ScanAndCount and AllAndCount report errors in sqlserver #3155
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wlqe Please add associated unit testing case for this update in crontrib/drivers/mssql
: https://github.com/gogf/gf/blob/master/contrib/drivers/mssql/mssql_z_model_test.go
contrib/drivers/mssql/mssql_z_model_test.go新加的单元测试代码如下:(不知道怎么把新变动的文件加到这个pr中来,只好直接贴在这了,哪位老大辛苦把代码加到mssql_z_model_test.go文件中吧) func Test_Model_AllAndCount(t *testing.T) {
} func Test_Model_ScanAndCount(t *testing.T) {
} |
The newly added unit test code of contrib/drivers/mssql/mssql_z_model_test.go is as follows: (I don’t know how to add the newly changed files to this PR, so I have to paste it directly here. Who has worked hard to add the code to mssql_z_model_test. go file) func Test_Model_AllAndCount(t *testing.T) { gtest.C(t, func(t *gtest.T) { t.Assert(len(result), 3) func Test_Model_ScanAndCount(t *testing.T) { gtest.C(t, func(t *gtest.T) { users := make([]User, 0) err := db.Model(table).Order("id").Limit(0, 3).ScanAndCount(&users, &total, false) t.Assert(len(users), 3) |
在你pr的分支继续commit就会自动加到pr中。 |
If you continue to commit on the branch of your pr, it will be automatically added to the pr. |
@zcyc thanks. Resubmitted. |
AllAndCount and ScanAndCount throw errors in SQL Server environment when there is an orderby statement。
sql server 2022 statement:
drop table if exists demo
create table demo(recid int identity(1,1),txt varchar(100),primary key(recid))
insert into demo(txt)values('txt1'),('txt2'),('txt3')
select * from demo
example code:
import (
"fmt"
_ "github.com/gogf/gf/contrib/drivers/mssql/v2"
"github.com/gogf/gf/v2/database/gdb"
)
Error message:
SELECT COUNT(1) FROM demo ORDER BY recid: mssql: Column "demo.recid" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP By clause.