@@ -305,6 +305,48 @@ void SQLiteTest::testBind()
305305}
306306
307307
308+ void SQLiteTest::testAddBindingReuse ()
309+ {
310+ Session session (Poco::Data::SQLite::Connector::KEY, " dummy.db" );
311+ session << " DROP TABLE IF EXISTS test" , now;
312+ session << " CREATE TABLE test (id INTEGER, name VARCHAR(30))" , now;
313+ session << " INSERT INTO test VALUES(1, 'Alice')" , now;
314+ session << " INSERT INTO test VALUES(2, 'Bob')" , now;
315+ session << " INSERT INTO test VALUES(3, 'Charlie')" , now;
316+
317+ Statement stmt (session);
318+ stmt << " SELECT name FROM test WHERE id = ?" ;
319+
320+ // first execute
321+ int id = 1 ;
322+ Poco::Data::AbstractBindingVec bindings;
323+ bindings.push_back (Poco::Data::Keywords::bind (id, " id" ));
324+ stmt.addBinding (bindings, true );
325+ std::string name;
326+ stmt.addExtract (into (name));
327+ stmt.execute ();
328+ assertTrue (name == " Alice" );
329+
330+ // second execute with new binding — this is the bug scenario from #5220
331+ id = 2 ;
332+ Poco::Data::AbstractBindingVec bindings2;
333+ bindings2.push_back (Poco::Data::Keywords::bind (id, " id" ));
334+ stmt.addBinding (bindings2, true );
335+ name.clear ();
336+ stmt.execute ();
337+ assertTrue (name == " Bob" );
338+
339+ // third execute to confirm repeated reuse
340+ id = 3 ;
341+ Poco::Data::AbstractBindingVec bindings3;
342+ bindings3.push_back (Poco::Data::Keywords::bind (id, " id" ));
343+ stmt.addBinding (bindings3, true );
344+ name.clear ();
345+ stmt.execute ();
346+ assertTrue (name == " Charlie" );
347+ }
348+
349+
308350void SQLiteTest::testBinding ()
309351{
310352 Session tmp (Poco::Data::SQLite::Connector::KEY, " dummy.db" );
@@ -4061,6 +4103,7 @@ CppUnit::Test* SQLiteTest::suite()
40614103 CppUnit_addTest (pSuite, SQLiteTest, testIllegalFilePath);
40624104 CppUnit_addTest (pSuite, SQLiteTest, testTransactionTypeProperty);
40634105 CppUnit_addTest (pSuite, SQLiteTest, testRecordsetCopyMove);
4106+ CppUnit_addTest (pSuite, SQLiteTest, testAddBindingReuse);
40644107
40654108 return pSuite;
40664109}
0 commit comments