One ORDER BY comparison: numeric columns by their (int)strtol value, * others by strcmp, a later key breaking ties; positive = a after b. * va/vb are the rows' parsed numeric keys, or NULL to parse here. */
| 3900 | * others by strcmp, a later key breaking ties; positive = a after b. |
| 3901 | * va/vb are the rows' parsed numeric keys, or NULL to parse here. */ |
| 3902 | static int rb_order_compare_rows(const rb_order_ctx_t *ctx, const char **ra, const char **rb_row, |
| 3903 | const int *va, const int *vb) { |
| 3904 | int cmp = 0; |
| 3905 | for (int k = 0; k < ctx->keys && cmp == 0; k++) { |
| 3906 | if (ctx->numeric[k]) { |
| 3907 | int a = va ? va[k] : (int)strtol(ra[ctx->cols[k]], NULL, CBM_DECIMAL_BASE); |
| 3908 | int b = vb ? vb[k] : (int)strtol(rb_row[ctx->cols[k]], NULL, CBM_DECIMAL_BASE); |
| 3909 | cmp = (a > b) - (a < b); |
| 3910 | } else { |
| 3911 | cmp = strcmp(ra[ctx->cols[k]], rb_row[ctx->cols[k]]); |
| 3912 | } |
| 3913 | if (ctx->descs[k]) { |
| 3914 | cmp = -cmp; |
| 3915 | } |
| 3916 | } |
| 3917 | return cmp; |
| 3918 | } |
| 3919 | |
| 3920 | static int rb_order_compare(const void *context, int a, int b) { |
| 3921 | const rb_order_ctx_t *ctx = context; |
no outgoing calls
no test coverage detected