mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
added support for Var assignment to Var-enabled types
This commit is contained in:
parent
1568abf9be
commit
d0d667af56
@ -306,6 +306,12 @@
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Date.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\DynamicDateTime.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\DynamicLOB.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Extraction.h">
|
||||
</File>
|
||||
@ -409,6 +415,9 @@
|
||||
<File
|
||||
RelativePath=".\src\Date.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DynamicLOB.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Limit.cpp">
|
||||
</File>
|
||||
|
@ -421,6 +421,14 @@
|
||||
RelativePath=".\include\Poco\Data\Date.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\DynamicDateTime.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\DynamicLOB.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Extraction.h"
|
||||
>
|
||||
@ -557,6 +565,10 @@
|
||||
RelativePath=".\src\Date.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DynamicLOB.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Limit.cpp"
|
||||
>
|
||||
|
@ -422,6 +422,14 @@
|
||||
RelativePath=".\include\Poco\Data\Date.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\DynamicDateTime.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\DynamicLOB.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Extraction.h"
|
||||
>
|
||||
@ -562,6 +570,10 @@
|
||||
RelativePath=".\src\Date.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DynamicLOB.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Limit.cpp"
|
||||
>
|
||||
|
@ -10,7 +10,7 @@ include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = AbstractBinder AbstractBinding AbstractExtraction AbstractExtractor \
|
||||
AbstractPreparation AbstractPreparator ArchiveStrategy Transaction \
|
||||
Bulk Connector DataException Date Limit MetaColumn \
|
||||
Bulk Connector DataException Date DynamicLOB Limit MetaColumn \
|
||||
PooledSessionHolder PooledSessionImpl Position \
|
||||
Range RecordSet Row RowFilter RowFormatter RowIterator \
|
||||
SimpleRowFormatter Session SessionFactory SessionImpl \
|
||||
|
@ -49,6 +49,12 @@ namespace Poco {
|
||||
|
||||
class DateTime;
|
||||
|
||||
namespace Dynamic {
|
||||
|
||||
class Var;
|
||||
|
||||
}
|
||||
|
||||
namespace Data {
|
||||
|
||||
|
||||
@ -84,9 +90,15 @@ public:
|
||||
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);
|
||||
/// Equality operator.
|
||||
|
||||
@ -127,6 +139,13 @@ inline int Date::day() const
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
@ -158,7 +177,7 @@ inline bool Date::operator > (const Date& date)
|
||||
|
||||
|
||||
//
|
||||
// VarHolderImpl<BLOB>
|
||||
// VarHolderImpl<Date>
|
||||
//
|
||||
|
||||
|
||||
|
67
Data/include/Poco/Data/DynamicDateTime.h
Normal file
67
Data/include/Poco/Data/DynamicDateTime.h
Normal file
@ -0,0 +1,67 @@
|
||||
//
|
||||
// DynamicDateTime.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/include/Poco/Data/DynamicDateTime.h#7 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: DataCore
|
||||
// Module: DynamicDateTime
|
||||
//
|
||||
// Definition of the Date and Time cast operators for Poco::Dynamic::Var.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_DynamicDateTime_INCLUDED
|
||||
#define Data_DynamicDateTime_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/Data.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
class Date;
|
||||
class Time;
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
|
||||
template <> Data_API Var::operator Poco::Data::Date () const;
|
||||
template <> Data_API Var::operator Poco::Data::Time () const;
|
||||
|
||||
|
||||
} } // namespace Poco::Dynamic
|
||||
|
||||
|
||||
#endif // Data_DynamicDateTime_INCLUDED
|
66
Data/include/Poco/Data/DynamicLOB.h
Normal file
66
Data/include/Poco/Data/DynamicLOB.h
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// DynamicLOB.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/include/Poco/Data/DynamicLOB.h#12 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: DataCore
|
||||
// Module: DynamicLOB
|
||||
//
|
||||
// Definition of the Poco::Dynamic::Var LOB cast operators.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_DynamicLOB_INCLUDED
|
||||
#define Data_DynamicLOB_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/Data.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
template <typename T> class LOB;
|
||||
typedef LOB<unsigned char> BLOB;
|
||||
typedef LOB<char> CLOB;
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
template <> Data_API Var::operator Poco::Data::CLOB () const;
|
||||
template <> Data_API Var::operator Poco::Data::BLOB () const;
|
||||
|
||||
} } // namespace Poco::Dynamic
|
||||
|
||||
|
||||
#endif // Data_DynamicLOB_INCLUDED
|
@ -47,6 +47,12 @@
|
||||
|
||||
namespace Poco {
|
||||
|
||||
namespace Dynamic {
|
||||
|
||||
class Var;
|
||||
|
||||
}
|
||||
|
||||
class DateTime;
|
||||
|
||||
namespace Data {
|
||||
@ -84,9 +90,15 @@ public:
|
||||
void assign(int hour, int minute, int second);
|
||||
/// Assigns time.
|
||||
|
||||
Time& operator = (const Time& t);
|
||||
/// Assignment operator for Time.
|
||||
|
||||
Time& operator = (const DateTime& dt);
|
||||
/// Assignment operator for DateTime.
|
||||
|
||||
Time& operator = (const Poco::Dynamic::Var& var);
|
||||
/// Assignment operator for Var.
|
||||
|
||||
bool operator == (const Time& time);
|
||||
/// Equality operator.
|
||||
|
||||
@ -127,6 +139,13 @@ inline int Time::second() const
|
||||
}
|
||||
|
||||
|
||||
inline Time& Time::operator = (const Time& t)
|
||||
{
|
||||
assign(t.hour(), t.minute(), t.second());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Time& Time::operator = (const DateTime& dt)
|
||||
{
|
||||
assign(dt.hour(), dt.minute(), dt.second());
|
||||
@ -158,7 +177,7 @@ inline bool Time::operator > (const Time& time)
|
||||
|
||||
|
||||
//
|
||||
// VarHolderImpl<BLOB>
|
||||
// VarHolderImpl<Time>
|
||||
//
|
||||
|
||||
|
||||
|
@ -37,9 +37,12 @@
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Data/DynamicDateTime.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
|
||||
|
||||
using Poco::DateTime;
|
||||
using Poco::Dynamic::Var;
|
||||
using Poco::NumberFormatter;
|
||||
|
||||
|
||||
@ -109,4 +112,39 @@ bool Date::operator < (const Date& date)
|
||||
}
|
||||
|
||||
|
||||
Date& Date::operator = (const Var& var)
|
||||
{
|
||||
*this = var.operator Date(); // g++ workaround
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
|
||||
using Poco::Data::Date;
|
||||
using Poco::DateTime;
|
||||
|
||||
|
||||
template <>
|
||||
Var::operator Date () const
|
||||
{
|
||||
if (!_pHolder)
|
||||
throw InvalidAccessException("Can not convert empty value.");
|
||||
|
||||
if (typeid(Date) == _pHolder->type())
|
||||
return extract<Date>();
|
||||
else
|
||||
{
|
||||
Poco::DateTime result;
|
||||
_pHolder->convert(result);
|
||||
return Date(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Dynamic
|
||||
|
85
Data/src/DynamicLOB.cpp
Normal file
85
Data/src/DynamicLOB.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
//
|
||||
// DynamicLOB.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/src/DynamicLOB.cpp#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: DataCore
|
||||
// Module: DynamicLOB
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/DynamicLOB.h"
|
||||
#include "Poco/Data/LOB.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
|
||||
using Poco::Data::CLOB;
|
||||
using Poco::Data::BLOB;
|
||||
|
||||
|
||||
template <>
|
||||
Var::operator CLOB () const
|
||||
{
|
||||
if (!_pHolder)
|
||||
throw InvalidAccessException("Can not convert empty value.");
|
||||
|
||||
if (typeid(CLOB) == _pHolder->type())
|
||||
return extract<CLOB>();
|
||||
else
|
||||
{
|
||||
std::string result;
|
||||
_pHolder->convert(result);
|
||||
return CLOB(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
Var::operator BLOB () const
|
||||
{
|
||||
if (!_pHolder)
|
||||
throw InvalidAccessException("Can not convert empty value.");
|
||||
|
||||
if (typeid(BLOB) == _pHolder->type())
|
||||
return extract<BLOB>();
|
||||
else
|
||||
{
|
||||
std::string result;
|
||||
_pHolder->convert(result);
|
||||
return BLOB(reinterpret_cast<const unsigned char*>(result.data()),
|
||||
result.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
@ -35,10 +35,13 @@
|
||||
|
||||
|
||||
#include "Poco/Data/Time.h"
|
||||
#include "Poco/Data/DynamicDateTime.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
|
||||
|
||||
using Poco::DateTime;
|
||||
using Poco::Dynamic::Var;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -106,4 +109,39 @@ bool Time::operator < (const Time& time)
|
||||
}
|
||||
|
||||
|
||||
Time& Time::operator = (const Var& var)
|
||||
{
|
||||
*this = var.operator Time(); // g++ workaround
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
|
||||
using Poco::Data::Time;
|
||||
using Poco::DateTime;
|
||||
|
||||
|
||||
template <>
|
||||
Var::operator Time () const
|
||||
{
|
||||
if (!_pHolder)
|
||||
throw InvalidAccessException("Can not convert empty value.");
|
||||
|
||||
if (typeid(Time) == _pHolder->type())
|
||||
return extract<Time>();
|
||||
else
|
||||
{
|
||||
Poco::DateTime result;
|
||||
_pHolder->convert(result);
|
||||
return Time(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Dynamic
|
||||
|
@ -49,6 +49,8 @@
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/Types.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/Data/DynamicLOB.h"
|
||||
#include "Poco/Data/DynamicDateTime.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
@ -318,6 +320,16 @@ void DataTest::testCLOB()
|
||||
assert (blobNumStr == blobChrVec);
|
||||
std::swap(blobNumStr, blobChrVec);
|
||||
assert (blobNumStr == blobChrVec);
|
||||
|
||||
assert (blobChrStr != blobNumStr);
|
||||
Var vLOB = blobNumStr;
|
||||
blobChrStr = vLOB;
|
||||
assert (blobChrStr == blobNumStr);
|
||||
|
||||
std::string xyz = "xyz";
|
||||
vLOB = xyz;
|
||||
blobChrStr = vLOB;
|
||||
assert (0 == std::strncmp(xyz.c_str(), blobChrStr.rawContent(), blobChrStr.size()));
|
||||
}
|
||||
|
||||
|
||||
@ -1306,6 +1318,20 @@ void DataTest::testDateAndTime()
|
||||
|
||||
t1 = dt;
|
||||
assert (t1 == dt);
|
||||
|
||||
d.assign(2007, 6, 15);
|
||||
d1.assign(2007, 6, 16);
|
||||
assert (d != d1);
|
||||
Var vDate = d;
|
||||
d1 = vDate;
|
||||
assert (d == d1);
|
||||
|
||||
t.assign(12, 30, 15);
|
||||
t1.assign(12, 30, 16);
|
||||
assert (t != t1);
|
||||
Var vTime = t;
|
||||
t1 = vTime;
|
||||
assert (t == t1);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user