conversion_result application_data_buffer::put_num()

in modules/platforms/cpp/ignite/odbc/app/application_data_buffer.cpp [162:258]


conversion_result application_data_buffer::put_num(T value) {
    LOG_MSG("value: " << value);

    SQLLEN *res_len_ptr = get_result_len();
    void *data_ptr = get_data();

    switch (m_type) {
        case odbc_native_type::AI_SIGNED_TINYINT: {
            return put_num_to_num_buffer<signed char>(value);
        }

        case odbc_native_type::AI_BIT:
        case odbc_native_type::AI_UNSIGNED_TINYINT: {
            return put_num_to_num_buffer<unsigned char>(value);
        }

        case odbc_native_type::AI_SIGNED_SHORT: {
            return put_num_to_num_buffer<SQLSMALLINT>(value);
        }

        case odbc_native_type::AI_UNSIGNED_SHORT: {
            return put_num_to_num_buffer<SQLUSMALLINT>(value);
        }

        case odbc_native_type::AI_SIGNED_LONG: {
            return put_num_to_num_buffer<SQLINTEGER>(value);
        }

        case odbc_native_type::AI_UNSIGNED_LONG: {
            return put_num_to_num_buffer<SQLUINTEGER>(value);
        }

        case odbc_native_type::AI_SIGNED_BIGINT: {
            return put_num_to_num_buffer<SQLBIGINT>(value);
        }

        case odbc_native_type::AI_UNSIGNED_BIGINT: {
            return put_num_to_num_buffer<SQLUBIGINT>(value);
        }

        case odbc_native_type::AI_FLOAT: {
            return put_num_to_num_buffer<SQLREAL>(value);
        }

        case odbc_native_type::AI_DOUBLE: {
            return put_num_to_num_buffer<SQLDOUBLE>(value);
        }

        case odbc_native_type::AI_CHAR: {
            return put_value_to_string_buffer<char>(value);
        }

        case odbc_native_type::AI_WCHAR: {
            return put_value_to_string_buffer<wchar_t>(value);
        }

        case odbc_native_type::AI_NUMERIC: {
            if (data_ptr) {
                auto *out = reinterpret_cast<SQL_NUMERIC_STRUCT *>(data_ptr);
                auto u_val = static_cast<std::uint64_t>(value < 0 ? -value : value);

                out->precision = detail::digit_length(u_val);
                out->scale = 0;
                out->sign = value < 0 ? 0 : 1;

                memset(out->val, 0, SQL_MAX_NUMERIC_LEN);

                memcpy(out->val, &u_val, std::min<int>(SQL_MAX_NUMERIC_LEN, sizeof(u_val)));
            }

            if (res_len_ptr)
                *res_len_ptr = static_cast<SQLLEN>(sizeof(SQL_NUMERIC_STRUCT));

            return conversion_result::AI_SUCCESS;
        }

        case odbc_native_type::AI_BINARY:
        case odbc_native_type::AI_DEFAULT: {
            if (data_ptr)
                memcpy(data_ptr, &value, std::min(sizeof(value), static_cast<std::size_t>(m_buffer_len)));

            if (res_len_ptr)
                *res_len_ptr = sizeof(value);

            return static_cast<std::size_t>(m_buffer_len) < sizeof(value) ? conversion_result::AI_VARLEN_DATA_TRUNCATED
                                                                          : conversion_result::AI_SUCCESS;
        }

        case odbc_native_type::AI_TDATE:
        case odbc_native_type::AI_TTIMESTAMP:
        case odbc_native_type::AI_TTIME:
        default:
            break;
    }

    return conversion_result::AI_UNSUPPORTED_CONVERSION;
}