def dump_session_as_json(self, session_id):
        """Returns a JSON string representing the list of SQL or BQL entries
        (e.g.  queries) executed within session `session_id`."""
        if session_id > self.session_id or session_id < 1:
            raise ValueError('No such session (%d)' % session_id)
        version = cursor_value(self._sql('''
            SELECT version FROM bayesdb_session
                WHERE id = ?
        ''', (session_id,)))
        cursor = self._sql('''
            SELECT * FROM bayesdb_session_entries
                WHERE session_id = ?
                ORDER BY start_time DESC
        ''', (session_id,))
        # XXX Get the description first because apsw cursors, for
        # whatever reason, don't let you get the description after
        # you've gotten all the results.
        # (see also bql.py BayesDBCursor.__init__)
        fields = []
        try:
            fields = [d[0] for d in cursor.description]
        except apsw.ExecutionCompleteError:
            pass # Probably no rows.
        entries = cursor.fetchall()
        session = {
            'entries': entries,
            'fields': fields,
            'version': version,
        }
        return json.dumps(session, sort_keys=True)
dataset/ETHPy150Open probcomp/bayeslite/src/sessions.py/SessionOrchestrator.dump_session_as_json/original