mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-08 12:36:43 +02:00
step, date, time
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/Data/Time.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
@@ -103,6 +105,23 @@ void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir)
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Date& val, Direction dir)
|
||||
{
|
||||
DateTime dt(val.year(), val.month(), val.day());
|
||||
std::string str(DateTimeFormatter::format(dt, Utility::SQLITE_DATE_FORMAT));
|
||||
bind(pos, str, dir);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Time& val, Direction dir)
|
||||
{
|
||||
DateTime dt;
|
||||
dt.assign(dt.year(), dt.month(), dt.day(), val.hour(), val.minute(), val.second());
|
||||
std::string str(DateTimeFormatter::format(dt, Utility::SQLITE_TIME_FORMAT));
|
||||
bind(pos, str, dir);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const DateTime& val, Direction dir)
|
||||
{
|
||||
std::string dt(DateTimeFormatter::format(val, DateTimeFormat::ISO8601_FORMAT));
|
||||
|
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "Poco/Data/SQLite/Extractor.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/Data/Time.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/DateTimeParser.h"
|
||||
@@ -205,6 +207,28 @@ bool Extractor::extract(std::size_t pos, char& val)
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Date& val)
|
||||
{
|
||||
std::string str;
|
||||
extract(pos, str);
|
||||
int tzd;
|
||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_DATE_FORMAT, str, tzd);
|
||||
val = dt;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Time& val)
|
||||
{
|
||||
std::string str;
|
||||
extract(pos, str);
|
||||
int tzd;
|
||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_TIME_FORMAT, str, tzd);
|
||||
val = dt;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, DateTime& val)
|
||||
{
|
||||
std::string dt;
|
||||
|
@@ -196,7 +196,7 @@ bool SQLiteStatementImpl::hasNext()
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::next()
|
||||
Poco::UInt32 SQLiteStatementImpl::next()
|
||||
{
|
||||
if (SQLITE_ROW == _nextResponse)
|
||||
{
|
||||
@@ -222,6 +222,8 @@ void SQLiteStatementImpl::next()
|
||||
int rc = _nextResponse;
|
||||
Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
|
||||
}
|
||||
|
||||
return 1u;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -49,6 +49,10 @@ namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const std::string Utility::SQLITE_DATE_FORMAT = "%Y-%m-%d";
|
||||
const std::string Utility::SQLITE_TIME_FORMAT = "%H:%M:%S";
|
||||
|
||||
|
||||
std::string Utility::lastError(sqlite3 *pDB)
|
||||
{
|
||||
return std::string(sqlite3_errmsg(pDB));
|
||||
@@ -76,6 +80,8 @@ MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size
|
||||
return MetaColumn::FDT_DOUBLE;
|
||||
else if (sqliteType.npos != sqliteType.find("BLOB"))
|
||||
return MetaColumn::FDT_BLOB;
|
||||
else if (sqliteType.npos != sqliteType.find("DATE"))
|
||||
return MetaColumn::FDT_TIMESTAMP;
|
||||
|
||||
throw Poco::NotFoundException();
|
||||
}
|
||||
|
Reference in New Issue
Block a user