mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 02:03:04 +01:00
Added encode/decode date/time methods to IUtil interface.
This commit is contained in:
parent
2a857cb415
commit
4647d5b78f
@ -26,7 +26,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
struct ISC_DATE;
|
||||
struct ISC_QUAD;
|
||||
struct ISC_TIME;
|
||||
struct FbCryptKey;
|
||||
|
||||
// Versioned interface - base for all FB interfaces
|
||||
@ -912,6 +914,10 @@ interface Util : Versioned
|
||||
Attachment executeCreateDatabase(Status status,
|
||||
uint stmtLength, const string creatDBstatement, uint dialect,
|
||||
boolean* stmtIsCreateDb);
|
||||
void decodeDate(ISC_DATE date, uint* year, uint* month, uint* day);
|
||||
void decodeTime(ISC_TIME time, uint* hours, uint* minutes, uint* seconds, uint* fractions);
|
||||
ISC_DATE encodeDate(uint year, uint month, uint day);
|
||||
ISC_TIME encodeTime(uint hours, uint minutes, uint seconds, uint fractions);
|
||||
}
|
||||
|
||||
// Database trace objects
|
||||
|
@ -3235,6 +3235,10 @@ namespace Firebird
|
||||
void (CLOOP_CARG *dumpBlob)(IUtil* self, IStatus* status, ISC_QUAD* blobId, IAttachment* att, ITransaction* tra, const char* file, FB_BOOLEAN txt) throw();
|
||||
void (CLOOP_CARG *getPerfCounters)(IUtil* self, IStatus* status, IAttachment* att, const char* countersSet, ISC_INT64* counters) throw();
|
||||
IAttachment* (CLOOP_CARG *executeCreateDatabase)(IUtil* self, IStatus* status, unsigned stmtLength, const char* creatDBstatement, unsigned dialect, FB_BOOLEAN* stmtIsCreateDb) throw();
|
||||
void (CLOOP_CARG *decodeDate)(IUtil* self, ISC_DATE date, unsigned* year, unsigned* month, unsigned* day) throw();
|
||||
void (CLOOP_CARG *decodeTime)(IUtil* self, ISC_TIME time, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions) throw();
|
||||
ISC_DATE (CLOOP_CARG *encodeDate)(IUtil* self, unsigned year, unsigned month, unsigned day) throw();
|
||||
ISC_TIME (CLOOP_CARG *encodeTime)(IUtil* self, unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions) throw();
|
||||
};
|
||||
|
||||
protected:
|
||||
@ -3280,6 +3284,28 @@ namespace Firebird
|
||||
StatusType::checkException(status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void decodeDate(ISC_DATE date, unsigned* year, unsigned* month, unsigned* day)
|
||||
{
|
||||
static_cast<VTable*>(this->cloopVTable)->decodeDate(this, date, year, month, day);
|
||||
}
|
||||
|
||||
void decodeTime(ISC_TIME time, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions)
|
||||
{
|
||||
static_cast<VTable*>(this->cloopVTable)->decodeTime(this, time, hours, minutes, seconds, fractions);
|
||||
}
|
||||
|
||||
ISC_DATE encodeDate(unsigned year, unsigned month, unsigned day)
|
||||
{
|
||||
ISC_DATE ret = static_cast<VTable*>(this->cloopVTable)->encodeDate(this, year, month, day);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ISC_TIME encodeTime(unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions)
|
||||
{
|
||||
ISC_TIME ret = static_cast<VTable*>(this->cloopVTable)->encodeTime(this, hours, minutes, seconds, fractions);
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
class ITraceConnection : public IVersioned
|
||||
@ -11688,6 +11714,10 @@ namespace Firebird
|
||||
this->dumpBlob = &Name::cloopdumpBlobDispatcher;
|
||||
this->getPerfCounters = &Name::cloopgetPerfCountersDispatcher;
|
||||
this->executeCreateDatabase = &Name::cloopexecuteCreateDatabaseDispatcher;
|
||||
this->decodeDate = &Name::cloopdecodeDateDispatcher;
|
||||
this->decodeTime = &Name::cloopdecodeTimeDispatcher;
|
||||
this->encodeDate = &Name::cloopencodeDateDispatcher;
|
||||
this->encodeTime = &Name::cloopencodeTimeDispatcher;
|
||||
}
|
||||
} vTable;
|
||||
|
||||
@ -11764,6 +11794,56 @@ namespace Firebird
|
||||
return static_cast<IAttachment*>(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void CLOOP_CARG cloopdecodeDateDispatcher(IUtil* self, ISC_DATE date, unsigned* year, unsigned* month, unsigned* day) throw()
|
||||
{
|
||||
try
|
||||
{
|
||||
static_cast<Name*>(self)->Name::decodeDate(date, year, month, day);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
StatusType::catchException(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void CLOOP_CARG cloopdecodeTimeDispatcher(IUtil* self, ISC_TIME time, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions) throw()
|
||||
{
|
||||
try
|
||||
{
|
||||
static_cast<Name*>(self)->Name::decodeTime(time, hours, minutes, seconds, fractions);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
StatusType::catchException(0);
|
||||
}
|
||||
}
|
||||
|
||||
static ISC_DATE CLOOP_CARG cloopencodeDateDispatcher(IUtil* self, unsigned year, unsigned month, unsigned day) throw()
|
||||
{
|
||||
try
|
||||
{
|
||||
return static_cast<Name*>(self)->Name::encodeDate(year, month, day);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
StatusType::catchException(0);
|
||||
return static_cast<ISC_DATE>(0);
|
||||
}
|
||||
}
|
||||
|
||||
static ISC_TIME CLOOP_CARG cloopencodeTimeDispatcher(IUtil* self, unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions) throw()
|
||||
{
|
||||
try
|
||||
{
|
||||
return static_cast<Name*>(self)->Name::encodeTime(hours, minutes, seconds, fractions);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
StatusType::catchException(0);
|
||||
return static_cast<ISC_TIME>(0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Name, typename StatusType, typename Base = IVersionedImpl<Name, StatusType, Inherit<IUtil> > >
|
||||
@ -11784,6 +11864,10 @@ namespace Firebird
|
||||
virtual void dumpBlob(StatusType* status, ISC_QUAD* blobId, IAttachment* att, ITransaction* tra, const char* file, FB_BOOLEAN txt) = 0;
|
||||
virtual void getPerfCounters(StatusType* status, IAttachment* att, const char* countersSet, ISC_INT64* counters) = 0;
|
||||
virtual IAttachment* executeCreateDatabase(StatusType* status, unsigned stmtLength, const char* creatDBstatement, unsigned dialect, FB_BOOLEAN* stmtIsCreateDb) = 0;
|
||||
virtual void decodeDate(ISC_DATE date, unsigned* year, unsigned* month, unsigned* day) = 0;
|
||||
virtual void decodeTime(ISC_TIME time, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions) = 0;
|
||||
virtual ISC_DATE encodeDate(unsigned year, unsigned month, unsigned day) = 0;
|
||||
virtual ISC_TIME encodeTime(unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions) = 0;
|
||||
};
|
||||
|
||||
template <typename Name, typename StatusType, typename Base>
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "./Interface.h"
|
||||
#include "./impl/boost/preprocessor/seq/for_each_i.hpp"
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FB_MESSAGE(name, fields) \
|
||||
@ -240,48 +239,35 @@ struct FbVarChar
|
||||
class FbDate
|
||||
{
|
||||
public:
|
||||
void decode(unsigned* year, unsigned* month, unsigned* day) const
|
||||
void decode(IUtil* util, unsigned* year, unsigned* month, unsigned* day) const
|
||||
{
|
||||
tm times;
|
||||
isc_decode_sql_date(&value, ×);
|
||||
|
||||
if (year)
|
||||
*year = times.tm_year + 1900;
|
||||
if (month)
|
||||
*month = times.tm_mon + 1;
|
||||
if (day)
|
||||
*day = times.tm_mday;
|
||||
util->decodeDate(value, year, month, day);
|
||||
}
|
||||
|
||||
unsigned getYear() const
|
||||
unsigned getYear(IUtil* util) const
|
||||
{
|
||||
unsigned year;
|
||||
decode(&year, NULL, NULL);
|
||||
decode(util, &year, NULL, NULL);
|
||||
return year;
|
||||
}
|
||||
|
||||
unsigned getMonth() const
|
||||
unsigned getMonth(IUtil* util) const
|
||||
{
|
||||
unsigned month;
|
||||
decode(NULL, &month, NULL);
|
||||
decode(util, NULL, &month, NULL);
|
||||
return month;
|
||||
}
|
||||
|
||||
unsigned getDay() const
|
||||
unsigned getDay(IUtil* util) const
|
||||
{
|
||||
unsigned day;
|
||||
decode(NULL, NULL, &day);
|
||||
decode(util, NULL, NULL, &day);
|
||||
return day;
|
||||
}
|
||||
|
||||
void encode(unsigned year, unsigned month, unsigned day)
|
||||
void encode(IUtil* util, unsigned year, unsigned month, unsigned day)
|
||||
{
|
||||
tm times;
|
||||
times.tm_year = year - 1900;
|
||||
times.tm_mon = month - 1;
|
||||
times.tm_mday = day;
|
||||
|
||||
isc_encode_sql_date(×, &value);
|
||||
value = util->encodeDate(year, month, day);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -292,58 +278,43 @@ public:
|
||||
class FbTime
|
||||
{
|
||||
public:
|
||||
void decode(unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions) const
|
||||
void decode(IUtil* util, unsigned* hours, unsigned* minutes, unsigned* seconds,
|
||||
unsigned* fractions) const
|
||||
{
|
||||
tm times;
|
||||
isc_decode_sql_time(&value, ×);
|
||||
|
||||
if (hours)
|
||||
*hours = times.tm_hour;
|
||||
if (minutes)
|
||||
*minutes = times.tm_min;
|
||||
if (seconds)
|
||||
*seconds = times.tm_sec;
|
||||
if (fractions)
|
||||
*fractions = value % ISC_TIME_SECONDS_PRECISION;
|
||||
util->decodeTime(value, hours, minutes, seconds, fractions);
|
||||
}
|
||||
|
||||
unsigned getHours() const
|
||||
unsigned getHours(IUtil* util) const
|
||||
{
|
||||
unsigned hours;
|
||||
decode(&hours, NULL, NULL, NULL);
|
||||
decode(util, &hours, NULL, NULL, NULL);
|
||||
return hours;
|
||||
}
|
||||
|
||||
unsigned getMinutes() const
|
||||
unsigned getMinutes(IUtil* util) const
|
||||
{
|
||||
unsigned minutes;
|
||||
decode(NULL, &minutes, NULL, NULL);
|
||||
decode(util, NULL, &minutes, NULL, NULL);
|
||||
return minutes;
|
||||
}
|
||||
|
||||
unsigned getSeconds() const
|
||||
unsigned getSeconds(IUtil* util) const
|
||||
{
|
||||
unsigned seconds;
|
||||
decode(NULL, NULL, &seconds, NULL);
|
||||
decode(util, NULL, NULL, &seconds, NULL);
|
||||
return seconds;
|
||||
}
|
||||
|
||||
unsigned getFractions() const
|
||||
unsigned getFractions(IUtil* util) const
|
||||
{
|
||||
unsigned fractions;
|
||||
decode(NULL, NULL, NULL, &fractions);
|
||||
decode(util, NULL, NULL, NULL, &fractions);
|
||||
return fractions;
|
||||
}
|
||||
|
||||
void encode(unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions)
|
||||
void encode(IUtil* util, unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions)
|
||||
{
|
||||
tm times;
|
||||
times.tm_hour = hours;
|
||||
times.tm_min = minutes;
|
||||
times.tm_sec = seconds;
|
||||
|
||||
isc_encode_sql_time(×, &value);
|
||||
value += fractions;
|
||||
value = util->encodeTime(hours, minutes, seconds, fractions);
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -552,6 +552,11 @@ public:
|
||||
YAttachment* executeCreateDatabase(Firebird::CheckStatusWrapper* status,
|
||||
unsigned stmtLength, const char* creatDBstatement, unsigned dialect,
|
||||
FB_BOOLEAN* stmtIsCreateDb = NULL);
|
||||
void decodeDate(ISC_DATE date, unsigned* year, unsigned* month, unsigned* day);
|
||||
void decodeTime(ISC_TIME time,
|
||||
unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions);
|
||||
ISC_DATE encodeDate(unsigned year, unsigned month, unsigned day);
|
||||
ISC_TIME encodeTime(unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions);
|
||||
};
|
||||
|
||||
} // namespace Why
|
||||
|
@ -630,6 +630,63 @@ YAttachment* UtilInterface::executeCreateDatabase(
|
||||
}
|
||||
}
|
||||
|
||||
void UtilInterface::decodeDate(ISC_DATE date, unsigned* year, unsigned* month, unsigned* day)
|
||||
{
|
||||
tm times;
|
||||
isc_decode_sql_date(&date, ×);
|
||||
|
||||
if (year)
|
||||
*year = times.tm_year + 1900;
|
||||
if (month)
|
||||
*month = times.tm_mon + 1;
|
||||
if (day)
|
||||
*day = times.tm_mday;
|
||||
}
|
||||
|
||||
void UtilInterface::decodeTime(ISC_TIME time,
|
||||
unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions)
|
||||
{
|
||||
tm times;
|
||||
isc_decode_sql_time(&time, ×);
|
||||
|
||||
if (hours)
|
||||
*hours = times.tm_hour;
|
||||
if (minutes)
|
||||
*minutes = times.tm_min;
|
||||
if (seconds)
|
||||
*seconds = times.tm_sec;
|
||||
if (fractions)
|
||||
*fractions = time % ISC_TIME_SECONDS_PRECISION;
|
||||
}
|
||||
|
||||
ISC_DATE UtilInterface::encodeDate(unsigned year, unsigned month, unsigned day)
|
||||
{
|
||||
tm times;
|
||||
times.tm_year = year - 1900;
|
||||
times.tm_mon = month - 1;
|
||||
times.tm_mday = day;
|
||||
|
||||
ISC_DATE date;
|
||||
isc_encode_sql_date(×, &date);
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
ISC_TIME UtilInterface::encodeTime(unsigned hours, unsigned minutes, unsigned seconds,
|
||||
unsigned fractions)
|
||||
{
|
||||
tm times;
|
||||
times.tm_hour = hours;
|
||||
times.tm_min = minutes;
|
||||
times.tm_sec = seconds;
|
||||
|
||||
ISC_TIME time;
|
||||
isc_encode_sql_time(×, &time);
|
||||
time += fractions;
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
} // namespace Why
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user