def create_values(connection, table, filter_): """Creates row values according to the given filter""" builder = QueryBuilder(connection, table, filter_=filter_.filter, limit=1, simplify=filter_.simplify) mapper = None keys = None if filter_.simplify: comment = create_comment(table, connection.comment(table.name), builder.counter, builder.aliases, None) keys = comment.display mapper = SimplifyMapper(table, comment=comment) result = connection.queryone(builder.build(), mapper) row = Row(table, result) logger.debug('Keys: %s', keys) if keys is None: keys = sorted(row.row.keys(), key=lambda key: '' if key == COMMENT_TITLE else tostring(key)) logger.debug('Keys: %s', keys) values = forward_references(row, table, keys, builder.aliases) values += back_references(row, table, builder.aliases) return values
def rows( self, connection, filter_=None, limit=DEFAULT_LIMIT, simplify=None): """Retrieves rows from the table with the given filter applied""" comment = None order = [] if simplify is None: simplify = False if simplify: comment = connection.comment(self.name) order = comment.order builder = QueryBuilder( connection, self, filter_=filter_, order=order, limit=limit, simplify=simplify) mapper = None if simplify: mapper = SimplifyMapper( self, comment=create_comment( self, comment, builder.counter, builder.aliases, None)) try: result = connection.queryall( builder.build(), mapper=mapper) except (DataError, ProgrammingError, UnknownColumnException, UnicodeEncodeError): # pragma: no cover raise except BaseException as e: # pragma: no cover logger.error(e, exc_info=1) # pragma: no cover import sys # pragma: no cover # pylint: disable=raising-non-exception raise type(e), type(e)( u'{} (check comment on table {})'.format(e.message, self.name) ), sys.exc_info()[2] # pragma: no cover return map(lambda row: Row(self, row), result)
def rows(self, connection, filter_=None, limit=DEFAULT_LIMIT, simplify=None): """Retrieves rows from the table with the given filter applied""" comment = None order = [] if simplify is None: simplify = False if simplify: comment = connection.comment(self.name) order = comment.order builder = QueryBuilder(connection, self, filter_=filter_, order=order, limit=limit, simplify=simplify) mapper = None if simplify: mapper = SimplifyMapper(self, comment=create_comment( self, comment, builder.counter, builder.aliases, None)) try: result = connection.queryall(builder.build(), mapper=mapper) except (DataError, ProgrammingError, UnknownColumnException, UnicodeEncodeError): # pragma: no cover raise except BaseException as e: # pragma: no cover logger.error(e, exc_info=1) # pragma: no cover import sys # pragma: no cover # pylint: disable=raising-non-exception raise type(e), type(e)(u'{} (check comment on table {})'.format( e.message, self.name)), sys.exc_info()[2] # pragma: no cover return map(lambda row: Row(self, row), result)
def create_values(connection, table, filter_): """Creates row values according to the given filter""" builder = QueryBuilder( connection, table, filter_=filter_.filter, limit=1, simplify=filter_.simplify) mapper = None keys = None if filter_.simplify: comment = create_comment( table, connection.comment(table.name), builder.counter, builder.aliases, None) keys = comment.display mapper = SimplifyMapper( table, comment=comment) result = connection.queryone( builder.build(), mapper) row = Row(table, result) logger.debug('Keys: %s', keys) if keys is None: keys = sorted( row.row.keys(), key=lambda key: '' if key == COMMENT_TITLE else tostring(key)) logger.debug('Keys: %s', keys) values = forward_references(row, table, keys, builder.aliases) values += back_references(row, table, builder.aliases) return values