def __queryItemsByParseTree(self, query_tree, limit, page, order_by):
        order_by_1 = ""
        order_by_2 = ""
        for col, direction in order_by:
            if order_by_1:
                order_by_1 += ", "
            if order_by_2:
                order_by_2 += ", "
            order_by_2 += col + " " + direction + " "
            if col == "title":
                order_by_1 += col + " " + direction + " "
        if order_by_1:
            order_by_1 = " ORDER BY " + order_by_1
        if order_by_2:
            order_by_2 = " ORDER BY " + order_by_2


        sub_sql = query_tree.interpret()

        if page < 1:
            raise ValueError("Page number cannot be negative or zero.")

        if limit < 0:
            raise ValueError("Limit cannot be negative number.")

        limit_offset = ""
        if limit > 0:
            offset = (page-1)*limit
            limit_offset += "LIMIT {0} OFFSET {1}".format(limit, offset)

        sql = '''
        select sub.*,
        ''' + db.Item_Tag._sql_from() + ''',
        ''' + db.Tag._sql_from() + ''',
        ''' + db.Thumbnail._sql_from() + ''',
        ''' + db.Item_Field._sql_from() + ''',
        ''' + db.Field._sql_from() + '''
        from (''' + sub_sql + " " + order_by_1 + " " + limit_offset +  ''') as sub
        left join items_tags on sub.id = items_tags.item_id
        left join tags on tags.id = items_tags.tag_id
        left join items_fields on sub.id = items_fields.item_id
        left join fields on fields.id = items_fields.field_id
        left join thumbnails on thumbnails.data_ref_id = sub.data_refs_id and
                  thumbnails.size = ''' + str(UserConfig().get("thumbnail_size",
                                                               consts.THUMBNAIL_DEFAULT_SIZE)) + '''
        where sub.alive
        ''' + order_by_2

        items = []
        try:
            items = self._session.query(db.Item)\
            .options(contains_eager("data_ref"), \
                     contains_eager("data_ref.thumbnails"), \
                     contains_eager("item_tags"), \
                     contains_eager("item_tags.tag"), \
                     contains_eager("item_fields"),\
                     contains_eager("item_fields.field"))\
            .from_statement(sql).all()

            for item in items:
                self._session.expunge(item)

        except ResourceClosedError:
            pass

        return items