X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=blobdiff_plain;f=datasette_pytables%2F__init__.py;h=b3d5b9a7d0ab3ec31eacf6bfe410169130fe094a;hp=93cc1f082fd6eef31e0250ef644080cf4474303c;hb=6cc3c0fa57c1155e9c76bf0c1b4ebfcc65772e12;hpb=6e8ac54ac9cc83d82ae2482dcec518a1f09991fa diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 93cc1f0..b3d5b9a 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -1,4 +1,3 @@ -from collections import OrderedDict from moz_sql_parser import parse import re import tables @@ -81,7 +80,9 @@ class Connection: parsed_sql = _parse_sql(sql, params) if parsed_sql['from'] == 'sqlite_master': - return self._execute_datasette_query(sql, params) + rows = self._execute_datasette_query(sql, params) + description = (('value',)) + return rows, truncated, description table = self.h5file.get_node(parsed_sql['from']) table_rows = [] @@ -94,7 +95,10 @@ class Connection: # Use 'where' statement or get all the rows def _cast_param(field, pname): # Cast value to the column type - coltype = table.coltypes[field] + if type(table) is tables.table.Table: + coltype = table.coltypes[field] + else: + coltype = table.dtype.name fcast = None if coltype == 'string': fcast = str @@ -107,6 +111,7 @@ class Connection: def _translate_where(where): # Translate SQL to PyTables expression + nonlocal start, end expr = '' operator = list(where)[0] @@ -118,9 +123,10 @@ class Connection: elif operator == 'exists': pass elif where == {'eq': ['rowid', 'p0']}: - nonlocal start, end start = int(params['p0']) end = start + 1 + elif where == {'gt': ['rowid', 'p0']}: + start = int(params['p0']) + 1 else: left, right = where[operator] if left in params: @@ -212,10 +218,7 @@ class Connection: description.append((field,)) # Return the rows - if truncate: - return rows, truncated, tuple(description) - else: - return rows + return rows, truncated, tuple(description) def _execute_datasette_query(self, sql, params): "Datasette special queries for getting tables info"