2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-07-23 11:02:47 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "db_ido/dbvalue.hpp"
|
2013-07-23 11:02:47 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
DbValue::DbValue(DbValueType type, Value value)
|
|
|
|
: m_Type(type), m_Value(std::move(value))
|
2013-07-23 11:02:47 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
Value DbValue::FromTimestamp(const Value& ts)
|
|
|
|
{
|
|
|
|
if (ts.IsEmpty() || ts == 0)
|
|
|
|
return Empty;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
return new DbValue(DbValueTimestamp, ts);
|
2013-07-23 11:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value DbValue::FromValue(const Value& value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-08-02 15:20:28 +02:00
|
|
|
Value DbValue::FromObjectInsertID(const Value& value)
|
|
|
|
{
|
2014-11-08 21:17:16 +01:00
|
|
|
return new DbValue(DbValueObjectInsertID, value);
|
2013-08-02 15:20:28 +02:00
|
|
|
}
|
|
|
|
|
2013-07-23 11:02:47 +02:00
|
|
|
bool DbValue::IsTimestamp(const Value& value)
|
|
|
|
{
|
|
|
|
if (!value.IsObjectType<DbValue>())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DbValue::Ptr dbv = value;
|
|
|
|
return dbv->GetType() == DbValueTimestamp;
|
|
|
|
}
|
|
|
|
|
2013-08-02 15:20:28 +02:00
|
|
|
bool DbValue::IsObjectInsertID(const Value& value)
|
|
|
|
{
|
|
|
|
if (!value.IsObjectType<DbValue>())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DbValue::Ptr dbv = value;
|
|
|
|
return dbv->GetType() == DbValueObjectInsertID;
|
|
|
|
}
|
|
|
|
|
2013-07-23 11:02:47 +02:00
|
|
|
Value DbValue::ExtractValue(const Value& value)
|
|
|
|
{
|
|
|
|
if (!value.IsObjectType<DbValue>())
|
|
|
|
return value;
|
|
|
|
|
|
|
|
DbValue::Ptr dbv = value;
|
|
|
|
return dbv->GetValue();
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
DbValueType DbValue::GetType() const
|
2013-07-23 11:02:47 +02:00
|
|
|
{
|
|
|
|
return m_Type;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Value DbValue::GetValue() const
|
2013-07-23 11:02:47 +02:00
|
|
|
{
|
|
|
|
return m_Value;
|
|
|
|
}
|
2016-03-21 13:37:32 +01:00
|
|
|
|
|
|
|
void DbValue::SetValue(const Value& value)
|
|
|
|
{
|
|
|
|
m_Value = value;
|
|
|
|
}
|