mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
synced 2026-01-12 15:15:20 +00:00
* remove leftover progen files * remove Data sources and turn headers into forwards * add SQL files #2059 * Data2sql: adjust Travis, AppVeyor & Makefiles (#2069) * Replace Data by SQL * Replace Data by SQL * Replace Data by SQL * Replace Data by SQL * fix header forwarding * Data2sql: Fixes for complete Travis CI success (#2071) * Replace Data by SQL * Replace Data by SQL * Replace Data by SQL * Replace Data by SQL * Replace Data by SQL * Restore DataFormatException * Replace Data by SQL * Replace Data by SQL * Replace Data by SQL * Replace Data by SQL * construct RowFilter from RecordSet reference instead of pointer * pass Container ref instead of ptr to Column * elimitate g++ warnings * SQL: remove raw pointers from interfaces #2094; add constness and move ops where appropriate * tidy up Postgres * ODBC fixes
241 lines
3.5 KiB
C++
241 lines
3.5 KiB
C++
//
|
|
// Date.h
|
|
//
|
|
// Library: Data
|
|
// Package: DataCore
|
|
// Module: Date
|
|
//
|
|
// Definition of the Date class.
|
|
//
|
|
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
|
// and Contributors.
|
|
//
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
//
|
|
|
|
|
|
#ifndef SQL_Date_INCLUDED
|
|
#define SQL_Date_INCLUDED
|
|
|
|
|
|
#include "Poco/SQL/SQL.h"
|
|
#include "Poco/Dynamic/VarHolder.h"
|
|
#include "Poco/Exception.h"
|
|
|
|
|
|
namespace Poco {
|
|
|
|
class DateTime;
|
|
|
|
namespace Dynamic {
|
|
|
|
class Var;
|
|
|
|
}
|
|
|
|
namespace SQL {
|
|
|
|
|
|
class Time;
|
|
|
|
|
|
class Poco_SQL_API Date
|
|
/// Date class wraps a DateTime and exposes date related interface.
|
|
/// The purpose of this class is binding/extraction support for date fields.
|
|
{
|
|
public:
|
|
Date();
|
|
/// Creates the Date
|
|
|
|
Date(int year, int month, int day);
|
|
/// Creates the Date
|
|
|
|
Date(const DateTime& dt);
|
|
/// Creates the Date from DateTime
|
|
|
|
~Date();
|
|
/// Destroys the Date.
|
|
|
|
int year() const;
|
|
/// Returns the year.
|
|
|
|
int month() const;
|
|
/// Returns the month.
|
|
|
|
int day() const;
|
|
/// Returns the day.
|
|
|
|
void assign(int year, int month, int day);
|
|
/// Assigns date.
|
|
|
|
Date& operator = (const Date& d);
|
|
/// Assignment operator for Date.
|
|
|
|
Date& operator = (const DateTime& dt);
|
|
/// Assignment operator for DateTime.
|
|
|
|
Date& operator = (const Poco::Dynamic::Var& var);
|
|
/// Assignment operator for Var.
|
|
|
|
bool operator == (const Date& date) const;
|
|
/// Equality operator.
|
|
|
|
bool operator != (const Date& date) const;
|
|
/// Inequality operator.
|
|
|
|
bool operator < (const Date& date) const;
|
|
/// Less then operator.
|
|
|
|
bool operator > (const Date& date) const;
|
|
/// Greater then operator.
|
|
|
|
private:
|
|
int _year;
|
|
int _month;
|
|
int _day;
|
|
};
|
|
|
|
|
|
//
|
|
// inlines
|
|
//
|
|
inline int Date::year() const
|
|
{
|
|
return _year;
|
|
}
|
|
|
|
|
|
inline int Date::month() const
|
|
{
|
|
return _month;
|
|
}
|
|
|
|
|
|
inline int Date::day() const
|
|
{
|
|
return _day;
|
|
}
|
|
|
|
|
|
inline Date& Date::operator = (const Date& d)
|
|
{
|
|
assign(d.year(), d.month(), d.day());
|
|
return *this;
|
|
}
|
|
|
|
|
|
inline Date& Date::operator = (const DateTime& dt)
|
|
{
|
|
assign(dt.year(), dt.month(), dt.day());
|
|
return *this;
|
|
}
|
|
|
|
|
|
inline bool Date::operator == (const Date& date) const
|
|
{
|
|
return _year == date.year() &&
|
|
_month == date.month() &&
|
|
_day == date.day();
|
|
}
|
|
|
|
|
|
inline bool Date::operator != (const Date& date) const
|
|
{
|
|
return !(*this == date);
|
|
}
|
|
|
|
|
|
inline bool Date::operator > (const Date& date) const
|
|
{
|
|
return !(*this == date) && !(*this < date);
|
|
}
|
|
|
|
|
|
} } // namespace Poco::SQL
|
|
|
|
|
|
//
|
|
// VarHolderImpl<Date>
|
|
//
|
|
|
|
|
|
namespace Poco {
|
|
namespace Dynamic {
|
|
|
|
|
|
template <>
|
|
class VarHolderImpl<Poco::SQL::Date>: public VarHolder
|
|
{
|
|
public:
|
|
VarHolderImpl(const Poco::SQL::Date& val): _val(val)
|
|
{
|
|
}
|
|
|
|
~VarHolderImpl()
|
|
{
|
|
}
|
|
|
|
const std::type_info& type() const
|
|
{
|
|
return typeid(Poco::SQL::Date);
|
|
}
|
|
|
|
void convert(Poco::Timestamp& val) const
|
|
{
|
|
DateTime dt;
|
|
dt.assign(_val.year(), _val.month(), _val.day());
|
|
val = dt.timestamp();
|
|
}
|
|
|
|
void convert(Poco::DateTime& val) const
|
|
{
|
|
val.assign(_val.year(), _val.month(), _val.day());
|
|
}
|
|
|
|
void convert(Poco::LocalDateTime& val) const
|
|
{
|
|
val.assign(_val.year(), _val.month(), _val.day());
|
|
}
|
|
|
|
void convert(std::string& val) const
|
|
{
|
|
DateTime dt(_val.year(), _val.month(), _val.day());
|
|
val = DateTimeFormatter::format(dt, "%Y/%m/%d");
|
|
}
|
|
|
|
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
|
|
{
|
|
return cloneHolder(pVarHolder, _val);
|
|
}
|
|
|
|
const Poco::SQL::Date& value() const
|
|
{
|
|
return _val;
|
|
}
|
|
|
|
bool isDate() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool isTime() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool isDateTime() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
private:
|
|
VarHolderImpl();
|
|
Poco::SQL::Date _val;
|
|
};
|
|
|
|
|
|
} } // namespace Poco::Dynamic
|
|
|
|
|
|
#endif // Data_Date_INCLUDED
|