From 6e8ac54ac9cc83d82ae2482dcec518a1f09991fa Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Fri, 25 May 2018 12:23:02 +0200 Subject: [PATCH] Use max_returned_rows in conjuction with page_size for truncating --- datasette_pytables/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index d9530ae..93cc1f0 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -71,7 +71,7 @@ class Connection: self.path = path self.h5file = tables.open_file(path) - def execute(self, sql, params=None, truncate=False, page_size=None): + def execute(self, sql, params=None, truncate=False, page_size=None, max_returned_rows=None): if params is None: params = {} rows = [] @@ -145,9 +145,11 @@ class Connection: end = start + max_rows # Truncate if needed - if page_size and truncate: - if end - start > page_size: - end = start + page_size + if page_size and max_returned_rows and truncate: + if max_returned_rows == page_size: + max_returned_rows += 1 + if end - start > max_returned_rows: + end = start + max_returned_rows truncated = True # Execute query -- 2.39.5