Skip to content

Commit

Permalink
report attempt to bind use elements both by position and name
Browse files Browse the repository at this point in the history
  • Loading branch information
toonen committed Mar 7, 2013
1 parent 0c0cffd commit 5ba1dc6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/backends/db2/soci-db2.h
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/backends/db2/standard-use-type.cpp
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/backends/db2/statement.cpp
Expand Up @@ -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)
{
}

Expand Down
14 changes: 12 additions & 2 deletions src/backends/db2/vector-use-type.cpp
Expand Up @@ -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(
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down

0 comments on commit 5ba1dc6

Please sign in to comment.