else:
current_keyword = str(token)
parsed_sql[current_keyword] = ""
+ elif type(token) is sqlparse.sql.Where:
+ parsed_sql['where'] = token
else:
if not token.is_whitespace:
parsed_sql[current_keyword] += str(token)
# Use 'where' statement or get all the rows
if 'where' in parsed_sql:
- pass
+ query = ''
+ start = 0
+ end = table.nrows
+ for condition in parsed_sql['where'].get_sublists():
+ if str(condition) == '"rowid"=:p0':
+ start = int(params['p0'])
+ end = start + 1
+ if query:
+ table_rows = table.where(query, start, end)
+ else:
+ table_rows = table.iterrows(start, end)
else:
table_rows = table.iterrows()
+ # Prepare rows
if len(fields) == 1 and fields[0] == 'count(*)':
- rows.append(Row({'count(*)': table.nrows}))
+ rows.append(Row({fields[0]: table.nrows}))
else:
for table_row in table_rows:
row = Row()
row[field] = table_row.nrow
elif field == '*':
for col in table.colnames:
- row[col] = table_row[col]
+ value = table_row[col]
+ if type(value) is bytes:
+ value = value.decode('utf-8')
+ row[col] = value
else:
row[field] = table_row[field]
rows.append(row)
- description = ((col,) for col in table.colnames)
+ # Prepare query description
+ for field in fields:
+ if field == '*':
+ for col in table.colnames:
+ description.append((col,))
+ else:
+ description.append((field,))
if truncate:
- return rows, truncated, description
+ return rows, truncated, tuple(description)
else:
return rows
def __getitem__(self, label):
if type(label) is int:
return super(OrderedDict, self).__getitem__(list(self.keys())[label])
+ else:
+ return super(OrderedDict, self).__getitem__(label)
+
+ def __iter__(self):
+ return self.values().__iter__()