+ def execute(self, sql, params=None, truncate=False):
+ rows = []
+ truncated = False
+ description = []
+
+ parsed_sql = _parse_sql(sql)
+ table = self.h5file.get_node(parsed_sql['from'][1:-1])
+ table_rows = []
+ fields = parsed_sql['select'].split(',')
+
+ # Use 'where' statement or get all the rows
+ if 'where' in parsed_sql:
+ pass
+ else:
+ table_rows = table.iterrows()
+
+ if len(fields) == 1 and fields[0] == 'count(*)':
+ rows.append(Row({'count(*)': table.nrows}))
+ else:
+ for table_row in table_rows:
+ row = Row()
+ for field in fields:
+ if field == 'rowid':
+ row[field] = table_row.nrow
+ elif field == '*':
+ for col in table.colnames:
+ row[col] = table_row[col]
+ else:
+ row[field] = table_row[field]
+ rows.append(row)
+
+ description = ((col,) for col in table.colnames)
+
+ if truncate:
+ return rows, truncated, description
+ else:
+ return rows
+
+class Row(OrderedDict):
+ def __getitem__(self, label):
+ if type(label) is int:
+ return super(OrderedDict, self).__getitem__(list(self.keys())[label])