diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2020-09-21 14:41:37 +0200 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2020-09-21 14:42:29 +0200 |
commit | 472bb0733d6dcbf9d33fd0f56b030b9abd5c4566 (patch) | |
tree | 2f9bc34ac052490093a192cdb0950cfd6df1ba79 | |
parent | d118efb78918fa15963cf2207acae1a7cc2d6dd2 (diff) |
put SQL only used in hlr-db-tool in hlr_db_tool.cneels/for_keith
Change-Id: I3ac327dbcef37472fb13b8689d008e74b83b3bb1
-rw-r--r-- | include/osmocom/hlr/db.h | 1 | ||||
-rw-r--r-- | src/db.c | 1 | ||||
-rw-r--r-- | 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 }; @@ -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) { |