flush resultset to network
| 223 | |
| 224 | // flush resultset to network |
| 225 | void ResultSet_Reply |
| 226 | ( |
| 227 | ResultSet *set // resultset to reply with |
| 228 | ) { |
| 229 | ASSERT(set != NULL); |
| 230 | |
| 231 | uint64_t row_count = ResultSet_RowCount(set); |
| 232 | |
| 233 | // check to see if we've encountered a run-time error |
| 234 | // if so, emit it as the only response |
| 235 | if(ErrorCtx_EncounteredError()) { |
| 236 | ErrorCtx_EmitException(); |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | // set up the results array and emit the header if the query requires one |
| 241 | _ResultSet_ReplyWithPreamble(set); |
| 242 | |
| 243 | // emit resultset |
| 244 | if(set->column_count > 0) { |
| 245 | RedisModule_ReplyWithArray(set->ctx, row_count); |
| 246 | SIValue *row[set->column_count]; |
| 247 | uint64_t cells = DataBlock_ItemCount(set->cells); |
| 248 | // for each row |
| 249 | for(uint64_t i = 0; i < cells; i += set->column_count) { |
| 250 | // for each column |
| 251 | for(uint j = 0; j < set->column_count; j++) { |
| 252 | row[j] = DataBlock_GetItem(set->cells, i + j); |
| 253 | } |
| 254 | |
| 255 | set->formatter->EmitRow(set->ctx, set->gc, row, set->column_count); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | ResultSetStat_emit(set->ctx, &set->stats); // response with statistics |
| 260 | } |
| 261 | |
| 262 | void ResultSet_Clear(ResultSet *set) { |
| 263 | ASSERT(set != NULL); |
no test coverage detected