mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 10:32:57 +01:00
change RowFormatter* to RowFormatterPtr
Modified all uses of RowFormatter pointer to SharedPtr (RowFormatterPtr)
This commit is contained in:
parent
a3873cbb5f
commit
1021b792b7
@ -98,21 +98,39 @@ public:
|
||||
static const std::size_t UNKNOWN_TOTAL_ROW_COUNT;
|
||||
|
||||
explicit RecordSet(const Statement& rStatement,
|
||||
RowFormatter* pRowFormatter = 0);
|
||||
RowFormatterPtr pRowFormatter = 0);
|
||||
/// Creates the RecordSet.
|
||||
|
||||
explicit RecordSet(Session& rSession,
|
||||
const std::string& query,
|
||||
RowFormatter* pRowFormatter = 0);
|
||||
RowFormatterPtr pRowFormatter = 0);
|
||||
/// Creates the RecordSet.
|
||||
|
||||
explicit RecordSet(Session& rSession,
|
||||
const std::string& query,
|
||||
const RowFormatter& rowFormatter);
|
||||
/// Creates the RecordSet.
|
||||
|
||||
template <class RF>
|
||||
RecordSet(Session& rSession, const std::string& query, const RF& rowFormatter):
|
||||
Statement((rSession << query, now)),
|
||||
_currentRow(0),
|
||||
_pBegin(new RowIterator(this, 0 == rowsExtracted())),
|
||||
_pEnd(new RowIterator(this, true)),
|
||||
_pFilter(0),
|
||||
_totalRowCount(UNKNOWN_TOTAL_ROW_COUNT)
|
||||
/// Creates the RecordSet.
|
||||
{
|
||||
setRowFormatter(Keywords::format(rowFormatter));
|
||||
}
|
||||
|
||||
RecordSet(const RecordSet& other);
|
||||
/// Copy-creates the recordset.
|
||||
|
||||
~RecordSet();
|
||||
/// Destroys the RecordSet.
|
||||
|
||||
void setRowFormatter(RowFormatter* pRowFormatter);
|
||||
void setRowFormatter(RowFormatterPtr pRowFormatter);
|
||||
/// Assigns the row formatter to the statement and all recordset rows.
|
||||
|
||||
Statement& operator = (const Statement& stmt);
|
||||
|
@ -232,13 +232,15 @@ inline void RowFormatter::setMode(Mode mode)
|
||||
}
|
||||
|
||||
|
||||
typedef SharedPtr<RowFormatter> RowFormatterPtr;
|
||||
|
||||
|
||||
namespace Keywords {
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline T* format(const T& formatter)
|
||||
inline RowFormatterPtr format(const T& formatter)
|
||||
/// Utility function used to pass formatter to the statement.
|
||||
/// Statement takes the ownership of the formatter.
|
||||
{
|
||||
return new T(formatter);
|
||||
}
|
||||
@ -247,9 +249,6 @@ inline T* format(const T& formatter)
|
||||
} // namespace Keywords
|
||||
|
||||
|
||||
typedef SharedPtr<RowFormatter> RowFormatterPtr;
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
|
@ -250,7 +250,7 @@ public:
|
||||
///
|
||||
/// Set per default to zero to Limit::LIMIT_UNLIMITED, which disables the limit.
|
||||
|
||||
Statement& operator , (RowFormatter* pRowFformatter);
|
||||
Statement& operator , (RowFormatterPtr pRowFformatter);
|
||||
/// Sets the row formatter for the statement.
|
||||
|
||||
Statement& operator , (const Range& extrRange);
|
||||
@ -401,7 +401,7 @@ public:
|
||||
/// Returns false if the current data set index points to the last
|
||||
/// data set. Otherwise, it returns true.
|
||||
|
||||
void setRowFormatter(RowFormatter* pRowFormatter);
|
||||
void setRowFormatter(RowFormatterPtr pRowFormatter);
|
||||
/// Sets the row formatter for this statement.
|
||||
/// Statement takes the ownership of the formatter.
|
||||
|
||||
@ -545,7 +545,7 @@ inline void Data_API reset(Statement& statement)
|
||||
// inlines
|
||||
//
|
||||
|
||||
inline Statement& Statement::operator , (RowFormatter* pRowFformatter)
|
||||
inline Statement& Statement::operator , (RowFormatterPtr pRowFformatter)
|
||||
{
|
||||
_pRowFormatter = pRowFformatter;
|
||||
return *this;
|
||||
@ -811,7 +811,7 @@ inline bool Statement::isAsync() const
|
||||
}
|
||||
|
||||
|
||||
inline void Statement::setRowFormatter(RowFormatter* pRowFormatter)
|
||||
inline void Statement::setRowFormatter(RowFormatterPtr pRowFormatter)
|
||||
{
|
||||
_pRowFormatter = pRowFormatter;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ using Poco::Data::Session;
|
||||
using Poco::Data::Statement;
|
||||
using Poco::Data::RecordSet;
|
||||
using Poco::Data::RowFormatter;
|
||||
using Poco::Data::RowFormatterPtr;
|
||||
|
||||
|
||||
class HTMLTableFormatter : public RowFormatter
|
||||
@ -103,15 +104,18 @@ public:
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// register SQLite connector
|
||||
Poco::Data::SQLite::Connector::registerConnector();
|
||||
|
||||
// create a session
|
||||
Session session("SQLite", "sample.db");
|
||||
|
||||
// drop sample table, if it exists
|
||||
session << "DROP TABLE IF EXISTS Simpsons", now;
|
||||
|
||||
|
||||
// (re)create table
|
||||
session << "CREATE TABLE Simpsons (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3), Birthday DATE)", now;
|
||||
|
||||
|
||||
// insert some rows
|
||||
DateTime hd(1956, 3, 1);
|
||||
session << "INSERT INTO Simpsons VALUES('Homer Simpson', 'Springfield', 42, ?)", use(hd), now;
|
||||
@ -121,7 +125,7 @@ int main(int argc, char** argv)
|
||||
session << "INSERT INTO Simpsons VALUES('Bart Simpson', 'Springfield', 12, ?)", use(hd), now;
|
||||
hd.assign(1982, 5, 9);
|
||||
session << "INSERT INTO Simpsons VALUES('Lisa Simpson', 'Springfield', 10, ?)", use(hd), now;
|
||||
|
||||
|
||||
// create a statement and print the column names and data as HTML table
|
||||
HTMLTableFormatter tf;
|
||||
Statement stmt = (session << "SELECT * FROM Simpsons", format(tf), now);
|
||||
@ -129,8 +133,8 @@ int main(int argc, char** argv)
|
||||
std::cout << rs << std::endl;
|
||||
|
||||
// Note: The code above is divided into individual steps for clarity purpose.
|
||||
// The four lines can be reduced to the following single line of code:
|
||||
std::cout << RecordSet(session, "SELECT * FROM Simpsons", new HTMLTableFormatter);
|
||||
// The four lines can be reduced to the following single line:
|
||||
std::cout << RecordSet(session, "SELECT * FROM Simpsons", HTMLTableFormatter());
|
||||
|
||||
// simple formatting example (uses the default SimpleRowFormatter provided by framework)
|
||||
std::cout << std::endl << "Simple formatting:" << std::endl << std::endl;
|
||||
|
@ -55,7 +55,7 @@ const std::size_t RecordSet::UNKNOWN_TOTAL_ROW_COUNT = std::numeric_limits<std::
|
||||
|
||||
|
||||
RecordSet::RecordSet(const Statement& rStatement,
|
||||
RowFormatter* pRowFormatter):
|
||||
RowFormatterPtr pRowFormatter):
|
||||
Statement(rStatement),
|
||||
_currentRow(0),
|
||||
_pBegin(new RowIterator(this, 0 == rowsExtracted())),
|
||||
@ -69,7 +69,7 @@ RecordSet::RecordSet(const Statement& rStatement,
|
||||
|
||||
RecordSet::RecordSet(Session& rSession,
|
||||
const std::string& query,
|
||||
RowFormatter* pRowFormatter):
|
||||
RowFormatterPtr pRowFormatter):
|
||||
Statement((rSession << query, now)),
|
||||
_currentRow(0),
|
||||
_pBegin(new RowIterator(this, 0 == rowsExtracted())),
|
||||
@ -309,7 +309,7 @@ bool RecordSet::moveLast()
|
||||
}
|
||||
|
||||
|
||||
void RecordSet::setRowFormatter(RowFormatter* pRowFormatter)
|
||||
void RecordSet::setRowFormatter(RowFormatterPtr pRowFormatter)
|
||||
{
|
||||
pRowFormatter->setTotalRowCount(static_cast<int>(getTotalRowCount()));
|
||||
Statement::setRowFormatter(pRowFormatter);
|
||||
|
Loading…
Reference in New Issue
Block a user