This commit is contained in:
maixl
2024-03-29 10:26:29 +08:00
parent 2d88cfe780
commit 8d52201d6a
3 changed files with 30 additions and 6 deletions
+1 -1
View File
@@ -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]
}
+25 -1
View File
@@ -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
View File
@@ -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() {