+ if type(table) is tables.table.Table:
+ count = 0
+ for table_row in table_rows:
+ count += 1
+ if limit and count > limit:
+ break
+ if truncate and max_returned_rows and count > max_returned_rows:
+ truncated = True
+ break
+ row = Row()
+ for field in fields:
+ field_name = field['value']
+ if type(field_name) is dict and 'distinct' in field_name:
+ field_name = field_name['distinct']
+ if field_name == 'rowid':
+ row['rowid'] = int(table_row.nrow)
+ elif field_name == '*':
+ for col in table.colnames:
+ value = table_row[col]
+ if type(value) is bytes:
+ value = value.decode('utf-8')
+ row[col] = value
+ else:
+ row[field_name] = table_row[field_name]
+ rows.append(row)
+ else:
+ # Any kind of array
+ rowid = start - 1
+ count = 0
+ for table_row in table_rows:
+ count += 1
+ if limit and count > limit:
+ break
+ if truncate and max_returned_rows and count > max_returned_rows:
+ truncated = True
+ break
+ row = Row()
+ rowid += 1
+ for field in fields:
+ field_name = field['value']
+ if type(field_name) is dict and 'distinct' in field_name:
+ field_name = field_name['distinct']
+ if field_name == 'rowid':
+ row['rowid'] = rowid
+ else:
+ value = table_row
+ if type(value) is bytes:
+ value = value.decode('utf-8')
+ row['value'] = value
+ rows.append(row)
+
+ # Prepare query description
+ for field in [f['value'] for f in fields]:
+ if field == '*':
+ if type(table) is tables.table.Table:
+ for col in table.colnames:
+ description.append((col,))
+ else:
+ description.append(('value',))
+ else:
+ description.append((field,))
+
+ # Return the rows
+ return rows, truncated, tuple(description)
+
+ 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'])