@@ -6,7 +6,6 @@ package sqlbuilder
66import (
77 "fmt"
88 "reflect"
9- "strings"
109
1110 "github.com/huandu/go-clone"
1211)
@@ -374,8 +373,6 @@ func (sb *SelectBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
374373 buf := newStringBuilder ()
375374 sb .injection .WriteTo (buf , selectMarkerInit )
376375
377- oraclePage := flavor == Oracle && (len (sb .limitVar ) > 0 || len (sb .offsetVar ) > 0 )
378-
379376 if sb .cteBuilderVar != "" {
380377 buf .WriteLeadingString (sb .cteBuilderVar )
381378 sb .injection .WriteTo (buf , selectMarkerAfterWith )
@@ -388,51 +385,11 @@ func (sb *SelectBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
388385 buf .WriteString ("DISTINCT " )
389386 }
390387
391- if oraclePage {
392- var selectCols = make ([]string , 0 , len (sb .selectCols ))
393- for i := range sb .selectCols {
394- cols := strings .SplitN (sb .selectCols [i ], "." , 2 )
395-
396- if len (cols ) == 1 {
397- selectCols = append (selectCols , cols [0 ])
398- } else {
399- selectCols = append (selectCols , cols [1 ])
400- }
401- }
402- buf .WriteStrings (selectCols , ", " )
403- } else {
404- buf .WriteStrings (sb .selectCols , ", " )
405- }
388+ buf .WriteStrings (sb .selectCols , ", " )
406389 }
407390
408391 sb .injection .WriteTo (buf , selectMarkerAfterSelect )
409392
410- if oraclePage {
411- if len (sb .selectCols ) > 0 {
412- buf .WriteLeadingString ("FROM (SELECT " )
413-
414- if sb .distinct {
415- buf .WriteString ("DISTINCT " )
416- }
417-
418- var selectCols = make ([]string , 0 , len (sb .selectCols )+ 1 )
419- selectCols = append (selectCols , "ROWNUM r" )
420-
421- for i := range sb .selectCols {
422- cols := strings .SplitN (sb .selectCols [i ], "." , 2 )
423- if len (cols ) == 1 {
424- selectCols = append (selectCols , cols [0 ])
425- } else {
426- selectCols = append (selectCols , cols [1 ])
427- }
428- }
429-
430- buf .WriteStrings (selectCols , ", " )
431- buf .WriteLeadingString ("FROM (SELECT " )
432- buf .WriteStrings (sb .selectCols , ", " )
433- }
434- }
435-
436393 tableNames := sb .TableNames ()
437394
438395 if len (tableNames ) > 0 {
@@ -562,34 +519,20 @@ func (sb *SelectBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
562519 }
563520
564521 case Oracle :
565- if oraclePage {
566- buf .WriteString (") " )
522+ if len (sb .offsetVar ) > 0 {
523+ buf .WriteLeadingString ("OFFSET " )
524+ buf .WriteString (sb .offsetVar )
525+ buf .WriteString (" ROWS" )
526+ }
567527
568- if len (sb .tables ) > 0 {
569- buf .WriteStrings (sb .tables , ", " )
528+ if len (sb .limitVar ) > 0 {
529+ if len (sb .offsetVar ) == 0 {
530+ buf .WriteLeadingString ("OFFSET 0 ROWS" )
570531 }
571532
572- buf .WriteString (") WHERE " )
573-
574- if len (sb .limitVar ) > 0 {
575- buf .WriteString ("r BETWEEN " )
576-
577- if len (sb .offsetVar ) > 0 {
578- buf .WriteString (sb .offsetVar )
579- buf .WriteString (" + 1 AND " )
580- buf .WriteString (sb .limitVar )
581- buf .WriteString (" + " )
582- buf .WriteString (sb .offsetVar )
583- } else {
584- buf .WriteString ("1 AND " )
585- buf .WriteString (sb .limitVar )
586- }
587- } else {
588- // As oraclePage is true, sb.offsetVar must not be empty.
589- buf .WriteString ("r >= " )
590- buf .WriteString (sb .offsetVar )
591- buf .WriteString (" + 1" )
592- }
533+ buf .WriteLeadingString ("FETCH NEXT " )
534+ buf .WriteString (sb .limitVar )
535+ buf .WriteString (" ROWS ONLY" )
593536 }
594537
595538 case Informix :
0 commit comments