| 110 | |
| 111 | |
| 112 | int lb_db_load_data( struct lb_data *data) |
| 113 | { |
| 114 | db_key_t columns[LB_NO_COLS]; |
| 115 | db_res_t* res = NULL; |
| 116 | db_row_t* row; |
| 117 | int i, n; |
| 118 | char *resource, *uri, *attrs; |
| 119 | int id, group, pmode; |
| 120 | unsigned int flags; |
| 121 | int no_rows = 10; |
| 122 | |
| 123 | |
| 124 | lb_dbf.use_table( lb_db_handle, &lb_table_name); |
| 125 | |
| 126 | columns[0] = &lb_id_column; |
| 127 | columns[1] = &lb_grpid_column; |
| 128 | columns[2] = &lb_dsturi_column; |
| 129 | columns[3] = &lb_resource_column; |
| 130 | columns[4] = &lb_pmode_column; |
| 131 | columns[5] = &lb_attrs_column; |
| 132 | |
| 133 | if (0/*DB_CAPABILITY(lb_dbf, DB_CAP_FETCH))*/) { |
| 134 | if (lb_dbf.query(lb_db_handle, 0, 0, 0, columns, 0, LB_NO_COLS, 0, 0) < 0) { |
| 135 | LM_ERR("DB query failed\n"); |
| 136 | return -1; |
| 137 | } |
| 138 | no_rows = estimate_available_rows( 4+4+64+256+8+256, LB_NO_COLS/*cols*/); |
| 139 | if (no_rows==0) no_rows = 10; |
| 140 | if(lb_dbf.fetch_result( lb_db_handle, &res, no_rows)<0) { |
| 141 | LM_ERR("Error fetching rows\n"); |
| 142 | return -1; |
| 143 | } |
| 144 | } else { |
| 145 | if (lb_dbf.query(lb_db_handle, 0, 0, 0, columns, 0, LB_NO_COLS, 0, &res)<0) { |
| 146 | LM_ERR("DB query failed\n"); |
| 147 | return -1; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if (res == NULL || RES_ROW_N(res) == 0) { |
| 152 | LM_WARN("table \"%.*s\" empty\n", lb_table_name.len,lb_table_name.s ); |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | LM_DBG("%d records found in %.*s\n", |
| 157 | RES_ROW_N(res), lb_table_name.len,lb_table_name.s ); |
| 158 | n = 0; |
| 159 | |
| 160 | do { |
| 161 | for(i=0; i < RES_ROW_N(res); i++) { |
| 162 | row = RES_ROWS(res) + i; |
| 163 | flags = 0; |
| 164 | /* ID column */ |
| 165 | check_val( ROW_VALUES(row), DB_INT, 1, 0); |
| 166 | id = VAL_INT(ROW_VALUES(row)); |
| 167 | /* GRP_ID column */ |
| 168 | check_val( ROW_VALUES(row)+1, DB_INT, 1, 0); |
| 169 | group = VAL_INT(ROW_VALUES(row)+1); |
no test coverage detected