Skip to content

Commit

Permalink
fix(Data::Binder: Skip reset for null Binder #4109
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-f committed Aug 15, 2023
1 parent b90316f commit 9a73467
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
14 changes: 10 additions & 4 deletions Data/SQLite/testsuite/src/SQLiteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ SQLiteTest::~SQLiteTest()

void SQLiteTest::testBind()
{
int f1 = -1;
std::vector<int> vf1;
Session session(Poco::Data::SQLite::Connector::KEY, "dummy.db");
session << "DROP TABLE IF EXISTS test", now;
session << "CREATE TABLE test (f1 INTEGER)", now;
Expand All @@ -265,12 +265,17 @@ void SQLiteTest::testBind()
statement << "INSERT INTO test(f1) VALUES(?)";
statement.addBind(Poco::Data::Keywords::bind(1, "f1"));
statement.execute();
session << "SELECT f1 FROM test", into(f1), now;
assertTrue (f1 == 1);
session << "SELECT f1 FROM test", into(vf1), now;
assertTrue (vf1.size() == 1);
assertTrue (vf1[0] == 1);
statement.removeBind("f1");
statement.addBind(Poco::Data::Keywords::bind(2, "f1"));
statement.execute();
assertTrue (f1 == 2);
vf1.clear();
session << "SELECT f1 FROM test", into(vf1), now;
assertTrue (vf1.size() == 2);
assertTrue (vf1[0] == 1);
assertTrue (vf1[1] == 2);
}


Expand Down Expand Up @@ -3501,6 +3506,7 @@ CppUnit::Test* SQLiteTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SQLiteTest");

CppUnit_addTest(pSuite, SQLiteTest, testBind);
CppUnit_addTest(pSuite, SQLiteTest, testBinding);
CppUnit_addTest(pSuite, SQLiteTest, testZeroRows);
CppUnit_addTest(pSuite, SQLiteTest, testSimpleAccess);
Expand Down
13 changes: 4 additions & 9 deletions Data/include/Poco/Data/Binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class Binding: public AbstractBinding
{
_bound = false;
AbstractBinder::Ptr pBinder = getBinder();
poco_assert_dbg (!pBinder.isNull());
pBinder->reset();
if (pBinder) pBinder->reset();
}

private:
Expand Down Expand Up @@ -168,12 +167,10 @@ class CopyBinding: public AbstractBinding
{
_bound = false;
AbstractBinder::Ptr pBinder = getBinder();
poco_assert_dbg (!pBinder.isNull());
pBinder->reset();
if (pBinder) pBinder->reset();
}

private:
//typedef typename TypeWrapper<T>::TYPE ValueType;
ValPtr _pVal;
bool _bound;
};
Expand Down Expand Up @@ -230,8 +227,7 @@ class Binding<const char*>: public AbstractBinding
{
_bound = false;
AbstractBinder::Ptr pBinder = getBinder();
poco_assert_dbg (!pBinder.isNull());
pBinder->reset();
if (pBinder) pBinder->reset();
}

private:
Expand Down Expand Up @@ -292,8 +288,7 @@ class CopyBinding<const char*>: public AbstractBinding
{
_bound = false;
AbstractBinder::Ptr pBinder = getBinder();
poco_assert_dbg (!pBinder.isNull());
pBinder->reset();
if (pBinder) pBinder->reset();
}

private:
Expand Down

0 comments on commit 9a73467

Please sign in to comment.