2016-05-22 21:34:27 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Common.hpp"
|
|
|
|
|
2016-07-07 23:57:57 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <cerrno>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
2016-05-22 21:34:27 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2016-06-05 04:08:59 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void SqDateToMySQLTime(Object & obj, MYSQL_TIME & t)
|
|
|
|
{
|
|
|
|
// The resulted date values
|
|
|
|
uint16_t year = 0;
|
|
|
|
uint8_t month = 0, day = 0;
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-06-05 04:08:59 +02:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object >::push(DefaultVM::Get(), obj);
|
2016-06-05 04:08:59 +02:00
|
|
|
// Attempt to get the values inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetDate(DefaultVM::Get(), -1, &year, &month, &day)))
|
2016-06-05 04:08:59 +02:00
|
|
|
{
|
|
|
|
STHROWF("Invalid date specified");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Populate the given structure
|
|
|
|
t.year = year;
|
|
|
|
t.month = month;
|
|
|
|
t.day = day;
|
|
|
|
t.hour = 0;
|
|
|
|
t.minute = 0;
|
|
|
|
t.second = 0;
|
|
|
|
t.neg = false;
|
|
|
|
t.second_part = 0;
|
|
|
|
t.time_type = MYSQL_TIMESTAMP_DATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void SqTimeToMySQLTime(Object & obj, MYSQL_TIME & t)
|
|
|
|
{
|
|
|
|
// The resulted time values
|
|
|
|
uint8_t hour = 0, minute = 0, second = 0;
|
|
|
|
uint16_t milli = 0;
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-06-05 04:08:59 +02:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object >::push(DefaultVM::Get(), obj);
|
2016-06-05 04:08:59 +02:00
|
|
|
// Attempt to get the values inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetTime(DefaultVM::Get(), -1, &hour, &minute, &second, &milli)))
|
2016-06-05 04:08:59 +02:00
|
|
|
{
|
|
|
|
STHROWF("Invalid time specified");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Populate the given structure
|
|
|
|
t.year = 0;
|
|
|
|
t.month = 0;
|
|
|
|
t.day = 0;
|
|
|
|
t.neg = false;
|
|
|
|
t.second_part = (milli * 1000L);
|
|
|
|
t.time_type = MYSQL_TIMESTAMP_TIME;
|
|
|
|
}
|
2016-05-22 21:34:27 +02:00
|
|
|
|
2016-06-05 04:08:59 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void SqDatetimeToMySQLTime(Object & obj, MYSQL_TIME & t)
|
|
|
|
{
|
|
|
|
// The resulted date values
|
|
|
|
uint16_t year = 0, milli = 0;
|
|
|
|
uint8_t month = 0, day = 0, hour = 0, minute = 0, second = 0;
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-07-17 02:24:07 +02:00
|
|
|
const StackGuard sg;
|
2016-06-05 04:08:59 +02:00
|
|
|
// Push the specified object onto the stack
|
2016-07-17 02:24:07 +02:00
|
|
|
Var< Object >::push(DefaultVM::Get(), obj);
|
2016-06-05 04:08:59 +02:00
|
|
|
// Attempt to get the values inside the specified object
|
2016-07-17 02:24:07 +02:00
|
|
|
if (SQ_FAILED(SqMod_GetDatetime(DefaultVM::Get(), -1, &year, &month, &day, &hour, &minute, &second, &milli)))
|
2016-06-05 04:08:59 +02:00
|
|
|
{
|
|
|
|
STHROWF("Invalid date and time specified");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Populate the given structure
|
|
|
|
t.year = year;
|
|
|
|
t.month = month;
|
|
|
|
t.day = day;
|
|
|
|
t.hour = hour;
|
|
|
|
t.minute = minute;
|
|
|
|
t.second = second;
|
|
|
|
t.neg = false;
|
|
|
|
t.second_part = (milli * 1000L);
|
|
|
|
t.time_type = MYSQL_TIMESTAMP_DATETIME;
|
|
|
|
}
|
2016-05-22 21:34:27 +02:00
|
|
|
|
|
|
|
} // Namespace:: SqMod
|