Skip to content

Commit

Permalink
Meta data stored as key/value
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Aug 6, 2019
1 parent 784e647 commit 772fef4
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions coverage/sqldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

os = isolate_module(os)

SCHEMA_VERSION = 5
SCHEMA_VERSION = 6

SCHEMA = """
CREATE TABLE coverage_schema (
Expand All @@ -39,27 +39,31 @@
-- 3: Replaced line table with line_map table.
-- 4: Changed line_map.bitmap to line_map.numbits.
-- 5: Added foreign key declarations.
-- 6: Key-value in meta.
);
CREATE TABLE meta (
-- One row, to record some metadata about the data
has_lines boolean, -- Is this data recording lines?
has_arcs boolean, -- .. or branches?
sys_argv text -- The coverage command line that recorded the data.
-- Key-value pairs, to record metadata about the data
key text,
value text,
unique (key)
-- Keys:
-- 'has_arcs' boolean -- Is this data recording branches?
-- 'sys_argv' text -- The coverage command line that recorded the data.
);
CREATE TABLE file (
-- A row per file measured.
id integer primary key,
path text,
unique(path)
unique (path)
);
CREATE TABLE context (
-- A row per context measured.
id integer primary key,
context text,
unique(context)
unique (context)
);
CREATE TABLE line_map (
Expand All @@ -69,7 +73,7 @@
numbits blob, -- see the numbits functions in coverage.numbits
foreign key (file_id) references file (id),
foreign key (context_id) references context (id),
unique(file_id, context_id)
unique (file_id, context_id)
);
CREATE TABLE arc (
Expand All @@ -80,7 +84,7 @@
tono integer, -- line number jumped to.
foreign key (file_id) references file (id),
foreign key (context_id) references context (id),
unique(file_id, context_id, fromno, tono)
unique (file_id, context_id, fromno, tono)
);
CREATE TABLE tracer (
Expand Down Expand Up @@ -226,8 +230,8 @@ def _create_db(self):
db.executescript(SCHEMA)
db.execute("insert into coverage_schema (version) values (?)", (SCHEMA_VERSION,))
db.execute(
"insert into meta (has_lines, has_arcs, sys_argv) values (?, ?, ?)",
(self._has_lines, self._has_arcs, str(getattr(sys, 'argv', None)))
"insert into meta (key, value) values (?, ?)",
('sys_argv', str(getattr(sys, 'argv', None)))
)

def _open_db(self):
Expand All @@ -254,8 +258,9 @@ def _read_db(self):
)
)

for row in db.execute("select has_lines, has_arcs from meta"):
self._has_lines, self._has_arcs = row
for row in db.execute("select value from meta where key = 'has_arcs'"):
self._has_arcs = bool(int(row[0]))
self._has_lines = not self._has_arcs

for path, id in db.execute("select path, id from file"):
self._file_map[path] = id
Expand Down Expand Up @@ -419,7 +424,10 @@ def _choose_lines_or_arcs(self, lines=False, arcs=False):
self._has_lines = lines
self._has_arcs = arcs
with self._connect() as con:
con.execute("update meta set has_lines = ?, has_arcs = ?", (lines, arcs))
con.execute(
"insert into meta (key, value) values (?, ?)",
('has_arcs', str(int(arcs)))
)

def add_file_tracers(self, file_tracers):
"""Add per-file plugin information.
Expand Down

0 comments on commit 772fef4

Please sign in to comment.