Skip to content

Commit

Permalink
feature: add deprecation warning for fetch_next
Browse files Browse the repository at this point in the history
  • Loading branch information
danielenricocahall committed Jan 6, 2024
1 parent a6c8b35 commit 05e89eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pypika/dialects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itertools
import warnings
from copy import copy
from typing import Any, Optional, Union, Tuple as TypedTuple

Expand Down Expand Up @@ -354,6 +355,11 @@ def _limit_sql(self) -> str:
def _offset_sql(self) -> str:
return " OFFSET {offset} ROWS".format(offset=self._offset or 0)

@builder
def fetch_next(self, limit: int):
warnings.warn("`fetch_next` is deprecated - please use the `limit` method", DeprecationWarning)
self._limit = limit


class OracleQuery(Query):
"""
Expand Down
8 changes: 8 additions & 0 deletions pypika/tests/dialects/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ def test_limit_offset_query(self):
q = OracleQuery.from_(t).select(t.test).limit(limit).offset(offset)

self.assertEqual(f'SELECT test FROM table1 OFFSET {offset} ROWS FETCH NEXT {limit} ROWS ONLY', str(q))

def test_fetch_next_method_deprecated(self):
with self.assertWarns(DeprecationWarning):
t = Table('table1')
limit = 5
q = OracleQuery.from_(t).select(t.test).fetch_next(limit)

self.assertEqual(f'SELECT test FROM table1 FETCH NEXT {limit} ROWS ONLY', str(q))

0 comments on commit 05e89eb

Please sign in to comment.