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
(self, sql, params, raw=True, output=False)
| 276 | ## Methods for retrieving history: |
| 277 | ## ------------------------------- |
| 278 | def _run_sql(self, sql, params, raw=True, output=False): |
| 279 | """Prepares and runs an SQL query for the history database. |
| 280 | |
| 281 | Parameters |
| 282 | ---------- |
| 283 | sql : str |
| 284 | Any filtering expressions to go after SELECT ... FROM ... |
| 285 | params : tuple |
| 286 | Parameters passed to the SQL query (to replace "?") |
| 287 | raw, output : bool |
| 288 | See :meth:`get_range` |
| 289 | |
| 290 | Returns |
| 291 | ------- |
| 292 | Tuples as :meth:`get_range` |
| 293 | """ |
| 294 | toget = 'source_raw' if raw else 'source' |
| 295 | sqlfrom = "history" |
| 296 | if output: |
| 297 | sqlfrom = "history LEFT JOIN output_history USING (session, line)" |
| 298 | toget = "history.%s, output_history.output" % toget |
| 299 | cur = self.db.execute("SELECT session, line, %s FROM %s " %\ |
| 300 | (toget, sqlfrom) + sql, params) |
| 301 | if output: # Regroup into 3-tuples, and parse JSON |
| 302 | return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur) |
| 303 | return cur |
| 304 | |
| 305 | @needs_sqlite |
| 306 | @catch_corrupt_db |