From 5ceff5fb8d1f1c9edcd53f73fe4bcc4029fc45a0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 17 Oct 2015 22:11:44 +0100 Subject: Add support for getting last insert value --- libmysqlpp/unittests/Jamfile.jam | 1 + libmysqlpp/unittests/mysqlschema.sql | 4 ++++ libmysqlpp/unittests/testmysql.cpp | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) (limited to 'libmysqlpp/unittests') diff --git a/libmysqlpp/unittests/Jamfile.jam b/libmysqlpp/unittests/Jamfile.jam index ed3e78e..167939a 100644 --- a/libmysqlpp/unittests/Jamfile.jam +++ b/libmysqlpp/unittests/Jamfile.jam @@ -17,6 +17,7 @@ run boost_utf boost_system boost_filesystem + mysqlschema.sql : testmysql ; diff --git a/libmysqlpp/unittests/mysqlschema.sql b/libmysqlpp/unittests/mysqlschema.sql index 58724c8..5ca3203 100644 --- a/libmysqlpp/unittests/mysqlschema.sql +++ b/libmysqlpp/unittests/mysqlschema.sql @@ -12,3 +12,7 @@ CREATE TABLE bulktest( intcol int, stringcol varchar(3000)); +CREATE TABLE inserts( + id int auto_increment, + num int, + primary key(id)); diff --git a/libmysqlpp/unittests/testmysql.cpp b/libmysqlpp/unittests/testmysql.cpp index bcbe528..9b0eae2 100644 --- a/libmysqlpp/unittests/testmysql.cpp +++ b/libmysqlpp/unittests/testmysql.cpp @@ -140,5 +140,22 @@ BOOST_AUTO_TEST_CASE( bigIterate ) delete ro; } +BOOST_AUTO_TEST_CASE( insertId ) +{ + auto ro = DB::MockDatabase::openConnectionTo("mysqlmock"); + auto ins = ro->newModifyCommand("INSERT INTO inserts(num) VALUES(?)"); + ins->bindParamI(0, 4); + ins->execute(); + BOOST_REQUIRE_EQUAL(1, ro->insertId()); + ins->bindParamI(0, 40); + ins->execute(); + BOOST_REQUIRE_EQUAL(2, ro->insertId()); + ins->bindParamI(0, -4); + ins->execute(); + BOOST_REQUIRE_EQUAL(3, ro->insertId()); + delete ins; + delete ro; +} + BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3