
* let limit and offset use bind parameter * format * format limt_test * try again * fix test case fro connpool * adding driverName for postgres ,if not to do so, the stmt vars will be added a wrong one called pgx.QueryExecModeSimpleProtocol , causing the SQL with limit problem need 1 parameter ,but given two. * delete trunk files * restore the test_test.go * restore test_test.go * driver/postgres->v1.5.5 * change postgres version rollback to 1.5.4 --------- Co-authored-by: chenchuan <chenchuan@360.cn> Co-authored-by: jason_chuan <jason_chuan@126.com>
47 lines
942 B
Go
47 lines
942 B
Go
package clause
|
|
|
|
// Limit limit clause
|
|
type Limit struct {
|
|
Limit *int
|
|
Offset int
|
|
}
|
|
|
|
// Name where clause name
|
|
func (limit Limit) Name() string {
|
|
return "LIMIT"
|
|
}
|
|
|
|
// Build build where clause
|
|
func (limit Limit) Build(builder Builder) {
|
|
if limit.Limit != nil && *limit.Limit >= 0 {
|
|
builder.WriteString("LIMIT ")
|
|
builder.AddVar(builder, *limit.Limit)
|
|
}
|
|
if limit.Offset > 0 {
|
|
if limit.Limit != nil && *limit.Limit >= 0 {
|
|
builder.WriteByte(' ')
|
|
}
|
|
builder.WriteString("OFFSET ")
|
|
builder.AddVar(builder, limit.Offset)
|
|
}
|
|
}
|
|
|
|
// MergeClause merge order by clauses
|
|
func (limit Limit) MergeClause(clause *Clause) {
|
|
clause.Name = ""
|
|
|
|
if v, ok := clause.Expression.(Limit); ok {
|
|
if (limit.Limit == nil || *limit.Limit == 0) && v.Limit != nil {
|
|
limit.Limit = v.Limit
|
|
}
|
|
|
|
if limit.Offset == 0 && v.Offset > 0 {
|
|
limit.Offset = v.Offset
|
|
} else if limit.Offset < 0 {
|
|
limit.Offset = 0
|
|
}
|
|
}
|
|
|
|
clause.Expression = limit
|
|
}
|