diff -r 25f42e208e08 -r f8b97639deb5 eric6/DebugClients/Python/coverage/sqldata.py --- a/eric6/DebugClients/Python/coverage/sqldata.py Tue Sep 15 19:09:05 2020 +0200 +++ b/eric6/DebugClients/Python/coverage/sqldata.py Thu Sep 17 19:10:36 2020 +0200 @@ -268,7 +268,7 @@ """Read the metadata from a database so that we are ready to use it.""" with self._dbs[get_thread_id()] as db: try: - schema_version, = db.execute("select version from coverage_schema").fetchone() + schema_version, = db.execute_one("select version from coverage_schema") except Exception as exc: raise CoverageException( "Data file {!r} doesn't seem to be a coverage data file: {}".format( @@ -374,7 +374,7 @@ assert context is not None self._start_using() with self._connect() as con: - row = con.execute("select id from context where context = ?", (context,)).fetchone() + row = con.execute_one("select id from context where context = ?", (context,)) if row is not None: return row[0] else: @@ -789,7 +789,7 @@ file_id = self._file_id(filename) if file_id is None: return None - row = con.execute("select tracer from tracer where file_id = ?", (file_id,)).fetchone() + row = con.execute_one("select tracer from tracer where file_id = ?", (file_id,)) if row is not None: return row[0] or "" return "" # File was measured, but no tracer associated. @@ -952,11 +952,13 @@ """ with SqliteDb(":memory:", debug=NoDebugging()) as db: + temp_store = [row[0] for row in db.execute("pragma temp_store")] compile_options = [row[0] for row in db.execute("pragma compile_options")] return [ ('sqlite3_version', sqlite3.version), ('sqlite3_sqlite_version', sqlite3.sqlite_version), + ('sqlite3_temp_store', temp_store), ('sqlite3_compile_options', compile_options), ] @@ -1062,6 +1064,23 @@ self.debug.write("EXCEPTION from execute: {}".format(msg)) raise CoverageException("Couldn't use data file {!r}: {}".format(self.filename, msg)) + def execute_one(self, sql, parameters=()): + """Execute a statement and return the one row that results. + + This is like execute(sql, parameters).fetchone(), except it is + correct in reading the entire result set. This will raise an + exception if more than one row results. + + Returns a row, or None if there were no rows. + """ + rows = list(self.execute(sql, parameters)) + if len(rows) == 0: + return None + elif len(rows) == 1: + return rows[0] + else: + raise CoverageException("Sql {!r} shouldn't return {} rows".format(sql, len(rows))) + def executemany(self, sql, data): """Same as :meth:`python:sqlite3.Connection.executemany`.""" if self.debug: