in sources/cqlrt_common.c [2254:2382]
static void cql_encode_new_result_set_data(
cql_fetch_info *_Nonnull info,
char *_Nullable data,
cql_int32 rows)
{
sqlite3 *db = info->db;
if (!db) {
// DB pointer is only set if the result_set is a came from the database.
// We also only encode/decode if the result_set came from the database.
// Non database result sets (e.g. out union) are never encoded/decoded
// therefore we should end here.
return;
}
int32_t rowsize = info->rowsize;
uint8_t *_Nonnull data_types = info->data_types;
uint16_t *_Nonnull col_offsets = info->col_offsets;
uint32_t count = col_offsets[0];
col_offsets++;
cql_bool got_encoder = false;
cql_object_ref encoder = NULL;
cql_int32 encode_context_type = -1;
if (info->encode_context_index >= 0) {
encode_context_type = data_types[info->encode_context_index];
}
char *encode_context_field = NULL;
char *row = data;
for (cql_int32 i = 0; i < rows ; i++, row += rowsize) {
if (info->encode_context_index >= 0) {
encode_context_field = row + col_offsets[info->encode_context_index];
}
for (cql_int32 column = 0; column < count; column++) {
uint8_t type = data_types[column];
char *field = row + col_offsets[column];
if (!got_encoder && type & CQL_DATA_TYPE_ENCODED) {
encoder = cql_copy_encoder(db);
got_encoder = true;
}
switch (type) {
case CQL_DATA_TYPE_INT32 | CQL_DATA_TYPE_ENCODED | CQL_DATA_TYPE_NOT_NULL: {
cql_int32 *int32_data = (cql_int32 *)field;
*int32_data = cql_encode_int32(encoder, *int32_data, encode_context_type, encode_context_field);
break;
}
case CQL_DATA_TYPE_INT64 | CQL_DATA_TYPE_ENCODED | CQL_DATA_TYPE_NOT_NULL: {
cql_int64 *int64_data = (cql_int64 *)field;
*int64_data = cql_encode_int64(encoder, *int64_data, encode_context_type, encode_context_field);
break;
}
case CQL_DATA_TYPE_DOUBLE | CQL_DATA_TYPE_ENCODED | CQL_DATA_TYPE_NOT_NULL: {
cql_double *double_data = (cql_double *)field;
*double_data = cql_encode_double(encoder, *double_data, encode_context_type, encode_context_field);
break;
}
case CQL_DATA_TYPE_BOOL | CQL_DATA_TYPE_ENCODED | CQL_DATA_TYPE_NOT_NULL: {
cql_bool *bool_data = (cql_bool *)field;
*bool_data = cql_encode_bool(encoder, *bool_data, encode_context_type, encode_context_field);
break;
}
case CQL_DATA_TYPE_STRING | CQL_DATA_TYPE_ENCODED | CQL_DATA_TYPE_NOT_NULL: {
cql_string_ref *str_ref = (cql_string_ref *)field;
cql_string_ref new_str_ref = cql_encode_string_ref_new(encoder, *str_ref, encode_context_type, encode_context_field);
cql_set_string_ref(str_ref, new_str_ref);
cql_string_release(new_str_ref);
break;
}
case CQL_DATA_TYPE_BLOB | CQL_DATA_TYPE_ENCODED | CQL_DATA_TYPE_NOT_NULL: {
cql_blob_ref *blob_ref = (cql_blob_ref *)field;
cql_blob_ref new_blob_ref = cql_encode_blob_ref_new(encoder, *blob_ref, encode_context_type, encode_context_field);
cql_set_blob_ref(blob_ref, new_blob_ref);
cql_blob_release(new_blob_ref);
break;
}
case CQL_DATA_TYPE_INT32 | CQL_DATA_TYPE_ENCODED: {
cql_nullable_int32 *_Nonnull int32p = (cql_nullable_int32 *_Nonnull)field;
if (!int32p->is_null) {
int32p->value = cql_encode_int32(encoder, int32p->value, encode_context_type, encode_context_field);
}
break;
}
case CQL_DATA_TYPE_INT64 | CQL_DATA_TYPE_ENCODED: {
cql_nullable_int64 *_Nonnull int64p = (cql_nullable_int64 *_Nonnull)field;
if (!int64p->is_null) {
int64p->value = cql_encode_int64(encoder, int64p->value, encode_context_type, encode_context_field);
}
break;
}
case CQL_DATA_TYPE_DOUBLE | CQL_DATA_TYPE_ENCODED: {
cql_nullable_double *_Nonnull doublep = (cql_nullable_double *_Nonnull)field;
if (!doublep->is_null) {
doublep->value = cql_encode_double(encoder, doublep->value, encode_context_type, encode_context_field);
}
break;
}
case CQL_DATA_TYPE_BOOL | CQL_DATA_TYPE_ENCODED: {
cql_nullable_bool *_Nonnull boolp = (cql_nullable_bool *_Nonnull)field;
if (!boolp->is_null) {
boolp->value = cql_encode_bool(encoder, boolp->value, encode_context_type, encode_context_field);
}
break;
}
case CQL_DATA_TYPE_STRING | CQL_DATA_TYPE_ENCODED: {
cql_string_ref *str_ref = (cql_string_ref *)field;
if (*str_ref) {
cql_string_ref new_str_ref = cql_encode_string_ref_new(encoder, *str_ref, encode_context_type, encode_context_field);
cql_set_string_ref(str_ref, new_str_ref);
cql_string_release(new_str_ref);
}
break;
}
case CQL_DATA_TYPE_BLOB | CQL_DATA_TYPE_ENCODED: {
cql_blob_ref *blob_ref = (cql_blob_ref *)field;
if (*blob_ref) {
cql_blob_ref new_blob_ref = cql_encode_blob_ref_new(encoder, *blob_ref, encode_context_type, encode_context_field);
cql_set_blob_ref(blob_ref, new_blob_ref);
cql_blob_release(new_blob_ref);
}
break;
}
}
}
}
cql_object_release(encoder);
}