Commit b1850958 authored by msobczak's avatar msobczak

Removed eNoData from indicators and exposed it as a flag in statement and session.

parent abceeda0
......@@ -59,15 +59,6 @@ void firebird_standard_into_type_backend::post_fetch(
*ind = statement_.inds_[position_][0];
}
}
else
{
if (ind == NULL)
{
throw soci_error("No data fetched and no indicator defined.");
}
*ind = eNoData;
}
}
......
......@@ -499,15 +499,11 @@ firebird_statement_backend::fetch(int number)
// here we put data fetched from database into user buffers
void firebird_statement_backend::exchangeData(bool gotData, int row)
{
// first save indicators
for (size_t i = 0; i < static_cast<unsigned int>(sqldap_->sqld); ++i)
if (gotData)
{
if (!gotData)
{
inds_[i][row] = eIndicator(eNoData);
}
else
for (size_t i = 0; i < static_cast<unsigned int>(sqldap_->sqld); ++i)
{
// first save indicators
if (((sqldap_->sqlvar+i)->sqltype & 1) == 0)
{
// there is no indicator for this column
......@@ -525,14 +521,8 @@ void firebird_statement_backend::exchangeData(bool gotData, int row)
{
throw soci_error("Unknown state in firebird_statement_backend::exchangeData()");
}
}
}
// then deal with data
if (gotData)
{
for (size_t i = 0; i<static_cast<unsigned int>(sqldap_->sqld); ++i)
{
// then deal with data
if (inds_[i][row] != eNull)
{
if (intoType_ == eVector)
......
......@@ -326,7 +326,7 @@ void test5()
assert(ind == eTruncated);
sql << "select 5 from rdb$database where 0 = 1", into(i, ind);
assert(ind == eNoData);
assert(sql.got_data() == false);
try
{
......@@ -717,7 +717,7 @@ void test9()
{
row r;
sql << "select * from test9", into(r);
assert(r.indicator(0) == eNoData);
assert(sql.got_data() == false);
}
std::string msg("Hello");
......
......@@ -135,17 +135,6 @@ void mysql_standard_into_type_backend::post_fetch(
throw soci_error("Into element used with non-supported type.");
}
}
else // no data retrieved
{
if (ind != NULL)
{
*ind = eNoData;
}
else
{
throw soci_error("No data fetched and no indicator defined.");
}
}
}
void mysql_standard_into_type_backend::clean_up()
......
......@@ -160,17 +160,6 @@ void odbc_standard_into_type_backend::post_fetch(
std::mktime(t);
}
}
else // no data retrieved
{
if (ind != NULL)
{
*ind = eNoData;
}
else
{
throw soci_error("No data fetched and no indicator defined.");
}
}
}
void odbc_standard_into_type_backend::clean_up()
......
......@@ -252,11 +252,7 @@ void odbc_standard_use_type_backend::post_use(bool gotData, eIndicator *ind)
if (ind != NULL)
{
if (gotData == false)
{
*ind = eNoData;
}
else
if (gotData)
{
if (indHolder_ == 0)
{
......
......@@ -220,11 +220,7 @@ void oracle_standard_into_type_backend::post_fetch(
}
if (ind != NULL)
{
if (gotData == false)
{
*ind = eNoData;
}
else
if (gotData)
{
if (indOCIHolder_ == 0)
{
......
......@@ -262,11 +262,7 @@ void oracle_standard_use_type_backend::post_use(bool gotData, eIndicator *ind)
if (ind != NULL)
{
if (gotData == false)
{
*ind = eNoData;
}
else
if (gotData)
{
if (indOCIHolder_ == 0)
{
......
......@@ -188,17 +188,6 @@ void postgresql_standard_into_type_backend::post_fetch(
throw soci_error("Into element used with non-supported type.");
}
}
else // no data retrieved
{
if (ind != NULL)
{
*ind = eNoData;
}
else
{
throw soci_error("No data fetched and no indicator defined.");
}
}
}
void postgresql_standard_into_type_backend::clean_up()
......
......@@ -168,17 +168,6 @@ void sqlite3_standard_into_type_backend::post_fetch(bool gotData,
throw soci_error("Into element used with non-supported type.");
}
}
else // no data retrieved
{
if (ind != NULL)
{
*ind = eNoData;
}
else
{
throw soci_error("No data fetched and no indicator defined.");
}
}
}
void sqlite3_standard_into_type_backend::clean_up()
......
......@@ -19,7 +19,9 @@ void ref_counted_statement::final_action()
st_.alloc();
st_.prepare(session_.get_query_stream().str(), eOneTimeQuery);
st_.define_and_bind();
st_.execute(true);
const bool gotData = st_.execute(true);
session_.set_got_data(gotData);
}
catch (...)
{
......
......@@ -62,6 +62,9 @@ public:
void log_query(std::string const &query);
std::string get_last_query() const;
void set_got_data(bool gotData) { gotData_ = gotData; }
bool got_data() const { return gotData_; }
// for diagnostics and advanced users
// (downcast it to expected back-end session class)
details::session_backend * get_backend() { return backEnd_; }
......@@ -83,6 +86,8 @@ private:
std::string lastConnectString_;
details::session_backend *backEnd_;
bool gotData_;
};
} // namespace SOCI
......
......@@ -25,7 +25,7 @@ enum eDataType
};
// the enum type for indicator variables
enum eIndicator { eOK, eNoData, eNull, eTruncated };
enum eIndicator { eOK, eNull, eTruncated };
namespace details
{
......
......@@ -330,6 +330,7 @@ bool statement_impl::execute(bool withDataExchange)
post_use(gotData);
}
session_.set_got_data(gotData);
return gotData;
}
......@@ -337,6 +338,7 @@ bool statement_impl::fetch()
{
if (fetchSize_ == 0)
{
session_.set_got_data(false);
return false;
}
......@@ -354,6 +356,7 @@ bool statement_impl::fetch()
}
else if (newFetchSize == 0)
{
session_.set_got_data(false);
return false;
}
else
......@@ -391,6 +394,7 @@ bool statement_impl::fetch()
}
post_fetch(gotData, true);
session_.set_got_data(gotData);
return gotData;
}
......
......@@ -161,12 +161,20 @@ public:
void undefine_and_bind() { impl_->undefine_and_bind(); }
bool execute(bool withDataExchange = false)
{
return impl_->execute(withDataExchange);
gotData_ = impl_->execute(withDataExchange);
return gotData_;
}
bool fetch() { return impl_->fetch(); }
void describe() { impl_->describe(); }
void set_row(row* r) { impl_->set_row(r); }
bool fetch()
{
gotData_ = impl_->fetch();
return gotData_;
}
bool got_data() const { return gotData_; }
void describe() { impl_->describe(); }
void set_row(row* r) { impl_->set_row(r); }
void exchange_for_rowset(details::into_type_ptr const &i)
{
impl_->exchange_for_rowset(i);
......@@ -206,6 +214,7 @@ public:
private:
details::statement_impl * impl_;
bool gotData_;
};
namespace details
......
......@@ -466,20 +466,11 @@ void test2()
}
sql << "select id from soci_test where id = 1000", into(i, ind);
assert(ind == eNoData);
assert(sql.got_data() == false);
try
{
// expect error
sql << "select id from soci_test where id = 1000", into(i);
assert(false);
}
catch (soci_error const &e)
{
std::string error = e.what();
assert(error ==
"No data fetched and no indicator defined.");
}
// no data expected
sql << "select id from soci_test where id = 1000", into(i);
assert(sql.got_data() == false);
}
}
......@@ -1718,7 +1709,7 @@ void test12()
row r;
sql << "select * from soci_test", into(r);
assert(r.indicator(0) == eNoData);
assert(sql.got_data() == false);
sql << "insert into soci_test"
" values(3.14, 123, \'Johny\',"
......@@ -1874,7 +1865,7 @@ void test14()
row r1;
sql << "select * from soci_test", into(r1);
assert(r1.indicator(0) == eNoData);
assert(sql.got_data() == false);
sql << "insert into soci_test values('david', '(404)123-4567')";
sql << "insert into soci_test values('john', '(404)123-4567')";
......
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