Add Mssql pagination feature with cte #825
No reviewers
Labels
No Label
backport/done
backport/v1
blocked
db
oracle
db
sqlserver
duplicate
feature
cache
frontport/done
frontport/main
invalid
kind
breaking
kind
bug
kind
build
kind
dependencies
kind
docs
kind
driver
kind
enhancement
kind
feature
kind
performance
kind
proposal
kind
question
kind
refactor
kind
testing
need
feedback
need
test
proposal:accepted
RaspBerry Pi
regression
skip-changelog
upstream
wip
wontfix
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: xorm/xorm#825
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "cantasci/added_mssql_pagination_feature"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
I want to make pagination with mssql. But offset feature is not working when page is greater than one.
So, I want to add this feature.
I use CTE(Common Table Expression) with related query for this problem.
WITH SQLPaging AS (SELECT TOP(%d) ROW_NUMBER() OVER (ORDER BY %v ASC) AS RN, %v FROM(%v) AS TEMP_TABLE_NAME)
I added getPrimaryColumnForOffset function
func (statement *Statement) getPrimaryColumnForOffset() string { var column string if len(statement.RefTable.PKColumns()) == 0 { for _, index := range statement.RefTable.Indexes { if len(index.Cols) == 1 { column = index.Cols[0] break } } if len(column) == 0 { column = statement.RefTable.ColumnsSeq()[0] } } else { column = statement.RefTable.PKColumns()[0].Name } return column }
Final query return filtered result by [start, start+limitN].
SELECT %v FROM SQLPaging WITH(NOLOCK) WHERE RN > %d AND RN < %d", columnStr, statement.Start, statement.Start+statement.LimitN+1) }
Thank you,
Codecov Report
63.88% <0%> (-1.41%)
77.77% <0%> (-0.09%)
Continue to review full report at Codecov.
outdated.
Pull request closed