mirror of
https://github.com/rbock/sqlpp11.git
synced 2025-12-31 10:10:28 -06:00
Add time of day paramter for mysql #565
This commit is contained in:
@@ -214,6 +214,39 @@ namespace sqlpp
|
||||
param.is_unsigned = false;
|
||||
param.error = nullptr;
|
||||
}
|
||||
|
||||
void _bind_time_of_day_parameter(size_t index, const ::std::chrono::microseconds* value, bool is_null)
|
||||
{
|
||||
if (_handle->debug)
|
||||
std::cerr << "MySQL debug: binding time_of_day parameter "
|
||||
<< " at index: " << index << ", being " << (is_null ? "" : "not ") << "null" << std::endl;
|
||||
|
||||
auto& bound_time = _handle->stmt_date_time_param_buffer[index];
|
||||
if (not is_null)
|
||||
{
|
||||
const auto time = ::date::make_time(*value);
|
||||
bound_time.year = 0u;
|
||||
bound_time.month = 0u;
|
||||
bound_time.day = 0u;
|
||||
bound_time.hour = static_cast<unsigned>(time.hours().count());
|
||||
bound_time.minute = static_cast<unsigned>(time.minutes().count());
|
||||
bound_time.second = static_cast<unsigned>(time.seconds().count());
|
||||
bound_time.second_part = static_cast<unsigned long>(time.subseconds().count());
|
||||
if (_handle->debug)
|
||||
std::cerr << "bound values: " << bound_time.hour << ':' << bound_time.minute << ':' << bound_time.second
|
||||
<< '.' << bound_time.second_part << std::endl;
|
||||
}
|
||||
|
||||
_handle->stmt_param_is_null[index] = is_null;
|
||||
MYSQL_BIND& param{_handle->stmt_params[index]};
|
||||
param.buffer_type = MYSQL_TYPE_TIME;
|
||||
param.buffer = &bound_time;
|
||||
param.buffer_length = sizeof(MYSQL_TIME);
|
||||
param.length = ¶m.buffer_length;
|
||||
param.is_null = &_handle->stmt_param_is_null[index].value;
|
||||
param.is_unsigned = false;
|
||||
param.error = nullptr;
|
||||
}
|
||||
};
|
||||
} // namespace mysql
|
||||
} // namespace sqlpp
|
||||
|
||||
@@ -83,7 +83,7 @@ int DateTime(int, char*[])
|
||||
col_day_point date,
|
||||
col_time_point datetime(3),
|
||||
col_date_time_point datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
col_time_of_day time
|
||||
col_time_of_day time(3)
|
||||
))");
|
||||
|
||||
const auto tab = TabDateTime{};
|
||||
@@ -130,12 +130,14 @@ int DateTime(int, char*[])
|
||||
.set(tab.colDayPoint = parameter(tab.colDayPoint), tab.colTimePoint = parameter(tab.colTimePoint))
|
||||
.unconditionally();
|
||||
|
||||
auto prepared_update = db.prepare(
|
||||
update(tab)
|
||||
.set(tab.colDayPoint = parameter(tab.colDayPoint), tab.colTimePoint = parameter(tab.colTimePoint))
|
||||
.unconditionally());
|
||||
auto prepared_update = db.prepare(update(tab)
|
||||
.set(tab.colDayPoint = parameter(tab.colDayPoint),
|
||||
tab.colTimePoint = parameter(tab.colTimePoint),
|
||||
tab.colTimeOfDay = parameter(tab.colTimeOfDay))
|
||||
.unconditionally());
|
||||
prepared_update.params.colDayPoint = today;
|
||||
prepared_update.params.colTimePoint = now;
|
||||
prepared_update.params.colTimeOfDay = current;
|
||||
std::cout << "---- running prepared update ----" << std::endl;
|
||||
db(prepared_update);
|
||||
std::cout << "---- finished prepared update ----" << std::endl;
|
||||
@@ -143,6 +145,7 @@ int DateTime(int, char*[])
|
||||
{
|
||||
require_equal(__LINE__, row.colDayPoint.value(), today);
|
||||
require_equal(__LINE__, row.colTimePoint.value(), now);
|
||||
require_equal(__LINE__, row.colTimeOfDay.value(), current);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
||||
Reference in New Issue
Block a user