| 2273 | // |
| 2274 | |
| 2275 | static void par_order(gpre_req* request, gpre_rse* select, bool union_f, bool view_flag) |
| 2276 | { |
| 2277 | gpre_nod* sort; |
| 2278 | USHORT i; |
| 2279 | |
| 2280 | assert_IS_REQ(request); |
| 2281 | |
| 2282 | if (!MSC_match(KW_ORDER)) |
| 2283 | return; |
| 2284 | if (view_flag) |
| 2285 | PAR_error("sort clause not allowed in a view definition"); |
| 2286 | |
| 2287 | MSC_match(KW_BY); |
| 2288 | gpre_lls* items = NULL; |
| 2289 | gpre_lls* directions = NULL; |
| 2290 | int count = 0; |
| 2291 | bool direction = false; |
| 2292 | gpre_nod* values = select->rse_fields; |
| 2293 | |
| 2294 | while (true) |
| 2295 | { |
| 2296 | direction = false; |
| 2297 | if (gpreGlob.token_global.tok_type == tok_number) |
| 2298 | { |
| 2299 | i = EXP_USHORT_ordinal(false); |
| 2300 | if (i < 1 || i > values->nod_count) |
| 2301 | CPR_s_error("<ordinal column position>"); |
| 2302 | sort = values->nod_arg[i - 1]; |
| 2303 | PAR_get_token(); |
| 2304 | if (gpreGlob.token_global.tok_keyword == KW_COLLATE) |
| 2305 | sort = par_collate(request, sort); |
| 2306 | } |
| 2307 | else |
| 2308 | { |
| 2309 | if (union_f) |
| 2310 | CPR_s_error("<column position in union>"); |
| 2311 | sort = SQE_value(request, false, NULL, NULL); |
| 2312 | map* request_map; |
| 2313 | if (request && (request_map = request->req_map)) |
| 2314 | sort = post_map(sort, request_map); |
| 2315 | } |
| 2316 | if (MSC_match(KW_ASCENDING)) |
| 2317 | direction = false; |
| 2318 | else if (MSC_match(KW_DESCENDING)) |
| 2319 | direction = true; |
| 2320 | count++; |
| 2321 | MSC_push((gpre_nod*)(IPTR) direction, &directions); |
| 2322 | MSC_push(sort, &items); |
| 2323 | if (!MSC_match(KW_COMMA)) |
| 2324 | break; |
| 2325 | } |
| 2326 | |
| 2327 | select->rse_sort = sort = MSC_node(nod_sort, (SSHORT) (count * 2)); |
| 2328 | sort->nod_count = count; |
| 2329 | gpre_nod** ptr = sort->nod_arg + count * 2; |
| 2330 | |
| 2331 | while (items) |
| 2332 | { |
no test coverage detected