def _run_sql(self, sql, params, raw=True, output=False):
toget = '<STR_LIT>' if raw else '<STR_LIT:source>'<EOL>sqlfrom = "<STR_LIT>"<EOL>if output:<EOL><INDENT>sqlfrom = "<STR_LIT>"<EOL>toget = "<STR_LIT>" % toget<EOL><DEDENT>cur = self.db.execute("<STR_LIT>" %(toget, sqlfrom) + sql, params)<EOL>if output:    <EOL><INDENT>return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur)<EOL><DEDENT>return cur<EOL>
Prepares and runs an SQL query for the history database.

        Parameters
        ----------
        sql : str
          Any filtering expressions to go after SELECT ... FROM ...
        params : tuple
          Parameters passed to the SQL query (to replace "?")
        raw, output : bool
          See :meth:`get_range`

        Returns
        -------
        Tuples as :meth:`get_range`