From: Javier Sancho Date: Mon, 14 May 2018 10:18:39 +0000 (+0200) Subject: Resolve queries by rowid (nrow) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=b61c78ff44e9c719615cc6955c63cb732be55847;p=datasette-pytables.git Resolve queries by rowid (nrow) --- diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 3c71267..50180fd 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -43,6 +43,8 @@ def _parse_sql(sql): else: current_keyword = str(token) parsed_sql[current_keyword] = "" + elif type(token) is sqlparse.sql.Where: + parsed_sql['where'] = token else: if not token.is_whitespace: parsed_sql[current_keyword] += str(token) @@ -65,7 +67,17 @@ class Connection: # Use 'where' statement or get all the rows if 'where' in parsed_sql: - pass + query = '' + start = 0 + end = table.nrows + for condition in parsed_sql['where'].get_sublists(): + if str(condition) == '"rowid"=:p0': + start = int(params['p0']) + end = start + 1 + if query: + table_rows = table.where(query, start, end) + else: + table_rows = table.iterrows(start, end) else: table_rows = table.iterrows()