Code refactor

This commit is contained in:
Juan Ferrer 2019-12-02 18:10:20 +01:00
parent 5d8c6555a4
commit e550ef0b6d
2 changed files with 3 additions and 5 deletions

View File

@ -85,11 +85,10 @@ char * sql_printf(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long
} }
char *arg = args->args[i]; char *arg = args->args[i];
unsigned long len = args->lengths[i];
if (arg) { if (arg != NULL) {
buffer_append(buffer, delimiter); buffer_append(buffer, delimiter);
buffer_append_len(buffer, arg, len); buffer_append_len(buffer, arg, args->lengths[i]);
buffer_append(buffer, delimiter); buffer_append(buffer, delimiter);
} else } else
buffer_append(buffer, "NULL"); buffer_append(buffer, "NULL");

View File

@ -81,11 +81,10 @@ int value_compare(Value *a, Value *b) {
case INT_RESULT: case INT_RESULT:
cmp = a->val.i - b->val.i; cmp = a->val.i - b->val.i;
break; break;
case REAL_RESULT: { case REAL_RESULT:
real_cmp = a->val.d - b->val.d; real_cmp = a->val.d - b->val.d;
cmp = real_cmp == 0.0 ? 0 : (real_cmp > 0.0 ? 1 : -1); cmp = real_cmp == 0.0 ? 0 : (real_cmp > 0.0 ? 1 : -1);
break; break;
}
default: // STRING_RESULT & DECIMAL_RESULT default: // STRING_RESULT & DECIMAL_RESULT
cmp = strncmp(a->val.s, b->val.s, min(a->len, b->len)); cmp = strncmp(a->val.s, b->val.s, min(a->len, b->len));
if (cmp == 0) cmp = a->len - b->len; if (cmp == 0) cmp = a->len - b->len;