File tree Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ public function __toString() {
145
145
$ query = $ this ->buildGroups ($ query );
146
146
$ query = $ this ->buildHavingConditions ($ query );
147
147
$ query = $ this ->buildOrder ($ query );
148
- $ query = $ this ->buildLimit ($ query );
148
+ $ query = $ this ->buildLimit ($ query, $ this -> getOffset () );
149
149
$ query = $ this ->buildOffset ($ query );
150
150
$ query = $ this ->buildUnions ($ query );
151
151
$ query = $ this ->buildForUpdate ($ query );
Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ trait LimitBuilder {
5
5
/** @var int */
6
6
private $ limit = null ;
7
7
8
+ /**
9
+ * @return int
10
+ */
11
+ protected function getLimit () {
12
+ return $ this ->limit ;
13
+ }
14
+
8
15
/**
9
16
* @param int $limit
10
17
* @return $this
@@ -16,11 +23,16 @@ public function limit($limit) {
16
23
17
24
/**
18
25
* @param string $query
26
+ * @param null $offset
19
27
* @return string
20
28
*/
21
- protected function buildLimit ($ query ) {
22
- if ($ this ->limit !== null ) {
23
- $ query .= "LIMIT \n\t{$ this ->limit }\n" ;
29
+ protected function buildLimit ($ query , $ offset = null ) {
30
+ $ limit = $ this ->limit ;
31
+ if ($ limit === null && $ offset !== null ) {
32
+ $ limit = '18446744073709551615 ' ;
33
+ }
34
+ if ($ limit !== null ) {
35
+ $ query .= "LIMIT \n\t{$ limit }\n" ;
24
36
}
25
37
return $ query ;
26
38
}
Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ trait OffsetBuilder {
5
5
/** @var int */
6
6
private $ offset = null ;
7
7
8
+ /**
9
+ * @return int
10
+ */
11
+ protected function getOffset () {
12
+ return $ this ->offset ;
13
+ }
14
+
8
15
/**
9
16
* @param int $offset
10
17
* @return $this
Original file line number Diff line number Diff line change @@ -146,6 +146,15 @@ public function testOffset() {
146
146
$ this ->assertEquals ("SELECT \n\ta \nFROM \n\ttest t \nLIMIT \n\t100 \nOFFSET \n\t50 \n" , $ str );
147
147
}
148
148
149
+ public function testOffsetWithoutLimit () {
150
+ $ str = TestSelect::create ()
151
+ ->field ('a ' )
152
+ ->from ('t ' , 'test ' )
153
+ ->offset (50 )
154
+ ->asString ();
155
+ $ this ->assertEquals ("SELECT \n\ta \nFROM \n\ttest t \nLIMIT \n\t18446744073709551615 \nOFFSET \n\t50 \n" , $ str );
156
+ }
157
+
149
158
public function testForUpdate () {
150
159
$ str = TestSelect::create ()
151
160
->field ('a ' )
You can’t perform that action at this time.
0 commit comments