static void cql_fetch_field()

in sources/cqlrt_common.c [719:839]


static void cql_fetch_field(
    cql_int32 type,
    cql_int32 column,
    sqlite3 *_Nonnull db,
    sqlite3_stmt *_Nullable stmt,
    char *_Nonnull field,
    cql_bool enable_encoding,
    cql_int32 encode_context_type,
    char *_Nullable encode_context_field,
    cql_object_ref _Nullable encoder)
{
  bool is_encoded = (type & CQL_DATA_TYPE_ENCODED) && enable_encoding;
  cql_int32 core_data_type_and_not_null = type & ~CQL_DATA_TYPE_ENCODED;

  switch (core_data_type_and_not_null) {
    case CQL_DATA_TYPE_INT32 | CQL_DATA_TYPE_NOT_NULL: {
      cql_int32 *int32_data = (cql_int32 *)field;
      *int32_data = sqlite3_column_int(stmt, column);
      if (is_encoded) {
        *int32_data = cql_encode_int32(encoder, *int32_data, encode_context_type, encode_context_field);
      }
      break;
    }
    case CQL_DATA_TYPE_INT64 | CQL_DATA_TYPE_NOT_NULL: {
      cql_int64 *int64_data = (cql_int64 *)field;
      *int64_data = sqlite3_column_int64(stmt, column);
      if (is_encoded) {
        *int64_data = cql_encode_int64(encoder, *int64_data, encode_context_type, encode_context_field);
      }
      break;
    }
    case CQL_DATA_TYPE_DOUBLE | CQL_DATA_TYPE_NOT_NULL: {
      cql_double *double_data = (cql_double *)field;
      *double_data = sqlite3_column_double(stmt, column);
      if (is_encoded) {
        *double_data = cql_encode_double(encoder, *double_data, encode_context_type, encode_context_field);
      }
      break;
    }
    case CQL_DATA_TYPE_BOOL | CQL_DATA_TYPE_NOT_NULL: {
      cql_bool *bool_data = (cql_bool *)field;
      *bool_data = !!sqlite3_column_int(stmt, column);
      if (is_encoded) {
        *bool_data = cql_encode_bool(encoder, *bool_data, encode_context_type, encode_context_field);
      }
      break;
    }
    case CQL_DATA_TYPE_STRING | CQL_DATA_TYPE_NOT_NULL: {
      cql_string_ref *str_ref = (cql_string_ref *)field;
      cql_column_string_ref(stmt, column, str_ref);
      if (is_encoded) {
        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_NOT_NULL: {
      cql_blob_ref *blob_ref = (cql_blob_ref *)field;
      cql_column_blob_ref(stmt, column, blob_ref);
      if (is_encoded) {
        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_nullable_int32 *_Nonnull int32p = (cql_nullable_int32 *)field;
      cql_column_nullable_int32(stmt, column, int32p);
      if (is_encoded && !int32p->is_null) {
        int32p->value = cql_encode_int32(encoder, int32p->value, encode_context_type, encode_context_field);
      }
      break;
    }
    case CQL_DATA_TYPE_INT64: {
      cql_nullable_int64 *_Nonnull int64p = (cql_nullable_int64 *)field;
      cql_column_nullable_int64(stmt, column, int64p);
      if (is_encoded && !int64p->is_null) {
        int64p->value = cql_encode_int64(encoder, int64p->value, encode_context_type, encode_context_field);
      }
      break;
    }
    case CQL_DATA_TYPE_DOUBLE: {
      cql_nullable_double *_Nonnull doublep = (cql_nullable_double *)field;
      cql_column_nullable_double(stmt, column, doublep);
      if (is_encoded && !doublep->is_null) {
        doublep->value = cql_encode_double(encoder, doublep->value, encode_context_type, encode_context_field);
      }
      break;
    }
    case CQL_DATA_TYPE_BOOL: {
      cql_nullable_bool *_Nonnull boolp = (cql_nullable_bool *)field;
      cql_column_nullable_bool(stmt, column, boolp);
      if (is_encoded && !boolp->is_null) {
        boolp->value = cql_encode_bool(encoder, boolp->value, encode_context_type, encode_context_field);
      }
      break;
    }
    case CQL_DATA_TYPE_STRING: {
      cql_string_ref *str_ref = (cql_string_ref *)field;
      cql_column_nullable_string_ref(stmt, column, str_ref);
      if (is_encoded && *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_blob_ref *blob_ref = (cql_blob_ref *)field;
      cql_column_nullable_blob_ref(stmt, column, blob_ref);
      if (is_encoded && *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;
    }
  }
}