projects
/
datasette-pytables.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
fd6cd6a
)
Check limit to return the appropiate number of rows
author
Javier Sancho
<jsf@jsancho.org>
Wed, 16 May 2018 10:14:45 +0000
(12:14 +0200)
committer
Javier Sancho
<jsf@jsancho.org>
Wed, 16 May 2018 10:14:45 +0000
(12:14 +0200)
datasette_pytables/__init__.py
patch
|
blob
|
history
diff --git
a/datasette_pytables/__init__.py
b/datasette_pytables/__init__.py
index 50628e7848ae704859bc41300b3f4c71f5531821..b857ee179bb744a1e64dca0fa09834fb8ee35b53 100644
(file)
--- a/
datasette_pytables/__init__.py
+++ b/
datasette_pytables/__init__.py
@@
-97,11
+97,12
@@
class Connection:
table_rows = []
fields = parsed_sql['select'].split(',')
table_rows = []
fields = parsed_sql['select'].split(',')
+ query = ''
+ start = 0
+ end = table.nrows
+
# Use 'where' statement or get all the rows
if 'where' in parsed_sql:
# Use 'where' statement or get all the rows
if 'where' in parsed_sql:
- query = ''
- start = 0
- end = table.nrows
try:
conditions = []
for condition in parsed_sql['where'].get_sublists():
try:
conditions = []
for condition in parsed_sql['where'].get_sublists():
@@
-118,12
+119,17
@@
class Connection:
# Probably it's a PyTables query
query = str(parsed_sql['where'])[6:] # without where keyword
# Probably it's a PyTables query
query = str(parsed_sql['where'])[6:] # without where keyword
- if query:
- table_rows = table.where(query, params, start, end)
- else:
- table_rows = table.iterrows(start, end)
+ # Limit number of rows
+ if 'limit' in parsed_sql:
+ max_rows = int(parsed_sql['limit'])
+ if end - start > max_rows:
+ end = start + max_rows
+
+ # Execute query
+ if query:
+ table_rows = table.where(query, params, start, end)
else:
else:
- table_rows = table.iterrows()
+ table_rows = table.iterrows(
start, end
)
# Prepare rows
if len(fields) == 1 and fields[0] == 'count(*)':
# Prepare rows
if len(fields) == 1 and fields[0] == 'count(*)':