conversion_result application_data_buffer::put_date()

in modules/platforms/cpp/ignite/odbc/app/application_data_buffer.cpp [612:677]


conversion_result application_data_buffer::put_date(const ignite_date &value) {
    SQLLEN *res_len_ptr = get_result_len();
    void *data_ptr = get_data();

    switch (m_type) {
        case odbc_native_type::AI_WCHAR:
        case odbc_native_type::AI_CHAR:
        case odbc_native_type::AI_BINARY: {
            constexpr auto val_len = SQLLEN(sizeof("HHHH-MM-DD"));
            auto tm_time = date_to_tm_for_strftime(value);

            return put_tm_to_string(tm_time, val_len, "%Y-%m-%d");
        }

        case odbc_native_type::AI_TDATE: {
            if (data_ptr) {
                auto *buffer = reinterpret_cast<SQL_DATE_STRUCT *>(data_ptr);
                memset(buffer, 0, sizeof(*buffer));

                buffer->year = SQLSMALLINT(value.get_year());
                buffer->month = SQLUSMALLINT(value.get_month()); // NOLINT(cert-str34-c)
                buffer->day = SQLUSMALLINT(value.get_day_of_month()); // NOLINT(cert-str34-c)
            }

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

            return conversion_result::AI_SUCCESS;
        }

        case odbc_native_type::AI_TTIMESTAMP: {
            if (data_ptr) {
                auto *buffer = reinterpret_cast<SQL_TIMESTAMP_STRUCT *>(data_ptr);
                memset(buffer, 0, sizeof(*buffer));

                buffer->year = SQLSMALLINT(value.get_year());
                buffer->month = SQLUSMALLINT(value.get_month()); // NOLINT(cert-str34-c)
                buffer->day = SQLUSMALLINT(value.get_day_of_month()); // NOLINT(cert-str34-c)
            }

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

            return conversion_result::AI_SUCCESS;
        }

        case odbc_native_type::AI_TTIME:
        case odbc_native_type::AI_DEFAULT:
        case odbc_native_type::AI_SIGNED_TINYINT:
        case odbc_native_type::AI_BIT:
        case odbc_native_type::AI_UNSIGNED_TINYINT:
        case odbc_native_type::AI_SIGNED_SHORT:
        case odbc_native_type::AI_UNSIGNED_SHORT:
        case odbc_native_type::AI_SIGNED_LONG:
        case odbc_native_type::AI_UNSIGNED_LONG:
        case odbc_native_type::AI_SIGNED_BIGINT:
        case odbc_native_type::AI_UNSIGNED_BIGINT:
        case odbc_native_type::AI_FLOAT:
        case odbc_native_type::AI_DOUBLE:
        case odbc_native_type::AI_NUMERIC:
        default:
            break;
    }

    return conversion_result::AI_UNSUPPORTED_CONVERSION;
}