- # Return the rows
- if truncate:
- return rows, truncated, tuple(description)
- else:
- return rows
-
- def _execute_datasette_query(self, sql, params):
- "Datasette special queries for getting tables info"
- if sql == "SELECT count(*) from sqlite_master WHERE type = 'view' and name=:n":
- row = Row()
- row['count(*)'] = 0
- return [row]
- elif sql == 'select sql from sqlite_master where name = :n and type="table"':
- try:
- table = self.h5file.get_node(params['n'])
- row = Row()
- row['sql'] = 'CREATE TABLE {} ()'.format(params['n'])
- return [row]
- except:
- return []
- else:
- raise Exception("SQLite queries cannot be executed with this 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
+ if limit is not None and count > limit:
+ break
+ if truncate and max_returned_rows and count > max_returned_rows:
+ truncated = True
+ break
+ row = {}
+ for field in fields:
+ field_name = field
+ if isinstance(field, dict):
+ field_name = field['value']
+ if isinstance(field_name, dict) and 'distinct' in field_name:
+ field_name = field_name['distinct']
+ if field_name == 'rowid':
+ row['rowid'] = get_rowid(table_row)
+ elif field_name == '*':
+ for col in colnames:
+ row[col] = normalize_field_value(get_row_value(table_row, col))
+ elif isinstance(field_name, dict):
+ if field_name.get('count') == '*':
+ row['count(*)'] = int(table.nrows)
+ elif field_name.get('json_type'):
+ field_name = field_name.get('json_type')
+ row['json_type(' + field_name + ')'] = _get_field_type(field_name)
+ else:
+ raise Exception("Function not recognized")
+ else:
+ row[field_name] = normalize_field_value(get_row_value(table_row, field_name))
+ results.append(row)