db_test: don't verify SQLite issued error messages, they might change
A user on openbsc@ complained that with SQLite 3.8.2, the db_test fails with
--- expected
+++ stderr
-DDB (2067) abort at 18 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
+DDB (2067) abort at 35 in [INSERT INTO subscriber (imsi) VALUES ($imsi)]: UNIQUE constraint failed: subscriber.imsi
i.e. a trivial difference in the error message issued by SQLite.
For db_test, don't output any SQLite error messages: Add argument
enable_sqlite_logging, pass as true, except in db_test.c.
Remove the SQLite error messages from expected output.
(Note that there is a src/db_test.c program that's not of interest here, this
is about the tests/db/db_test.c)
Change-Id: I2513d71cc0072aef8d08f47d0a1959f311176229
diff --git a/src/db.c b/src/db.c
index d16f8ec..cc06ee6 100644
--- a/src/db.c
+++ b/src/db.c
@@ -211,7 +211,7 @@
return 0;
}
-struct db_context *db_open(void *ctx, const char *fname)
+struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logging)
{
struct db_context *dbc = talloc_zero(ctx, struct db_context);
unsigned int i;
@@ -233,9 +233,11 @@
has_sqlite_config_sqllog = true;
}
- rc = sqlite3_config(SQLITE_CONFIG_LOG, sql3_error_log_cb, NULL);
- if (rc != SQLITE_OK)
- LOGP(DDB, LOGL_NOTICE, "Unable to set SQLite3 error log callback\n");
+ if (enable_sqlite_logging) {
+ rc = sqlite3_config(SQLITE_CONFIG_LOG, sql3_error_log_cb, NULL);
+ if (rc != SQLITE_OK)
+ LOGP(DDB, LOGL_NOTICE, "Unable to set SQLite3 error log callback\n");
+ }
if (has_sqlite_config_sqllog) {
rc = sqlite3_config(SQLITE_CONFIG_SQLLOG, sql3_sql_log_cb, NULL);
diff --git a/src/db.h b/src/db.h
index fc8e511..92fdac4 100644
--- a/src/db.h
+++ b/src/db.h
@@ -38,7 +38,7 @@
bool db_bind_int(sqlite3_stmt *stmt, const char *param_name, int nr);
bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr);
void db_close(struct db_context *dbc);
-struct db_context *db_open(void *ctx, const char *fname);
+struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite3_logging);
#include <osmocom/crypt/auth.h>
diff --git a/src/db_test.c b/src/db_test.c
index 0e823f9..7891c90 100644
--- a/src/db_test.c
+++ b/src/db_test.c
@@ -62,7 +62,7 @@
exit(1);
}
- g_hlr->dbc = db_open(NULL, "hlr.db");
+ g_hlr->dbc = db_open(NULL, "hlr.db", true);
if (!g_hlr->dbc) {
LOGP(DMAIN, LOGL_ERROR, "Error opening database\n");
exit(1);
diff --git a/src/hlr.c b/src/hlr.c
index 78a7055..861597a 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -460,7 +460,7 @@
exit(1);
}
- g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file);
+ g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file, true);
if (!g_hlr->dbc) {
LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
exit(1);
diff --git a/src/hlr_db_tool.c b/src/hlr_db_tool.c
index d8a3584..318308c 100644
--- a/src/hlr_db_tool.c
+++ b/src/hlr_db_tool.c
@@ -409,7 +409,7 @@
exit(EXIT_FAILURE);
}
- g_hlr_db_tool_ctx->dbc = db_open(g_hlr_db_tool_ctx, cmdline_opts.db_file);
+ g_hlr_db_tool_ctx->dbc = db_open(g_hlr_db_tool_ctx, cmdline_opts.db_file, true);
if (!g_hlr_db_tool_ctx->dbc) {
LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
exit(EXIT_FAILURE);