mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-18 00:15:27 +01:00
- use() takes reference now
- bind() for constants - Statement: allow for easier external binding supply
This commit is contained in:
parent
48d0d9fef9
commit
41c775b41d
@ -2897,6 +2897,7 @@ void SQLExecutor::asynchronous(int rowCount)
|
||||
assert (stmt2.execute() == rowCount);
|
||||
}
|
||||
|
||||
|
||||
void SQLExecutor::any()
|
||||
{
|
||||
Any i = 42;
|
||||
|
@ -46,6 +46,8 @@
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
@ -119,6 +121,8 @@ private:
|
||||
|
||||
typedef Poco::AutoPtr<AbstractBinding> AbstractBindingPtr;
|
||||
typedef std::vector<AbstractBindingPtr> AbstractBindingVec;
|
||||
typedef std::deque<AbstractBindingPtr> AbstractBindingDeq;
|
||||
typedef std::list<AbstractBindingPtr> AbstractBindingLst;
|
||||
|
||||
|
||||
//
|
||||
|
@ -46,6 +46,8 @@
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
@ -133,6 +135,10 @@ private:
|
||||
typedef Poco::AutoPtr<AbstractExtraction> AbstractExtractionPtr;
|
||||
typedef std::vector<AbstractExtractionPtr> AbstractExtractionVec;
|
||||
typedef std::vector<AbstractExtractionVec> AbstractExtractionVecVec;
|
||||
typedef std::deque<AbstractExtractionPtr> AbstractExtractionDeq;
|
||||
typedef std::vector<AbstractExtractionDeq> AbstractExtractionDeqVec;
|
||||
typedef std::list<AbstractExtractionPtr> AbstractExtractionLst;
|
||||
typedef std::vector<AbstractExtractionLst> AbstractExtractionLstVec;
|
||||
|
||||
|
||||
//
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "Poco/Data/AbstractBinding.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/Data/TypeHandler.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
@ -58,14 +59,28 @@ namespace Data {
|
||||
|
||||
template <class T>
|
||||
class Binding: public AbstractBinding
|
||||
/// A Binding maps a value to a column.
|
||||
/// Binding maps a value or multiple values (see Binding specializations for STL containers as
|
||||
/// well as type handlers) to database column(s). Values to be bound can be either mapped
|
||||
/// directly (by reference) or a copy can be created, depending on the value of the copy argument.
|
||||
/// To pass a reference to a variable, it is recommended to pass it to the intermediate
|
||||
/// utility function use(), which will create the proper binding. In cases when a reference
|
||||
/// is passed to binding, the storage it refers to must be valid at the statement execution time.
|
||||
/// To pass a copy of a variable, constant or string literal, use utility function bind().
|
||||
/// Variables can be passed as either copies or references (i.e. using either use() or bind()).
|
||||
/// Constants, however, can only be passed as copies. this is best achieved using bind() utility
|
||||
/// function. An attempt to pass a constant by reference shall result in compile-time error.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const T& val, const std::string& name = "", Direction direction = PD_IN):
|
||||
AbstractBinding(name, direction),
|
||||
_val(val),
|
||||
explicit Binding(T& val,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN,
|
||||
bool copy = false):
|
||||
AbstractBinding(name, direction),
|
||||
_pVal(copy ? new T(val) : 0),
|
||||
_val(copy ? *_pVal : val),
|
||||
_bound(false)
|
||||
/// Creates the Binding.
|
||||
/// Creates the Binding using the passed reference as bound value.
|
||||
/// If copy is true, a copy of the value referred to is created.
|
||||
{
|
||||
}
|
||||
|
||||
@ -105,8 +120,66 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const T& _val;
|
||||
bool _bound;
|
||||
SharedPtr<T> _pVal;
|
||||
const T& _val;
|
||||
bool _bound;
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
class Binding<const char*>: public AbstractBinding
|
||||
/// Binding const char* specialization wraps char pointer into string.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const char* pVal,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN,
|
||||
bool copy = true):
|
||||
AbstractBinding(name, direction),
|
||||
_val(pVal ? pVal : throw NullPointerException() ),
|
||||
_bound(false)
|
||||
/// Creates the Binding by copying the passed string.
|
||||
{
|
||||
}
|
||||
|
||||
~Binding()
|
||||
/// Destroys the Binding.
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t numOfColumnsHandled() const
|
||||
{
|
||||
return 1u;
|
||||
}
|
||||
|
||||
std::size_t numOfRowsHandled() const
|
||||
{
|
||||
return 1u;
|
||||
}
|
||||
|
||||
bool canBind() const
|
||||
{
|
||||
return !_bound;
|
||||
}
|
||||
|
||||
void bind(std::size_t pos)
|
||||
{
|
||||
poco_assert_dbg(getBinder() != 0);
|
||||
TypeHandler<std::string>::bind(pos, _val, getBinder(), getDirection());
|
||||
_bound = true;
|
||||
}
|
||||
|
||||
void reset ()
|
||||
{
|
||||
_bound = false;
|
||||
AbstractBinder* pBinder = getBinder();
|
||||
poco_check_ptr (pBinder);
|
||||
pBinder->reset();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _val;
|
||||
bool _bound;
|
||||
};
|
||||
|
||||
|
||||
@ -115,13 +188,15 @@ class Binding<std::vector<T> >: public AbstractBinding
|
||||
/// Specialization for std::vector.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const std::vector<T>& val,
|
||||
explicit Binding(std::vector<T>& val,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN):
|
||||
AbstractBinding(name, direction),
|
||||
_val(val),
|
||||
_begin(val.begin()),
|
||||
_end(val.end())
|
||||
Direction direction = PD_IN,
|
||||
bool copy = false):
|
||||
AbstractBinding(name, direction),
|
||||
_pVal(copy ? new std::vector<T>(val) : 0),
|
||||
_val(copy ? *_pVal : val),
|
||||
_begin(_val.begin()),
|
||||
_end(_val.end())
|
||||
/// Creates the Binding.
|
||||
{
|
||||
if (PD_IN == direction && numOfRowsHandled() == 0)
|
||||
@ -164,9 +239,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::vector<T>& _val;
|
||||
typename std::vector<T>::const_iterator _begin;
|
||||
typename std::vector<T>::const_iterator _end;
|
||||
typedef std::vector<T> Type;
|
||||
typedef SharedPtr<Type> TypePtr;
|
||||
typedef typename Type::const_iterator Iterator;
|
||||
|
||||
TypePtr _pVal;
|
||||
const Type& _val;
|
||||
Iterator _begin;
|
||||
Iterator _end;
|
||||
};
|
||||
|
||||
|
||||
@ -251,11 +331,15 @@ class Binding<std::list<T> >: public AbstractBinding
|
||||
/// Specialization for std::list.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const std::list<T>& val, const std::string& name = "", Direction direction = PD_IN):
|
||||
explicit Binding(std::list<T>& val,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN,
|
||||
bool copy = false):
|
||||
AbstractBinding(name, direction),
|
||||
_val(val),
|
||||
_begin(val.begin()),
|
||||
_end(val.end())
|
||||
_pVal(copy ? new std::list<T>(val) : 0),
|
||||
_val(copy ? *_pVal : val),
|
||||
_begin(_val.begin()),
|
||||
_end(_val.end())
|
||||
/// Creates the Binding.
|
||||
{
|
||||
if (PD_IN == direction && numOfRowsHandled() == 0)
|
||||
@ -297,9 +381,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::list<T>& _val;
|
||||
typename std::list<T>::const_iterator _begin;
|
||||
typename std::list<T>::const_iterator _end;
|
||||
typedef std::list<T> Type;
|
||||
typedef SharedPtr<Type> TypePtr;
|
||||
typedef typename Type::const_iterator Iterator;
|
||||
|
||||
TypePtr _pVal;
|
||||
const Type& _val;
|
||||
Iterator _begin;
|
||||
Iterator _end;
|
||||
};
|
||||
|
||||
|
||||
@ -308,11 +397,15 @@ class Binding<std::deque<T> >: public AbstractBinding
|
||||
/// Specialization for std::deque.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const std::deque<T>& val, const std::string& name = "", Direction direction = PD_IN):
|
||||
explicit Binding(std::deque<T>& val,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN,
|
||||
bool copy = false):
|
||||
AbstractBinding(name, direction),
|
||||
_val(val),
|
||||
_begin(val.begin()),
|
||||
_end(val.end())
|
||||
_pVal(copy ? new std::deque<T>(val) : 0),
|
||||
_val(copy ? *_pVal : val),
|
||||
_begin(_val.begin()),
|
||||
_end(_val.end())
|
||||
/// Creates the Binding.
|
||||
{
|
||||
if (PD_IN == direction && numOfRowsHandled() == 0)
|
||||
@ -354,9 +447,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::deque<T>& _val;
|
||||
typename std::deque<T>::const_iterator _begin;
|
||||
typename std::deque<T>::const_iterator _end;
|
||||
typedef std::deque<T> Type;
|
||||
typedef SharedPtr<Type> TypePtr;
|
||||
typedef typename Type::const_iterator Iterator;
|
||||
|
||||
TypePtr _pVal;
|
||||
const Type& _val;
|
||||
Iterator _begin;
|
||||
Iterator _end;
|
||||
};
|
||||
|
||||
|
||||
@ -365,11 +463,15 @@ class Binding<std::set<T> >: public AbstractBinding
|
||||
/// Specialization for std::set.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const std::set<T>& val, const std::string& name = "", Direction direction = PD_IN):
|
||||
explicit Binding(std::set<T>& val,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN,
|
||||
bool copy = false):
|
||||
AbstractBinding(name, direction),
|
||||
_val(val),
|
||||
_begin(val.begin()),
|
||||
_end(val.end())
|
||||
_pVal(copy ? new std::set<T>(val) : 0),
|
||||
_val(copy ? *_pVal : val),
|
||||
_begin(_val.begin()),
|
||||
_end(_val.end())
|
||||
/// Creates the Binding.
|
||||
{
|
||||
if (PD_IN == direction && numOfRowsHandled() == 0)
|
||||
@ -411,9 +513,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::set<T>& _val;
|
||||
typename std::set<T>::const_iterator _begin;
|
||||
typename std::set<T>::const_iterator _end;
|
||||
typedef std::set<T> Type;
|
||||
typedef SharedPtr<Type> TypePtr;
|
||||
typedef typename Type::const_iterator Iterator;
|
||||
|
||||
TypePtr _pVal;
|
||||
const Type& _val;
|
||||
Iterator _begin;
|
||||
Iterator _end;
|
||||
};
|
||||
|
||||
|
||||
@ -422,11 +529,15 @@ class Binding<std::multiset<T> >: public AbstractBinding
|
||||
/// Specialization for std::multiset.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const std::multiset<T>& val, const std::string& name = "", Direction direction = PD_IN):
|
||||
explicit Binding(std::multiset<T>& val,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN,
|
||||
bool copy = false):
|
||||
AbstractBinding(name, direction),
|
||||
_val(val),
|
||||
_begin(val.begin()),
|
||||
_end(val.end())
|
||||
_pVal(copy ? new std::multiset<T>(val) : 0),
|
||||
_val(copy ? *_pVal : val),
|
||||
_begin(_val.begin()),
|
||||
_end(_val.end())
|
||||
/// Creates the Binding.
|
||||
{
|
||||
if (PD_IN == direction && numOfRowsHandled() == 0)
|
||||
@ -468,9 +579,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::multiset<T>& _val;
|
||||
typename std::multiset<T>::const_iterator _begin;
|
||||
typename std::multiset<T>::const_iterator _end;
|
||||
typedef std::multiset<T> Type;
|
||||
typedef SharedPtr<Type> TypePtr;
|
||||
typedef typename Type::const_iterator Iterator;
|
||||
|
||||
TypePtr _pVal;
|
||||
const Type& _val;
|
||||
Iterator _begin;
|
||||
Iterator _end;
|
||||
};
|
||||
|
||||
|
||||
@ -479,11 +595,15 @@ class Binding<std::map<K, V> >: public AbstractBinding
|
||||
/// Specialization for std::map.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const std::map<K, V>& val, const std::string& name = "", Direction direction = PD_IN):
|
||||
explicit Binding(std::map<K, V>& val,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN,
|
||||
bool copy = false):
|
||||
AbstractBinding(name, direction),
|
||||
_val(val),
|
||||
_begin(val.begin()),
|
||||
_end(val.end())
|
||||
_pVal(copy ? new std::map<K, V>(val) : 0),
|
||||
_val(copy ? *_pVal : val),
|
||||
_begin(_val.begin()),
|
||||
_end(_val.end())
|
||||
/// Creates the Binding.
|
||||
{
|
||||
if (PD_IN == direction && numOfRowsHandled() == 0)
|
||||
@ -525,9 +645,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::map<K, V>& _val;
|
||||
typename std::map<K, V>::const_iterator _begin;
|
||||
typename std::map<K, V>::const_iterator _end;
|
||||
typedef std::map<K, V> Type;
|
||||
typedef SharedPtr<Type> TypePtr;
|
||||
typedef typename Type::const_iterator Iterator;
|
||||
|
||||
TypePtr _pVal;
|
||||
const Type& _val;
|
||||
Iterator _begin;
|
||||
Iterator _end;
|
||||
};
|
||||
|
||||
|
||||
@ -536,11 +661,15 @@ class Binding<std::multimap<K, V> >: public AbstractBinding
|
||||
/// Specialization for std::multimap.
|
||||
{
|
||||
public:
|
||||
explicit Binding(const std::multimap<K, V>& val, const std::string& name = "", Direction direction = PD_IN):
|
||||
explicit Binding(std::multimap<K, V>& val,
|
||||
const std::string& name = "",
|
||||
Direction direction = PD_IN,
|
||||
bool copy = false):
|
||||
AbstractBinding(name, direction),
|
||||
_val(val),
|
||||
_begin(val.begin()),
|
||||
_end(val.end())
|
||||
_pVal(copy ? new std::multimap<K, V>(val) : 0),
|
||||
_val(copy ? *_pVal : val),
|
||||
_begin(_val.begin()),
|
||||
_end(_val.end())
|
||||
/// Creates the Binding.
|
||||
{
|
||||
if (PD_IN == direction && numOfRowsHandled() == 0)
|
||||
@ -582,30 +711,49 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::multimap<K, V>& _val;
|
||||
typename std::multimap<K, V>::const_iterator _begin;
|
||||
typename std::multimap<K, V>::const_iterator _end;
|
||||
typedef std::multimap<K, V> Type;
|
||||
typedef SharedPtr<Type> TypePtr;
|
||||
typedef typename Type::const_iterator Iterator;
|
||||
|
||||
TypePtr _pVal;
|
||||
const Type& _val;
|
||||
Iterator _begin;
|
||||
Iterator _end;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
Binding<T>* use(const T& t, const std::string& name = "")
|
||||
inline Binding<T>* use(T& t, const std::string& name = "")
|
||||
/// Convenience function for a more compact Binding creation.
|
||||
{
|
||||
return new Binding<T>(t, name, AbstractBinding::PD_IN);
|
||||
}
|
||||
|
||||
|
||||
inline Binding<NullData>* use(const NullData& t, const std::string& name = "")
|
||||
/// NullData overload.
|
||||
{
|
||||
return new Binding<NullData>(const_cast<NullData&>(t), name, AbstractBinding::PD_IN);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
Binding<T>* in(const T& t, const std::string& name = "")
|
||||
inline Binding<T>* in(T& t, const std::string& name = "")
|
||||
/// Convenience function for a more compact Binding creation.
|
||||
{
|
||||
return new Binding<T>(t, name, AbstractBinding::PD_IN);
|
||||
}
|
||||
|
||||
|
||||
inline Binding<NullData>* in(const NullData& t, const std::string& name = "")
|
||||
/// NullData overload.
|
||||
{
|
||||
return new Binding<NullData>(const_cast<NullData&>(t), name, AbstractBinding::PD_IN);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
Binding<T>* out(T& t, const std::string& name = "")
|
||||
inline Binding<T>* out(T& t, const std::string& name = "")
|
||||
/// Convenience function for a more compact Binding creation.
|
||||
{
|
||||
return new Binding<T>(t, name, AbstractBinding::PD_OUT);
|
||||
@ -613,13 +761,61 @@ Binding<T>* out(T& t, const std::string& name = "")
|
||||
|
||||
|
||||
template <typename T>
|
||||
Binding<T>* io(T& t, const std::string& name = "")
|
||||
inline Binding<T>* io(T& t, const std::string& name = "")
|
||||
/// Convenience function for a more compact Binding creation.
|
||||
{
|
||||
return new Binding<T>(t, name, AbstractBinding::PD_IN_OUT);
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBindingVec& use(AbstractBindingVec& bv)
|
||||
/// Convenience dummy function (for syntax purposes only).
|
||||
{
|
||||
return bv;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBindingVec& in(AbstractBindingVec& bv)
|
||||
/// Convenience dummy function (for syntax purposes only).
|
||||
{
|
||||
return bv;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBindingVec& out(AbstractBindingVec& bv)
|
||||
/// Convenience dummy function (for syntax purposes only).
|
||||
{
|
||||
return bv;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBindingVec& io(AbstractBindingVec& bv)
|
||||
/// Convenience dummy function (for syntax purposes only).
|
||||
{
|
||||
return bv;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline Binding<T>* bind(T t,
|
||||
const std::string& name = "",
|
||||
AbstractBinding::Direction direction = AbstractBinding::PD_IN)
|
||||
/// Convenience function for a more compact Binding creation.
|
||||
/// This funtion differs from use() in its value copy semantics.
|
||||
{
|
||||
return new Binding<T>(t, name, direction, true);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline Binding<T>* bind(T t, AbstractBinding::Direction direction)
|
||||
/// Convenience function for a more compact Binding creation.
|
||||
/// This funtion differs from use() in its value copy semantics.
|
||||
{
|
||||
return bind(t, "", direction);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
|
@ -816,6 +816,20 @@ Extraction<T>* into(T& t, const Position& pos, const T& def)
|
||||
}
|
||||
|
||||
|
||||
inline AbstractExtractionVecVec& into(AbstractExtractionVecVec& evv)
|
||||
/// Convenience dummy function (for syntax purposes only).
|
||||
{
|
||||
return evv;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractExtractionVec& into(AbstractExtractionVec& ev)
|
||||
/// Convenience dummy function (for syntax purposes only).
|
||||
{
|
||||
return ev;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
|
@ -153,12 +153,82 @@ public:
|
||||
Statement& operator , (Manipulator manip);
|
||||
/// Handles manipulators, such as now, async, etc.
|
||||
|
||||
Statement& operator , (AbstractBinding* info);
|
||||
/// Registers the Binding at the Statement.
|
||||
Statement& operator , (AbstractBinding* bind);
|
||||
/// Registers the Binding with the Statement by calling addBind().
|
||||
/// Statement takes the ownership of the bind in an AutoPtr.
|
||||
/// To prevent bind destruction upon statement destruction, pass an
|
||||
/// AutoPtr<AbstractBinding>::duplicate() to this function.
|
||||
/// This function is primarily intended to be a destination for
|
||||
/// use() and bind() utility functions return value, so it is
|
||||
/// recommended to call addBind() directly instead.
|
||||
|
||||
Statement& addBind(AbstractBinding* pBind, bool duplicate = true);
|
||||
/// Registers a single binding with the statement.
|
||||
/// To allow the binding to outlive the statement destruction,
|
||||
/// duplicate must be true.
|
||||
|
||||
void removeBind(const std::string& name);
|
||||
/// Removes the all the bindings with specified name from the statement.
|
||||
|
||||
Statement& operator , (AbstractBindingVec& bindVec);
|
||||
/// Registers the Binding vector with the Statement.
|
||||
|
||||
Statement& operator , (AbstractExtraction* extract);
|
||||
/// Registers objects used for extracting data at the Statement.
|
||||
/// Registers objects used for extracting data with the Statement by
|
||||
/// calling addExtract().
|
||||
/// Statement takes the ownership of the extract in an AutoPtr.
|
||||
/// To prevent extract destruction upon statement destruction, pass an
|
||||
/// AutoPtr<AbstractExtraction>::duplicate() to this function.
|
||||
/// This function is primarily intended to be a destination for
|
||||
/// into() utility function return value, so it is recommended to call
|
||||
/// addExtract() directly instead.
|
||||
|
||||
Statement& addExtract(AbstractExtraction* pExtract, bool duplicate = true);
|
||||
/// Registers a single extraction with the statement.
|
||||
/// To allow the extraction to outlive the statement destruction,
|
||||
/// duplicate must be true.
|
||||
|
||||
Statement& operator , (AbstractExtractionVec& extVec);
|
||||
/// Registers the extraction vector with the Statement.
|
||||
/// The vector is registered at position 0 (i.e. for the first returned data set).
|
||||
|
||||
Statement& operator , (AbstractExtractionVecVec& extVecVec);
|
||||
/// Registers the vector of extraction vectors with the Statement.
|
||||
|
||||
template <typename C>
|
||||
Statement& addBinding(C& bindingCont, bool reset)
|
||||
/// Registers binding container with the Statement.
|
||||
{
|
||||
if (reset) _pImpl->resetBinding();
|
||||
typename C::iterator itAB = bindingCont.begin();
|
||||
typename C::iterator itABEnd = bindingCont.end();
|
||||
for (; itAB != itABEnd; ++itAB) addBind(itAB->duplicate());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
Statement& addExtraction(C& val, bool reset)
|
||||
/// Registers extraction container with the Statement.
|
||||
{
|
||||
if (reset) _pImpl->resetExtraction();
|
||||
typename C::iterator itAE = val.begin();
|
||||
typename C::iterator itAEEnd = val.end();
|
||||
for (; itAE != itAEEnd; ++itAE) addExtract(itAE->duplicate());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
Statement& addExtractions(C& val)
|
||||
/// Registers container of extraction containers with the Statement.
|
||||
{
|
||||
_pImpl->resetExtraction();
|
||||
typename C::iterator itAEV = val.begin();
|
||||
typename C::iterator itAEVEnd = val.end();
|
||||
for (; itAEV != itAEVEnd; ++itAEV) addExtraction(*itAEV, false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Statement& operator , (const Bulk& bulk);
|
||||
/// Sets the bulk execution mode (both binding and extraction) for this
|
||||
/// statement.Statement must not have any extractors or binders set at the
|
||||
@ -337,7 +407,7 @@ private:
|
||||
/// Asynchronously executes the statement.
|
||||
|
||||
template <typename T>
|
||||
Statement& commaImpl (const T& val)
|
||||
Statement& commaPODImpl(const T& val)
|
||||
{
|
||||
_arguments.push_back(val);
|
||||
return *this;
|
||||
@ -440,99 +510,135 @@ inline Statement& Statement::operator , (RowFormatter* pRowFformatter)
|
||||
|
||||
inline Statement& Statement::operator , (char value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (Poco::UInt8 value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (Poco::Int8 value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (Poco::UInt16 value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (Poco::Int16 value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (Poco::UInt32 value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (Poco::Int32 value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
inline Statement& Statement::operator , (long value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (unsigned long value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (Poco::UInt64 value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (Poco::Int64 value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (double value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (float value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (bool value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (const std::string& value)
|
||||
{
|
||||
return commaImpl(value);
|
||||
return commaPODImpl(value);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (const char* value)
|
||||
{
|
||||
return commaImpl(std::string(value));
|
||||
return commaPODImpl(std::string(value));
|
||||
}
|
||||
|
||||
|
||||
inline void Statement::removeBind(const std::string& name)
|
||||
{
|
||||
_pImpl->removeBind(name);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (AbstractBinding* pBind)
|
||||
{
|
||||
return addBind(pBind, false);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (AbstractBindingVec& bindVec)
|
||||
{
|
||||
return addBinding(bindVec, false);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (AbstractExtraction* pExtract)
|
||||
{
|
||||
return addExtract(pExtract, false);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (AbstractExtractionVec& extVec)
|
||||
{
|
||||
return addExtraction(extVec, false);
|
||||
}
|
||||
|
||||
|
||||
inline Statement& Statement::operator , (AbstractExtractionVecVec& extVecVec)
|
||||
{
|
||||
return addExtractions(extVecVec);
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,11 +125,15 @@ public:
|
||||
_ostr << t;
|
||||
}
|
||||
|
||||
void addBinding(AbstractBinding* pBinding);
|
||||
/// Registers the Binding at the StatementImpl.
|
||||
void addBind(AbstractBinding* pBinding);
|
||||
/// Registers the Binding with the StatementImpl.
|
||||
|
||||
void removeBind(const std::string& name);
|
||||
/// Unregisters all the bindings having specified name with the StatementImpl.
|
||||
/// Bindings are released and, if this class was the sole owner, deleted.
|
||||
|
||||
void addExtract(AbstractExtraction* pExtraction);
|
||||
/// Registers objects used for extracting data at the StatementImpl.
|
||||
/// Registers objects used for extracting data with the StatementImpl.
|
||||
|
||||
void setExtractionLimit(const Limit& extrLimit);
|
||||
/// Changes the extractionLimit to extrLimit. Per default no limit (EXTRACT_UNLIMITED) is set.
|
||||
@ -426,7 +430,7 @@ private:
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void StatementImpl::addBinding(AbstractBinding* pBinding)
|
||||
inline void StatementImpl::addBind(AbstractBinding* pBinding)
|
||||
{
|
||||
poco_check_ptr (pBinding);
|
||||
_bindings.push_back(pBinding);
|
||||
|
@ -205,7 +205,7 @@ Statement& Statement::operator , (Manipulator manip)
|
||||
}
|
||||
|
||||
|
||||
Statement& Statement::operator , (AbstractBinding* pBind)
|
||||
Statement& Statement::addBind(AbstractBinding* pBind, bool duplicate)
|
||||
{
|
||||
if (pBind->isBulk())
|
||||
{
|
||||
@ -219,12 +219,13 @@ Statement& Statement::operator , (AbstractBinding* pBind)
|
||||
}
|
||||
else _pImpl->forbidBulk();
|
||||
|
||||
_pImpl->addBinding(pBind);
|
||||
if (duplicate) pBind->duplicate();
|
||||
_pImpl->addBind(pBind);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Statement& Statement::operator , (AbstractExtraction* pExtract)
|
||||
Statement& Statement::addExtract(AbstractExtraction* pExtract, bool duplicate)
|
||||
{
|
||||
if (pExtract->isBulk())
|
||||
{
|
||||
@ -241,6 +242,7 @@ Statement& Statement::operator , (AbstractExtraction* pExtract)
|
||||
}
|
||||
else _pImpl->forbidBulk();
|
||||
|
||||
if (duplicate) pExtract->duplicate();
|
||||
_pImpl->addExtract(pExtract);
|
||||
return *this;
|
||||
}
|
||||
|
@ -363,6 +363,26 @@ void StatementImpl::addExtract(AbstractExtraction* pExtraction)
|
||||
}
|
||||
|
||||
|
||||
void StatementImpl::removeBind(const std::string& name)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
AbstractBindingVec::iterator it = _bindings.begin();
|
||||
for (; it != _bindings.end();)
|
||||
{
|
||||
if ((*it)->name() == name)
|
||||
{
|
||||
it = _bindings.erase(it);
|
||||
found = true;
|
||||
}
|
||||
else ++it;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
throw NotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
void StatementImpl::formatSQL(std::vector<Any>& arguments)
|
||||
{
|
||||
std::string sql;
|
||||
|
@ -1098,12 +1098,21 @@ void DataTest::testDateAndTime()
|
||||
assert (t1 < t); assert (t1 != t);
|
||||
t1.assign(t.hour(), t.minute(), t.second() - 1);
|
||||
assert (t1 < t); assert (t1 != t);
|
||||
t1.assign(t.hour() + 1, t.minute(), t.second());
|
||||
assert (t1 > t); assert (t1 != t);
|
||||
t1.assign(t.hour(), t.minute() + 1, t.second());
|
||||
assert (t1 > t); assert (t1 != t);
|
||||
t1.assign(t.hour(), t.minute(), t.second() + 1);
|
||||
assert (t1 > t); assert (t1 != t);
|
||||
if (t.hour() < 23)
|
||||
{
|
||||
t1.assign(t.hour() + 1, t.minute(), t.second());
|
||||
assert (t1 > t); assert (t1 != t);
|
||||
}
|
||||
if (t.minute() < 59)
|
||||
{
|
||||
t1.assign(t.hour(), t.minute() + 1, t.second());
|
||||
assert (t1 > t); assert (t1 != t);
|
||||
}
|
||||
if (t.second() < 59)
|
||||
{
|
||||
t1.assign(t.hour(), t.minute(), t.second() + 1);
|
||||
assert (t1 > t); assert (t1 != t);
|
||||
}
|
||||
t1.assign(t.hour(), t.minute(), t.second());
|
||||
assert (t1 == t);
|
||||
|
||||
@ -1122,6 +1131,55 @@ void DataTest::testDateAndTime()
|
||||
}
|
||||
|
||||
|
||||
void DataTest::testExternalBindingAndExtraction()
|
||||
{
|
||||
AbstractExtractionVecVec extractionVec;
|
||||
AbstractExtractionVec extraction;
|
||||
AbstractBindingVec binding;
|
||||
|
||||
Session tmp (Poco::Data::Test::Connector::KEY, "dummy.db");
|
||||
|
||||
int i;
|
||||
AbstractExtraction* pExt1 = into(i);
|
||||
AbstractExtraction* pExt2 = into(i);
|
||||
assert (1 == pExt1->referenceCount());
|
||||
assert (1 == pExt2->referenceCount());
|
||||
{
|
||||
Statement stmt(tmp);
|
||||
stmt.addExtract(pExt1); // retain external ownership in addition to giving it to statement
|
||||
assert (2 == pExt1->referenceCount());
|
||||
stmt.addExtract(pExt2, false); // give ownership to statement
|
||||
assert (1 == pExt2->referenceCount());
|
||||
}
|
||||
assert (1 == pExt1->referenceCount()); delete pExt1;
|
||||
// pExt2 does not exist any more
|
||||
|
||||
AbstractBinding* pBind1 = use(i, "mybind1");
|
||||
AbstractBinding* pBind2 = use(i, "mybind2");
|
||||
AbstractBinding* pBind3 = use(i, "mybind3");
|
||||
assert (1 == pBind1->referenceCount());
|
||||
assert (1 == pBind2->referenceCount());
|
||||
assert (1 == pBind3->referenceCount());
|
||||
{
|
||||
Statement stmt(tmp);
|
||||
stmt.addBind(pBind1); // retain external ownership in addition to giving it to statement
|
||||
assert (2 == pBind1->referenceCount());
|
||||
stmt.addBind(pBind2, false);// give ownership to statement
|
||||
assert (1 == pBind2->referenceCount());
|
||||
stmt.addBind(pBind3);// give ownership to statement
|
||||
assert (2 == pBind3->referenceCount());
|
||||
stmt.removeBind(pBind3->name());// take ownership from statement
|
||||
assert (1 == pBind3->referenceCount());
|
||||
|
||||
try { stmt.removeBind("a bad name"); fail("must fail"); }
|
||||
catch (NotFoundException&) { }
|
||||
}
|
||||
assert (1 == pBind1->referenceCount()); delete pBind1;
|
||||
// pBind2 does not exist any more
|
||||
assert (1 == pBind3->referenceCount()); delete pBind3;
|
||||
}
|
||||
|
||||
|
||||
void DataTest::setUp()
|
||||
{
|
||||
}
|
||||
@ -1150,6 +1208,7 @@ CppUnit::Test* DataTest::suite()
|
||||
CppUnit_addTest(pSuite, DataTest, testRowSort);
|
||||
CppUnit_addTest(pSuite, DataTest, testRowFormat);
|
||||
CppUnit_addTest(pSuite, DataTest, testDateAndTime);
|
||||
CppUnit_addTest(pSuite, DataTest, testExternalBindingAndExtraction);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ public:
|
||||
void testRowSort();
|
||||
void testRowFormat();
|
||||
void testDateAndTime();
|
||||
void testExternalBindingAndExtraction();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
Loading…
x
Reference in New Issue
Block a user