MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / load_entire_table

Function load_entire_table

modules/sql_cacher/sql_cacher.c:940–1078  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

938}
939
940static int load_entire_table(cache_entry_t *c_entry, db_handlers_t *db_hdls,
941 int inc_rld_vers)
942{
943 db_key_t *query_cols = NULL;
944 db_res_t *sql_res = NULL;
945 db_row_t *row;
946 db_val_t *values;
947 int i;
948 int reload_vers = 0;
949 int loaded_rec = 0;
950
951 sr_add_report( sql_srg, STR2CI(c_entry->id),
952 CHAR_INT("starting DB data loading"), 0);
953 if (inc_rld_vers==0)
954 sr_set_status( sql_srg, STR2CI(c_entry->id),
955 SR_STATUS_LOADING_DATA, CHAR_INT("startup data loading"), 0);
956 else
957 sr_set_status( sql_srg, STR2CI(c_entry->id),
958 SR_STATUS_RELOADING_DATA, CHAR_INT("data re-loading"), 0);
959
960 query_cols = pkg_malloc((c_entry->nr_columns + 1) * sizeof(db_key_t));
961 if (!query_cols) {
962 LM_ERR("No more pkg memory\n");
963 goto error_end;
964 }
965 query_cols[0] = &(c_entry->key);
966 for (i=0; i < c_entry->nr_columns; i++)
967 query_cols[i+1] = &((*c_entry->columns[i]));
968
969 /* query the entire table */
970 if (db_hdls->db_funcs.use_table(db_hdls->db_con, &c_entry->table) < 0) {
971 LM_ERR("Invalid table name: %.*s\n", c_entry->table.len, c_entry->table.s);
972 db_hdls->db_funcs.close(db_hdls->db_con);
973 db_hdls->db_con = 0;
974 pkg_free(query_cols);
975 goto error_end;
976 }
977 if (DB_CAPABILITY(db_hdls->db_funcs, DB_CAP_FETCH)) {
978 if (db_hdls->db_funcs.query(db_hdls->db_con, NULL, 0, NULL,
979 query_cols, 0, c_entry->nr_columns + 1, 0, 0) != 0) {
980 LM_ERR("Failure to issue query to SQL DB: %s\n",
981 db_url_escape(&c_entry->db_url));
982 pkg_free(query_cols);
983 goto error;
984 }
985
986 if (db_hdls->db_funcs.fetch_result(db_hdls->db_con,&sql_res,fetch_nr_rows)<0) {
987 LM_ERR("Error fetching rows from SQL DB: %s\n",
988 db_url_escape(&c_entry->db_url));
989 pkg_free(query_cols);
990 goto error;
991 }
992 } else {
993 if (db_hdls->db_funcs.query(db_hdls->db_con, NULL, 0, NULL,
994 query_cols, 0, c_entry->nr_columns + 1, 0, &sql_res) != 0) {
995 LM_ERR("Failure to issue query to SQL DB: %s\n",
996 db_url_escape(&c_entry->db_url));
997 pkg_free(query_cols);

Callers 3

reload_timerFunction · 0.85
mi_reloadFunction · 0.85
cache_init_loadFunction · 0.85

Calls 7

sr_add_reportFunction · 0.85
sr_set_statusFunction · 0.85
db_url_escapeFunction · 0.85
inc_cache_rld_versFunction · 0.85
get_column_typesFunction · 0.85
insert_in_cachedbFunction · 0.85
sr_add_report_fmtFunction · 0.85

Tested by

no test coverage detected