Skip to content
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

method "Page(page,limit)" generate paging sql is incorrect where database type is not mysql #3343

Closed
kim709394 opened this issue Mar 1, 2024 · 2 comments · Fixed by #3782
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. help wanted

Comments

@kim709394
Copy link

What version of Go and system type/arch are you using?
go 1.21.6, windows11/amd64

What version of GoFrame are you using?
2.6.3

Can this bug be re-produced with the latest release?
yes

What did you do?

// when i run these codes there is a bug happen
//my database is sql server , the method name "Page(page,linit)" generate sql of paging is by mysql , not sql server
// i tracked the source code line is 
/* LIMIT.
	if !isCountStatement {
		if m.limit != 0 {
			if m.start >= 0 {
				conditionExtra += fmt.Sprintf(" LIMIT %d,%d", m.start, m.limit)
			} else {
				conditionExtra += fmt.Sprintf(" LIMIT %d", m.limit)
			}
		} else if limit1 {
			conditionExtra += " LIMIT 1"
		}

		if m.offset >= 0 {
			conditionExtra += fmt.Sprintf(" OFFSET %d", m.offset)
		}
*/
/*of method name  "func (m *Model) formatCondition(
	ctx context.Context, limit1 bool, isCountStatement bool,
) (conditionWhere string, conditionExtra string, conditionArgs []interface{}) "
of file "gdb_model_select.go"  of "package gdb"
*/
model.OrderDesc("start_time").Page(req.PageNo, req.PageSize).ScanAndCount(&res.CarDistanceAlarms, &res.RecordCount, true)

What did you expect to see?
generate sql of paging should by current database type example sqlserver is "select * from student order by sno offset ((@pageIndex-1)*@pageSize) rows
fetch next @pageSize rows only;"

What did you see instead?
sql server database type generate sql of paging is "ORDER BY "start_time" DESC LIMIT 0,10" which is incorrect

@kim709394 kim709394 added the bug It is confirmed a bug, but don't worry, we'll handle it. label Mar 1, 2024
@gqcn
Copy link
Member

gqcn commented Sep 13, 2024

There might be some details here to be imoeved

func (d *Driver) parseSql(toBeCommittedSql string) (string, error) {
to support different paging statement.

Copy link

Hello @kim709394. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @kim709394。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants