X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=blobdiff_plain;f=datasette_pytables%2F__init__.py;h=889dccadbf9f4ad453022e9c7d6c5acdfa3bd430;hp=c4087730d24699c52968cb34b1de0955635b24a0;hb=8f981acbd074be2eec098253112f8ef479373a5e;hpb=d48ebf712918cb81ff6a6eae72ef053dd0b8ba6a diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index c408773..889dcca 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -118,12 +118,16 @@ class PyTablesConnector(dc.Connector): start = 0 end = table.nrows - # Use 'where' statement or get all the rows - def _cast_param(field, pname): - # Cast value to the column type + def _get_field_type(field): coltype = table.dtype.name if type(table) is tables.table.Table: coltype = table.coltypes[field] + return coltype + + # Use 'where' statement or get all the rows + def _cast_param(field, pname): + # Cast value to the column type + coltype = _get_field_type(field) fcast = None if coltype == 'string': fcast = str @@ -194,6 +198,11 @@ class PyTablesConnector(dc.Connector): if 'limit' in parsed_sql: limit = int(parsed_sql['limit']) + # Offset + offset = None + if 'offset' in parsed_sql: + offset = int(parsed_sql['offset']) + # Truncate if needed if page_size and max_returned_rows and truncate: if max_returned_rows == page_size: @@ -241,6 +250,8 @@ class PyTablesConnector(dc.Connector): # Get results get_rowid = make_get_rowid() get_row_value = make_get_row_value() + if offset: + table_rows = table_rows[offset:] count = 0 for table_row in table_rows: count += 1 @@ -266,7 +277,7 @@ class PyTablesConnector(dc.Connector): row['count(*)'] = int(table.nrows) elif field_name.get('json_type'): field_name = field_name.get('json_type') - row['json_type(' + field_name + ')'] = table.coltypes[field_name] + row['json_type(' + field_name + ')'] = _get_field_type(field) else: raise Exception("Function not recognized") else: