Skip to content

Commit 5dbadce

Browse files
committed
vef: convert ba_concat_all_prerun to typed PrerunArgs/PrerunResult
1 parent c351103 commit 5dbadce

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

villagesql/examples/vsql-simple/src/extension.cc

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,20 @@ void ba_len(IntResult out) { out.set(static_cast<long long>(kBytearrayLen)); }
158158
// Prerun: validate that all arguments are BYTEARRAY (or NULL literals,
159159
// which appear as VEF_TYPE_STRING in the prerun arg-type array) and ask
160160
// the server to allocate arg_count * kBytearrayLen bytes of result buffer.
161-
void ba_concat_all_prerun(vef_context_t *, vef_prerun_args_t *args,
162-
vef_prerun_result_t *result) {
163-
if (args->arg_count == 0) {
164-
result->type = VEF_RESULT_ERROR;
165-
snprintf(result->error_msg, VEF_MAX_ERROR_LEN,
166-
"ba_concat_all requires at least one argument");
161+
void ba_concat_all_prerun(vsql::PrerunArgs args, vsql::PrerunResult out) {
162+
if (args.size() == 0) {
163+
out.error("ba_concat_all requires at least one argument");
167164
return;
168165
}
169-
for (unsigned int i = 0; i < args->arg_count; i++) {
170-
vef_type_id id = args->arg_types[i].id;
171-
if (id != VEF_TYPE_CUSTOM && id != VEF_TYPE_STRING) {
172-
result->type = VEF_RESULT_ERROR;
173-
snprintf(result->error_msg, VEF_MAX_ERROR_LEN,
174-
"ba_concat_all: argument %u must be BYTEARRAY", i);
166+
for (size_t i = 0; i < args.size(); i++) {
167+
auto t = args.type_at(i);
168+
if (!t.is_custom() && !t.is_str()) {
169+
out.error("ba_concat_all: argument " + std::to_string(i) +
170+
" must be BYTEARRAY");
175171
return;
176172
}
177173
}
178-
result->result_buffer_size = args->arg_count * kBytearrayLen;
174+
out.request_buffer_size(args.size() * kBytearrayLen);
179175
}
180176

181177
void ba_concat_all(VarArgs args, StringResult out) {

0 commit comments

Comments
 (0)