From 472bb0733d6dcbf9d33fd0f56b030b9abd5c4566 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 21 Sep 2020 14:41:37 +0200 Subject: put SQL only used in hlr-db-tool in hlr_db_tool.c Change-Id: I3ac327dbcef37472fb13b8689d008e74b83b3bb1 --- include/osmocom/hlr/db.h | 1 - src/db.c | 1 - src/hlr_db_tool.c | 24 +++++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/osmocom/hlr/db.h b/include/osmocom/hlr/db.h index 176a097..ca336a0 100644 --- a/include/osmocom/hlr/db.h +++ b/include/osmocom/hlr/db.h @@ -33,7 +33,6 @@ enum stmt_idx { DB_STMT_SET_LAST_LU_SEEN_PS, DB_STMT_EXISTS_BY_IMSI, DB_STMT_EXISTS_BY_MSISDN, - DB_STMT_SET_IMPLICIT_LU_BY_IMSI, _NUM_DB_STMT }; diff --git a/src/db.c b/src/db.c index fb7c2d5..5ec20e2 100644 --- a/src/db.c +++ b/src/db.c @@ -85,7 +85,6 @@ static const char *stmt_sql[] = { [DB_STMT_SET_LAST_LU_SEEN_PS] = "UPDATE subscriber SET last_lu_seen_ps = datetime($val, 'unixepoch') WHERE id = $subscriber_id", [DB_STMT_EXISTS_BY_IMSI] = "SELECT 1 FROM subscriber WHERE imsi = $imsi", [DB_STMT_EXISTS_BY_MSISDN] = "SELECT 1 FROM subscriber WHERE msisdn = $msisdn", - [DB_STMT_SET_IMPLICIT_LU_BY_IMSI] = "UPDATE subscriber SET last_lu_seen = datetime($last_lu, 'unixepoch') WHERE imsi = $imsi", }; static void sql3_error_log_cb(void *arg, int err_code, const char *msg) diff --git a/src/hlr_db_tool.c b/src/hlr_db_tool.c index e9733a0..eb44744 100644 --- a/src/hlr_db_tool.c +++ b/src/hlr_db_tool.c @@ -230,6 +230,17 @@ static const char *nitb_stmt_sql[] = { sqlite3_stmt *nitb_stmt[ARRAY_SIZE(nitb_stmt_sql)] = {}; +enum hlr_db_stmt { + HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI, +}; + +static const char *hlr_db_stmt_sql[] = { + [HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI] = + "UPDATE subscriber SET last_lu_seen = datetime($last_lu, 'unixepoch') WHERE imsi = $imsi", +}; + +sqlite3_stmt *hlr_db_stmt[ARRAY_SIZE(hlr_db_stmt_sql)] = {}; + size_t _dbd_decode_binary(const unsigned char *in, unsigned char *out); /*! Set a subscriber's LU timestamp in the HLR database. @@ -246,7 +257,7 @@ int db_subscr_update_lu_by_imsi(struct db_context *dbc, const char* imsi, const { int rc, ret = 0; - sqlite3_stmt *stmt = dbc->stmt[DB_STMT_SET_IMPLICIT_LU_BY_IMSI]; + sqlite3_stmt *stmt = hlr_db_stmt[HLR_DB_STMT_SET_IMPLICIT_LU_BY_IMSI]; if (!db_bind_text(stmt, "$imsi", imsi)) return -EIO; @@ -424,6 +435,17 @@ int import_nitb_db(void) } } + for (i = 0; i < ARRAY_SIZE(hlr_db_stmt_sql); i++) { + sql = hlr_db_stmt_sql[i]; + rc = sqlite3_prepare_v2(g_hlr_db_tool_ctx->dbc->db, hlr_db_stmt_sql[i], -1, + &hlr_db_stmt[i], NULL); + if (rc != SQLITE_OK) { + LOGP(DDB, LOGL_ERROR, "OsmoHLR DB: Unable to prepare SQL statement '%s'\n", sql); + ret = -1; + goto out_free; + } + } + stmt = nitb_stmt[NITB_SELECT_SUBSCR]; while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { -- cgit v1.2.3