step, date, time

This commit is contained in:
Aleksandar Fabijanic
2007-11-10 23:21:28 +00:00
parent 95c5230389
commit fca08a18df
63 changed files with 2161 additions and 96 deletions

112
Data/src/Date.cpp Normal file
View File

@@ -0,0 +1,112 @@
//
// Date.cpp
//
// $Id: //poco/Main/Data/src/Date.cpp#5 $
//
// Library: Data
// Package: DataCore
// Module: Date
//
// 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/Date.h"
#include "Poco/DateTime.h"
#include "Poco/NumberFormatter.h"
using Poco::DateTime;
using Poco::NumberFormatter;
namespace Poco {
namespace Data {
Date::Date()
{
DateTime dt;
assign(dt.year(), dt.month(), dt.day());
}
Date::Date(int year, int month, int day)
{
assign(year, month, day);
}
Date::Date(const DateTime& dt)
{
assign(dt.year(), dt.month(), dt.day());
}
Date::~Date()
{
}
void Date::assign(int year, int month, int day)
{
if (year < 0 || year > 9999)
throw InvalidArgumentException("Year must be between 0 and 9999");
if (month < 1 || month > 12)
throw InvalidArgumentException("Month must be between 1 and 12");
if (day < 1 || day > DateTime::daysOfMonth(year, month))
throw InvalidArgumentException("Month must be between 1 and " +
NumberFormatter::format(DateTime::daysOfMonth(year, month)));
_year = year;
_month = month;
_day = day;
}
bool Date::operator < (const Date& date)
{
int year = date.year();
if (_year < year) return true;
else if (_year > year) return false;
else // years equal
{
int month = date.month();
if (_month < month) return true;
else
if (_month > month) return false;
else // months equal
if (_day < date.day()) return true;
}
return false;
}
} } // namespace Poco::Data

View File

@@ -36,6 +36,8 @@
#include "Poco/Data/RecordSet.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/Time.h"
#include "Poco/Data/DataException.h"
#include "Poco/DateTime.h"
@@ -94,6 +96,8 @@ DynamicAny RecordSet::value(std::size_t col, std::size_t row) const
case MetaColumn::FDT_DOUBLE: return value<double>(col, row);
case MetaColumn::FDT_STRING: return value<std::string>(col, row);
case MetaColumn::FDT_BLOB: return value<BLOB>(col, row);
case MetaColumn::FDT_DATE: return value<Date>(col, row);
case MetaColumn::FDT_TIME: return value<Time>(col, row);
case MetaColumn::FDT_TIMESTAMP: return value<DateTime>(col, row);
default:
throw UnknownTypeException("Data type not supported.");
@@ -118,6 +122,8 @@ DynamicAny RecordSet::value(const std::string& name, std::size_t row) const
case MetaColumn::FDT_DOUBLE: return value<double>(name, row);
case MetaColumn::FDT_STRING: return value<std::string>(name, row);
case MetaColumn::FDT_BLOB: return value<BLOB>(name, row);
case MetaColumn::FDT_DATE: return value<Date>(name, row);
case MetaColumn::FDT_TIME: return value<Time>(name, row);
case MetaColumn::FDT_TIMESTAMP: return value<DateTime>(name, row);
default:
throw UnknownTypeException("Data type not supported.");

View File

@@ -40,6 +40,8 @@
#include "Poco/Data/AbstractBinder.h"
#include "Poco/Data/Extraction.h"
#include "Poco/Data/BLOB.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/Time.h"
#include "Poco/SharedPtr.h"
#include "Poco/DateTime.h"
#include "Poco/Exception.h"
@@ -67,7 +69,8 @@ StatementImpl::StatementImpl(SessionImpl& rSession):
_storage(STORAGE_UNKNOWN_IMPL),
_ostr(),
_bindings(),
_curDataSet(0)
_curDataSet(0),
_step(1u)
{
_extractors.resize(1);
}
@@ -107,10 +110,7 @@ Poco::UInt32 StatementImpl::executeWithLimit()
{
bind();
while (hasNext() && count < _extrLimit.value())
{
next();
++count;
}
count += next();
} while (canBind());
if (!canBind() && (!hasNext() || _extrLimit.value() == 0))
@@ -132,11 +132,7 @@ Poco::UInt32 StatementImpl::executeWithoutLimit()
do
{
bind();
while (hasNext())
{
next();
++count;
}
while (hasNext()) count += next();
} while (canBind());
_state = ST_DONE;
@@ -312,6 +308,10 @@ void StatementImpl::makeExtractors(Poco::UInt32 count)
addInternalExtract<std::string>(mc); break;
case MetaColumn::FDT_BLOB:
addInternalExtract<BLOB>(mc); break;
case MetaColumn::FDT_DATE:
addInternalExtract<Date>(mc); break;
case MetaColumn::FDT_TIME:
addInternalExtract<Time>(mc); break;
case MetaColumn::FDT_TIMESTAMP:
addInternalExtract<DateTime>(mc); break;
default:

55
Data/src/Step.cpp Normal file
View File

@@ -0,0 +1,55 @@
//
// Step.cpp
//
// $Id: //poco/Main/Data/src/Step.cpp#5 $
//
// Library: Data
// Package: DataCore
// Module: Step
//
// 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/Step.h"
namespace Poco {
namespace Data {
Step::Step(Poco::UInt32 value):
_value(value)
{
}
Step::~Step()
{
}
} } // namespace Poco::Data

109
Data/src/Time.cpp Normal file
View File

@@ -0,0 +1,109 @@
//
// Time.cpp
//
// $Id: //poco/Main/Data/src/Time.cpp#5 $
//
// Library: Data
// Package: DataCore
// Module: Time
//
// 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/Time.h"
#include "Poco/DateTime.h"
using Poco::DateTime;
namespace Poco {
namespace Data {
Time::Time()
{
DateTime dt;
assign(dt.hour(), dt.minute(), dt.second());
}
Time::Time(int hour, int minute, int second)
{
assign(hour, minute, second);
}
Time::Time(const DateTime& dt)
{
assign(dt.hour(), dt.minute(), dt.second());
}
Time::~Time()
{
}
void Time::assign(int hour, int minute, int second)
{
if (hour < 0 || hour > 23)
throw InvalidArgumentException("Hour must be between 0 and 23.");
if (minute < 0 || minute > 59)
throw InvalidArgumentException("Minute must be between 0 and 59.");
if (second < 0 || second > 59)
throw InvalidArgumentException("Second must be between 0 and 59.");
_hour = hour;
_minute = minute;
_second = second;
}
bool Time::operator < (const Time& time)
{
int hour = time.hour();
if (_hour < hour) return true;
else if (_hour > hour) return false;
else // hours equal
{
int minute = time.minute();
if (_minute < minute) return true;
else
if (_minute > minute) return false;
else // minutes equal
if (_second < time.second()) return true;
}
return false;
}
} } // namespace Poco::Data