in modules/platforms/cpp/ignite/odbc/app/application_data_buffer.cpp [764:838]
conversion_result application_data_buffer::put_time(const ignite_time &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: {
const auto val_len = SQLLEN(sizeof("HH:MM:SS"));
auto tm_time = time_to_tm_for_strftime(value);
return put_tm_to_string(tm_time, val_len, "%H:%M:%S");
}
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 = SQLSMALLINT(value.get_hour());
buffer->minute = SQLSMALLINT(value.get_minute());
buffer->second = SQLSMALLINT(value.get_second());
}
if (res_len_ptr)
*res_len_ptr = static_cast<SQLLEN>(sizeof(SQL_TIME_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));
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
auto tm_time = time_t_to_tm(now);
// According to ODBC specification, those should be set to current date.
buffer->year = SQLSMALLINT(tm_time.tm_year + 1900);
buffer->month = tm_time.tm_mon + 1;
buffer->day = tm_time.tm_mday;
buffer->hour = SQLSMALLINT(value.get_hour());
buffer->minute = SQLSMALLINT(value.get_minute());
buffer->second = SQLSMALLINT(value.get_second());
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:
case odbc_native_type::AI_TDATE:
default:
break;
}
return conversion_result::AI_UNSUPPORTED_CONVERSION;
}