@@ -19,6 +19,12 @@ class DB2Grammar extends Grammar
1919 */
2020 protected $ dateFormat ;
2121
22+ /**
23+ * Offset compatibility mode true triggers FETCH FIRST X ROWS and ROW_NUM behavior for older versions of DB2
24+ * @var bool
25+ */
26+ protected $ offsetCompatibilityMode = true ;
27+
2228 /**
2329 * Wrap a single string in keyword identifiers.
2430 *
@@ -45,7 +51,10 @@ protected function wrapValue($value)
4551 */
4652 protected function compileLimit (Builder $ query , $ limit )
4753 {
48- return "FETCH FIRST $ limit ROWS ONLY " ;
54+ if ($ this ->offsetCompatibilityMode ){
55+ return "FETCH FIRST $ limit ROWS ONLY " ;
56+ }
57+ return parent ::compileLimit ($ query , $ limit );
4958 }
5059
5160 /**
@@ -57,6 +66,10 @@ protected function compileLimit(Builder $query, $limit)
5766 */
5867 public function compileSelect (Builder $ query )
5968 {
69+ if (!$ this ->offsetCompatibilityMode ){
70+ return parent ::compileSelect ($ query );
71+ }
72+
6073 if (is_null ($ query ->columns )) {
6174 $ query ->columns = ['* ' ];
6275 }
@@ -183,7 +196,10 @@ protected function compileTableExpression($sql, $constraint)
183196 */
184197 protected function compileOffset (Builder $ query , $ offset )
185198 {
186- return '' ;
199+ if ($ this ->offsetCompatibilityMode ){
200+ return '' ;
201+ }
202+ return parent ::compileOffset ($ query , $ offset );
187203 }
188204
189205 /**
@@ -221,6 +237,16 @@ public function setDateFormat($dateFormat)
221237 $ this ->dateFormat = $ dateFormat ;
222238 }
223239
240+ /**
241+ * Set offset compatibility mode to trigger FETCH FIRST X ROWS and ROW_NUM behavior for older versions of DB2
242+ *
243+ * @param $bool
244+ */
245+ public function setOffsetCompatibilityMode ($ bool )
246+ {
247+ $ this ->offsetCompatibilityMode = $ bool ;
248+ }
249+
224250 /**
225251 * Compile the SQL statement to define a savepoint.
226252 *
0 commit comments