| 938 | } |
| 939 | |
| 940 | static 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); |
no test coverage detected