mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
fix bug
This commit is contained in:
+1
-1
@@ -224,7 +224,7 @@ func ExampleInsertBuilder_subSelect_informix() {
|
||||
fmt.Println(args)
|
||||
|
||||
// Output:
|
||||
// INSERT INTO demo.user (id, name) SELECT id, name FROM demo.test WHERE id = :1
|
||||
// INSERT INTO demo.user (id, name) SELECT id, name FROM demo.test WHERE id = ?
|
||||
// [1]
|
||||
}
|
||||
|
||||
|
||||
@@ -247,6 +247,24 @@ func (sb *SelectBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
|
||||
if len(sb.selectCols) > 0 {
|
||||
buf.WriteLeadingString("SELECT ")
|
||||
|
||||
if flavor == Informix {
|
||||
if sb.offset >= 0 {
|
||||
buf.WriteString("SKIP ")
|
||||
buf.WriteString(strconv.Itoa(sb.offset))
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
|
||||
if sb.limit > 0 {
|
||||
if sb.offset < 0 {
|
||||
buf.WriteString("SKIP 0 ")
|
||||
}
|
||||
|
||||
buf.WriteString("FIRST ")
|
||||
buf.WriteString(strconv.Itoa(sb.limit))
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
}
|
||||
|
||||
if sb.distinct {
|
||||
buf.WriteString("DISTINCT ")
|
||||
}
|
||||
@@ -351,7 +369,7 @@ func (sb *SelectBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
|
||||
}
|
||||
|
||||
switch flavor {
|
||||
case MySQL, SQLite, ClickHouse, Informix:
|
||||
case MySQL, SQLite, ClickHouse:
|
||||
if sb.limit >= 0 {
|
||||
buf.WriteLeadingString("LIMIT ")
|
||||
buf.WriteString(strconv.Itoa(sb.limit))
|
||||
@@ -423,6 +441,12 @@ func (sb *SelectBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
|
||||
buf.WriteString(strconv.Itoa(min + 1))
|
||||
}
|
||||
}
|
||||
case Informix:
|
||||
// If ORDER BY is not set, sort column #1 by default.
|
||||
// It's required to make OFFSET...FETCH work.
|
||||
if len(sb.orderByCols) == 0 && (sb.limit >= 0 || sb.offset >= 0) {
|
||||
buf.WriteLeadingString("ORDER BY 1")
|
||||
}
|
||||
}
|
||||
|
||||
if sb.limit >= 0 {
|
||||
|
||||
+4
-4
@@ -236,10 +236,10 @@ func ExampleSelectBuilder_limit_offset() {
|
||||
//
|
||||
// Informix
|
||||
// #1: SELECT * FROM user
|
||||
// #2: SELECT * FROM user
|
||||
// #3: SELECT * FROM user LIMIT 1 OFFSET 0
|
||||
// #4: SELECT * FROM user LIMIT 1
|
||||
// #5: SELECT * FROM user ORDER BY id LIMIT 1 OFFSET 1
|
||||
// #2: SELECT SKIP 0 * FROM user ORDER BY 1
|
||||
// #3: SELECT SKIP 0 FIRST 1 * FROM user ORDER BY 1
|
||||
// #4: SELECT SKIP 0 FIRST 1 * FROM user ORDER BY 1
|
||||
// #5: SELECT SKIP 1 FIRST 1 * FROM user ORDER BY id
|
||||
}
|
||||
|
||||
func ExampleSelectBuilder_ForUpdate() {
|
||||
|
||||
Reference in New Issue
Block a user