eric6/DebugClients/Python/coverage/sqldata.py

changeset 7975
7d493839a8fc
parent 7702
f8b97639deb5
--- a/eric6/DebugClients/Python/coverage/sqldata.py	Wed Jan 13 19:05:48 2021 +0100
+++ b/eric6/DebugClients/Python/coverage/sqldata.py	Wed Jan 13 19:07:20 2021 +0100
@@ -167,7 +167,8 @@
     To record data for contexts, use :meth:`set_context` to set a context to
     be used for subsequent :meth:`add_lines` and :meth:`add_arcs` calls.
 
-    To add a source file without any measured data, use :meth:`touch_file`.
+    To add a source file without any measured data, use :meth:`touch_file`,
+    or :meth:`touch_files` for a list of such files.
 
     Write the data to its file with :meth:`write`.
 
@@ -536,16 +537,26 @@
         `plugin_name` is the name of the plugin responsible for this file. It is used
         to associate the right filereporter, etc.
         """
+        self.touch_files([filename], plugin_name)
+
+    def touch_files(self, filenames, plugin_name=""):
+        """Ensure that `filenames` appear in the data, empty if needed.
+
+        `plugin_name` is the name of the plugin responsible for these files. It is used
+        to associate the right filereporter, etc.
+        """
         if self._debug.should('dataop'):
-            self._debug.write("Touching %r" % (filename,))
+            self._debug.write("Touching %r" % (filenames,))
         self._start_using()
-        if not self._has_arcs and not self._has_lines:
-            raise CoverageException("Can't touch files in an empty CoverageData")
+        with self._connect(): # Use this to get one transaction.
+            if not self._has_arcs and not self._has_lines:
+                raise CoverageException("Can't touch files in an empty CoverageData")
 
-        self._file_id(filename, add=True)
-        if plugin_name:
-            # Set the tracer for this file
-            self.add_file_tracers({filename: plugin_name})
+            for filename in filenames:
+                self._file_id(filename, add=True)
+                if plugin_name:
+                    # Set the tracer for this file
+                    self.add_file_tracers({filename: plugin_name})
 
     def update(self, other_data, aliases=None):
         """Update this data with data from several other :class:`CoverageData` instances.
@@ -1045,7 +1056,13 @@
             tail = " with {!r}".format(parameters) if parameters else ""
             self.debug.write("Executing {!r}{}".format(sql, tail))
         try:
-            return self.con.execute(sql, parameters)
+            try:
+                return self.con.execute(sql, parameters)
+            except Exception:
+                # In some cases, an error might happen that isn't really an
+                # error.  Try again immediately.
+                # https://github.com/nedbat/coveragepy/issues/1010
+                return self.con.execute(sql, parameters)
         except sqlite3.Error as exc:
             msg = str(exc)
             try:

eric ide

mercurial