Commit 5ba1dc67 authored by Brian R. Toonen's avatar Brian R. Toonen

report attempt to bind use elements both by position and name

parent 0c0cffda
......@@ -38,6 +38,17 @@
namespace soci
{
namespace details { namespace db2
{
enum binding_method
{
BOUND_BY_NONE,
BOUND_BY_NAME,
BOUND_BY_POSITION
};
}}
static const std::size_t maxBuffer = 1024 * 1024 * 1024; //CLI limit is about 3 GB, but 1GB should be enough
class db2_soci_error : public soci_error {
public:
......@@ -192,6 +203,7 @@ struct SOCI_DB2_DECL db2_statement_backend : details::statement_backend
std::vector<std::string> names;
bool hasVectorUseElements;
SQLUINTEGER numRowsFetched;
details::db2::binding_method use_binding_method_;
};
struct db2_rowid_backend : details::rowid_backend
......
......@@ -113,13 +113,24 @@ void db2_standard_use_type_backend::bind_helper(int &position, void *data, detai
void db2_standard_use_type_backend::bind_by_pos(
int &position, void *data, exchange_type type, bool /* readOnly */)
{
bind_helper(position, data, type);
if (statement_.use_binding_method_ == details::db2::BOUND_BY_NAME)
{
throw soci_error("Binding for use elements must be either by position or by name.");
}
statement_.use_binding_method_ = details::db2::BOUND_BY_POSITION;
bind_helper(position, data, type);
}
void db2_standard_use_type_backend::bind_by_name(
std::string const &name, void *data, exchange_type type, bool /* readOnly */)
{
if (statement_.use_binding_method_ == details::db2::BOUND_BY_POSITION)
{
throw soci_error("Binding for use elements must be either by position or by name.");
}
statement_.use_binding_method_ = details::db2::BOUND_BY_NAME;
int position = -1;
int count = 1;
......
......@@ -19,7 +19,7 @@ using namespace soci::details;
db2_statement_backend::db2_statement_backend(db2_session_backend &session)
: session_(session),hasVectorUseElements(false)
: session_(session),hasVectorUseElements(false),use_binding_method_(details::db2::BOUND_BY_NONE)
{
}
......
......@@ -210,8 +210,13 @@ void db2_vector_use_type_backend::bind_helper(int &position, void *data, details
void db2_vector_use_type_backend::bind_by_pos(int &position,
void *data, exchange_type type)
{
bind_helper(position, data, type);
if (statement_.use_binding_method_ == details::db2::BOUND_BY_NAME)
{
throw soci_error("Binding for use elements must be either by position or by name.");
}
statement_.use_binding_method_ = details::db2::BOUND_BY_POSITION;
bind_helper(position, data, type);
}
void db2_vector_use_type_backend::bind_by_name(
......@@ -220,6 +225,12 @@ void db2_vector_use_type_backend::bind_by_name(
int position = -1;
int count = 1;
if (statement_.use_binding_method_ == details::db2::BOUND_BY_POSITION)
{
throw soci_error("Binding for use elements must be either by position or by name.");
}
statement_.use_binding_method_ = details::db2::BOUND_BY_NAME;
for (std::vector<std::string>::iterator it = statement_.names.begin();
it != statement_.names.end(); ++it)
{
......@@ -241,7 +252,6 @@ void db2_vector_use_type_backend::bind_by_name(
ss << "Unable to find name '" << name << "' to bind to";
throw soci_error(ss.str().c_str());
}
}
void db2_vector_use_type_backend::pre_use(indicator const *ind)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment