mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-02-01 22:56:39 +01:00
Core/DBLayer: Support retrieving DATE/DATETIME/TIMESTAMP column values directly without casting in sql
(cherry picked from commit 404bb5b3c2)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user