Skip to content

Commit bc1d68c

Browse files
committed
fix parsing empty config JSON & regression test
1 parent 2e37481 commit bc1d68c

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

src/genomicsqlite.cc

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,24 @@ class ConfigParser {
8484
throw SQLite::Exception("GenomicSQLite::ConfigParser()::sqlite3_open_v2()", rc);
8585
}
8686

87-
// merge config_json into defaults
88-
if ((rc = sqlite3_prepare_v2(db_, "SELECT json_patch(?,?)", -1, &patch_, nullptr)) !=
89-
SQLITE_OK)
90-
throw SQLite::Exception(db_, rc);
91-
if ((rc = sqlite3_bind_text(patch_, 1, GenomicSQLiteDefaultConfigJSON().c_str(), -1,
92-
SQLITE_TRANSIENT)) != SQLITE_OK)
93-
throw SQLite::Exception(db_, rc);
94-
if ((rc = sqlite3_bind_text(patch_, 2, config_json.c_str(), -1, SQLITE_TRANSIENT)) !=
95-
SQLITE_OK)
96-
throw SQLite::Exception(db_, rc);
97-
const char *merged_config_json = nullptr;
98-
if ((rc = sqlite3_step(patch_)) != SQLITE_ROW ||
99-
!(merged_config_json = (const char *)sqlite3_column_text(patch_, 0)) ||
100-
merged_config_json[0] != '{') {
101-
throw SQLite::Exception("error parsing config JSON", rc);
87+
string default_json = GenomicSQLiteDefaultConfigJSON();
88+
const char *merged_config_json = default_json.c_str();
89+
if (config_json.size() > 2) { // "{}"
90+
// merge config_json into defaults
91+
if ((rc = sqlite3_prepare_v2(db_, "SELECT json_patch(?,?)", -1, &patch_, nullptr)) !=
92+
SQLITE_OK)
93+
throw SQLite::Exception(db_, rc);
94+
if ((rc = sqlite3_bind_text(patch_, 1, default_json.c_str(), -1, SQLITE_TRANSIENT)) !=
95+
SQLITE_OK)
96+
throw SQLite::Exception(db_, rc);
97+
if ((rc = sqlite3_bind_text(patch_, 2, config_json.c_str(), -1, SQLITE_TRANSIENT)) !=
98+
SQLITE_OK)
99+
throw SQLite::Exception(db_, rc);
100+
if ((rc = sqlite3_step(patch_)) != SQLITE_ROW ||
101+
!(merged_config_json = (const char *)sqlite3_column_text(patch_, 0)) ||
102+
merged_config_json[0] != '{') {
103+
throw SQLite::Exception("error parsing config JSON", rc);
104+
}
102105
}
103106

104107
if ((rc = sqlite3_prepare_v2(db_, "SELECT json_extract(?,?)", -1, &extract_, nullptr)) !=

test/genomicsqlite_big_tests.wdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ task build {
4242
4343
apt-get -qq update
4444
DEBIAN_FRONTEND=noninteractive apt-get -qq install -y \
45-
zip pigz wget build-essential git-core \
45+
zip pigz wget build-essential git-core sqlite3 \
4646
cmake libsqlite3-dev libzstd-dev \
4747
python3-pip maven cargo \
4848
libhts-dev samtools tabix

test/test_bam.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ def sam_into_sqlite(infilename, outfilename, *options):
1616
check=True,
1717
)
1818
print(outfilename)
19+
# test CLI
20+
cmd = (
21+
"python3",
22+
os.path.join(HERE, "../bindings/python/genomicsqlite/__init__.py"),
23+
outfilename,
24+
"-readonly",
25+
"SELECT * from sqlite_master",
26+
)
27+
print(" ".join(cmd))
28+
subprocess.run(
29+
cmd,
30+
check=True,
31+
)
1932

2033

2134
def test_bam(tmp_path):

0 commit comments

Comments
 (0)