From: Javier Sancho Date: Fri, 30 Oct 2020 19:09:05 +0000 (+0100) Subject: Only tables have columns with types X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=commitdiff_plain;h=a408f0f468266f9b647e8572babda08fe9e0e09c Only tables have columns with types --- diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index c408773..9cb9005 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 @@ -266,7 +270,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: