in modules/platforms/cpp/ignite/odbc/app/application_data_buffer.cpp [679:762]
conversion_result application_data_buffer::put_timestamp(const ignite_timestamp &value) {
auto *res_len_ptr = get_result_len();
void *data_ptr = get_data();
auto tm_time = timestamp_to_tm(value);
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 HH:MM:SS"));
return put_tm_to_string(tm_time, val_len, "%Y-%m-%d %H:%M:%S");
}
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(tm_time.tm_year + 1900);
buffer->month = tm_time.tm_mon + 1;
buffer->day = tm_time.tm_mday;
}
if (res_len_ptr)
*res_len_ptr = static_cast<SQLLEN>(sizeof(SQL_DATE_STRUCT));
return conversion_result::AI_FRACTIONAL_TRUNCATED;
}
case odbc_native_type::AI_TTIME: {
if (data_ptr) {
auto *buffer = reinterpret_cast<SQL_TIME_STRUCT *>(data_ptr);
memset(buffer, 0, sizeof(*buffer));
buffer->hour = tm_time.tm_hour;
buffer->minute = tm_time.tm_min;
buffer->second = tm_time.tm_sec;
}
if (res_len_ptr)
*res_len_ptr = static_cast<SQLLEN>(sizeof(SQL_TIME_STRUCT));
return conversion_result::AI_FRACTIONAL_TRUNCATED;
}
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(tm_time.tm_year + 1900);
buffer->month = tm_time.tm_mon + 1;
buffer->day = tm_time.tm_mday;
buffer->hour = tm_time.tm_hour;
buffer->minute = tm_time.tm_min;
buffer->second = tm_time.tm_sec;
buffer->fraction = value.get_nano();
}
if (res_len_ptr)
*res_len_ptr = static_cast<SQLLEN>(sizeof(SQL_TIMESTAMP_STRUCT));
return conversion_result::AI_SUCCESS;
}
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;
}