Skip to content

Commit 772fef4

Browse files
committed
Meta data stored as key/value
1 parent 784e647 commit 772fef4

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

coverage/sqldata.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
os = isolate_module(os)
2929

30-
SCHEMA_VERSION = 5
30+
SCHEMA_VERSION = 6
3131

3232
SCHEMA = """
3333
CREATE TABLE coverage_schema (
@@ -39,27 +39,31 @@
3939
-- 3: Replaced line table with line_map table.
4040
-- 4: Changed line_map.bitmap to line_map.numbits.
4141
-- 5: Added foreign key declarations.
42+
-- 6: Key-value in meta.
4243
);
4344
4445
CREATE TABLE meta (
45-
-- One row, to record some metadata about the data
46-
has_lines boolean, -- Is this data recording lines?
47-
has_arcs boolean, -- .. or branches?
48-
sys_argv text -- The coverage command line that recorded the data.
46+
-- Key-value pairs, to record metadata about the data
47+
key text,
48+
value text,
49+
unique (key)
50+
-- Keys:
51+
-- 'has_arcs' boolean -- Is this data recording branches?
52+
-- 'sys_argv' text -- The coverage command line that recorded the data.
4953
);
5054
5155
CREATE TABLE file (
5256
-- A row per file measured.
5357
id integer primary key,
5458
path text,
55-
unique(path)
59+
unique (path)
5660
);
5761
5862
CREATE TABLE context (
5963
-- A row per context measured.
6064
id integer primary key,
6165
context text,
62-
unique(context)
66+
unique (context)
6367
);
6468
6569
CREATE TABLE line_map (
@@ -69,7 +73,7 @@
6973
numbits blob, -- see the numbits functions in coverage.numbits
7074
foreign key (file_id) references file (id),
7175
foreign key (context_id) references context (id),
72-
unique(file_id, context_id)
76+
unique (file_id, context_id)
7377
);
7478
7579
CREATE TABLE arc (
@@ -80,7 +84,7 @@
8084
tono integer, -- line number jumped to.
8185
foreign key (file_id) references file (id),
8286
foreign key (context_id) references context (id),
83-
unique(file_id, context_id, fromno, tono)
87+
unique (file_id, context_id, fromno, tono)
8488
);
8589
8690
CREATE TABLE tracer (
@@ -226,8 +230,8 @@ def _create_db(self):
226230
db.executescript(SCHEMA)
227231
db.execute("insert into coverage_schema (version) values (?)", (SCHEMA_VERSION,))
228232
db.execute(
229-
"insert into meta (has_lines, has_arcs, sys_argv) values (?, ?, ?)",
230-
(self._has_lines, self._has_arcs, str(getattr(sys, 'argv', None)))
233+
"insert into meta (key, value) values (?, ?)",
234+
('sys_argv', str(getattr(sys, 'argv', None)))
231235
)
232236

233237
def _open_db(self):
@@ -254,8 +258,9 @@ def _read_db(self):
254258
)
255259
)
256260

257-
for row in db.execute("select has_lines, has_arcs from meta"):
258-
self._has_lines, self._has_arcs = row
261+
for row in db.execute("select value from meta where key = 'has_arcs'"):
262+
self._has_arcs = bool(int(row[0]))
263+
self._has_lines = not self._has_arcs
259264

260265
for path, id in db.execute("select path, id from file"):
261266
self._file_map[path] = id
@@ -419,7 +424,10 @@ def _choose_lines_or_arcs(self, lines=False, arcs=False):
419424
self._has_lines = lines
420425
self._has_arcs = arcs
421426
with self._connect() as con:
422-
con.execute("update meta set has_lines = ?, has_arcs = ?", (lines, arcs))
427+
con.execute(
428+
"insert into meta (key, value) values (?, ?)",
429+
('has_arcs', str(int(arcs)))
430+
)
423431

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

0 commit comments

Comments
 (0)