Skip to content

Commit 9a73467

Browse files
committed
fix(Data::Binder: Skip reset for null Binder #4109
1 parent b90316f commit 9a73467

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Data/SQLite/testsuite/src/SQLiteTest.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ SQLiteTest::~SQLiteTest()
256256

257257
void SQLiteTest::testBind()
258258
{
259-
int f1 = -1;
259+
std::vector<int> vf1;
260260
Session session(Poco::Data::SQLite::Connector::KEY, "dummy.db");
261261
session << "DROP TABLE IF EXISTS test", now;
262262
session << "CREATE TABLE test (f1 INTEGER)", now;
@@ -265,12 +265,17 @@ void SQLiteTest::testBind()
265265
statement << "INSERT INTO test(f1) VALUES(?)";
266266
statement.addBind(Poco::Data::Keywords::bind(1, "f1"));
267267
statement.execute();
268-
session << "SELECT f1 FROM test", into(f1), now;
269-
assertTrue (f1 == 1);
268+
session << "SELECT f1 FROM test", into(vf1), now;
269+
assertTrue (vf1.size() == 1);
270+
assertTrue (vf1[0] == 1);
270271
statement.removeBind("f1");
271272
statement.addBind(Poco::Data::Keywords::bind(2, "f1"));
272273
statement.execute();
273-
assertTrue (f1 == 2);
274+
vf1.clear();
275+
session << "SELECT f1 FROM test", into(vf1), now;
276+
assertTrue (vf1.size() == 2);
277+
assertTrue (vf1[0] == 1);
278+
assertTrue (vf1[1] == 2);
274279
}
275280

276281

@@ -3501,6 +3506,7 @@ CppUnit::Test* SQLiteTest::suite()
35013506
{
35023507
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SQLiteTest");
35033508

3509+
CppUnit_addTest(pSuite, SQLiteTest, testBind);
35043510
CppUnit_addTest(pSuite, SQLiteTest, testBinding);
35053511
CppUnit_addTest(pSuite, SQLiteTest, testZeroRows);
35063512
CppUnit_addTest(pSuite, SQLiteTest, testSimpleAccess);

Data/include/Poco/Data/Binding.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ class Binding: public AbstractBinding
9898
{
9999
_bound = false;
100100
AbstractBinder::Ptr pBinder = getBinder();
101-
poco_assert_dbg (!pBinder.isNull());
102-
pBinder->reset();
101+
if (pBinder) pBinder->reset();
103102
}
104103

105104
private:
@@ -168,12 +167,10 @@ class CopyBinding: public AbstractBinding
168167
{
169168
_bound = false;
170169
AbstractBinder::Ptr pBinder = getBinder();
171-
poco_assert_dbg (!pBinder.isNull());
172-
pBinder->reset();
170+
if (pBinder) pBinder->reset();
173171
}
174172

175173
private:
176-
//typedef typename TypeWrapper<T>::TYPE ValueType;
177174
ValPtr _pVal;
178175
bool _bound;
179176
};
@@ -230,8 +227,7 @@ class Binding<const char*>: public AbstractBinding
230227
{
231228
_bound = false;
232229
AbstractBinder::Ptr pBinder = getBinder();
233-
poco_assert_dbg (!pBinder.isNull());
234-
pBinder->reset();
230+
if (pBinder) pBinder->reset();
235231
}
236232

237233
private:
@@ -292,8 +288,7 @@ class CopyBinding<const char*>: public AbstractBinding
292288
{
293289
_bound = false;
294290
AbstractBinder::Ptr pBinder = getBinder();
295-
poco_assert_dbg (!pBinder.isNull());
296-
pBinder->reset();
291+
if (pBinder) pBinder->reset();
297292
}
298293

299294
private:

0 commit comments

Comments
 (0)