Core/DBLayer: Support retrieving DATE/DATETIME/TIMESTAMP column values directly without casting in sql

(cherry picked from commit 404bb5b3c2)
This commit is contained in:
Shauren
2024-04-10 13:59:19 +02:00
committed by Ovahlord
parent 1d3af156a3
commit 2d1c2c79ab
10 changed files with 310 additions and 41 deletions

View File

@@ -20,6 +20,7 @@
#include "Log.h"
#include "MySQLHacks.h"
#include "PreparedStatement.h"
#include <chrono>
#include <cstring>
template<typename T>
@@ -145,6 +146,33 @@ void MySQLPreparedStatement::SetParameter(uint8 index, T value)
memcpy(param->buffer, &value, len);
}
void MySQLPreparedStatement::SetParameter(uint8 index, SystemTimePoint value)
{
AssertValidIndex(index);
m_paramsSet[index] = true;
MYSQL_BIND* param = &m_bind[index];
uint32 len = sizeof(MYSQL_TIME);
param->buffer_type = MYSQL_TYPE_DATETIME;
delete[] static_cast<char*>(param->buffer);
param->buffer = new char[len];
param->buffer_length = len;
param->is_null_value = 0;
delete param->length;
param->length = new unsigned long(len);
std::chrono::year_month_day ymd(time_point_cast<std::chrono::days>(value));
std::chrono::hh_mm_ss hms(duration_cast<std::chrono::microseconds>(value - std::chrono::sys_days(ymd)));
MYSQL_TIME* time = reinterpret_cast<MYSQL_TIME*>(static_cast<char*>(param->buffer));
time->year = static_cast<int32>(ymd.year());
time->month = static_cast<uint32>(ymd.month());
time->day = static_cast<uint32>(ymd.day());
time->hour = hms.hours().count();
time->minute = hms.minutes().count();
time->second = hms.seconds().count();
time->second_part = hms.subseconds().count();
}
void MySQLPreparedStatement::SetParameter(uint8 index, std::string const& value)
{
AssertValidIndex(index);