diff --git a/livesupport/modules/db/src/SimpleConnectionManagerTest.cxx b/livesupport/modules/db/src/SimpleConnectionManagerTest.cxx index cd73b6794..e8eea36c4 100644 --- a/livesupport/modules/db/src/SimpleConnectionManagerTest.cxx +++ b/livesupport/modules/db/src/SimpleConnectionManagerTest.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/SimpleConnectionManagerTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -43,6 +43,7 @@ #include #include #include +#include #include "SimpleConnectionManager.h" #include "SimpleConnectionManagerTest.h" @@ -113,6 +114,11 @@ SimpleConnectionManagerTest :: firstTest(void) CPPUNIT_ASSERT(rs->next()); CPPUNIT_ASSERT(rs->getInt(1) == 1); + rs.reset(); + stmt->close(); + stmt.reset(); + scm->returnConnection(connection); + } catch (std::invalid_argument &e) { CPPUNIT_FAIL(e.what()); } catch (std::runtime_error &e) { @@ -122,3 +128,85 @@ SimpleConnectionManagerTest :: firstTest(void) } } + +/*------------------------------------------------------------------------------ + * Test to handle large integers. + *----------------------------------------------------------------------------*/ +void +SimpleConnectionManagerTest :: bigIntTest(void) + throw (CPPUNIT_NS::Exception) +{ + long long testValue = 0x7fffffffffffffffLL; + std::string createStmt = "CREATE TABLE testTable\n" + "(\n" + " id BIGINT NOT NULL\n" + ");"; + bool b; + + try { + xmlpp::DomParser parser; + const xmlpp::Document * document = getConfigDocument(parser, + configFileName); + const xmlpp::Element * root = document->get_root_node(); + Ptr::Ref scm(new SimpleConnectionManager()); + + scm->configure(*root); + + Ptr::Ref connection = scm->getConnection(); + CPPUNIT_ASSERT(connection); + + // simply see if selecting the highest 63 bit number works... + Ptr::Ref pstmt(connection->prepareStatement( + "SELECT ?")); + pstmt->setLong(1, testValue); + Ptr::Ref rs(pstmt->executeQuery()); + CPPUNIT_ASSERT(rs->next()); + CPPUNIT_ASSERT(rs->getLong(1) == testValue); + rs.reset(); + pstmt->close(); + pstmt.reset(); + + // so far, so good. now create a table with a BIGINT column + // and try the same + Ptr::Ref stmt(connection->createStatement()); + stmt->execute(createStmt); + stmt->close(); + stmt.reset(); + + pstmt.reset(connection->prepareStatement("INSERT INTO testTable " + " VALUES(?)")); + pstmt->setLong(1, testValue); + CPPUNIT_ASSERT(pstmt->executeUpdate() == 1); + pstmt->close(); + pstmt.reset(); + + stmt.reset(connection->createStatement()); + rs.reset(stmt->executeQuery("SELECT * FROM testTable")); + CPPUNIT_ASSERT(rs->next()); +//std::cerr << std::endl; +//std::cerr << "rs->getLong: " << rs->getLong(1) << std::endl; +//std::cerr << "testValue: " << testValue << std::endl; + b = rs->getLong(1) == testValue; + CPPUNIT_ASSERT(b); + rs.reset(); + stmt->close(); + stmt.reset(); + + stmt.reset(connection->createStatement()); + stmt->executeUpdate("DROP TABLE testTable"); + stmt->close(); + stmt.reset(); + + scm->returnConnection(connection); + + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL(e.what()); + } catch (std::runtime_error &e) { + CPPUNIT_FAIL(e.what()); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL(e.what()); + } catch (SQLException &e) { + CPPUNIT_FAIL(e.what()); + } +} + diff --git a/livesupport/modules/db/src/SimpleConnectionManagerTest.h b/livesupport/modules/db/src/SimpleConnectionManagerTest.h index 51b142422..a7a8de0ca 100644 --- a/livesupport/modules/db/src/SimpleConnectionManagerTest.h +++ b/livesupport/modules/db/src/SimpleConnectionManagerTest.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/SimpleConnectionManagerTest.h,v $ ------------------------------------------------------------------------------*/ @@ -63,13 +63,14 @@ using namespace LiveSupport::Core; * Unit test for the SimpleConnectionManager class. * * @author $Author: maroy $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * @see SimpleConnectionManager */ class SimpleConnectionManagerTest : public BaseTestMethod { CPPUNIT_TEST_SUITE(SimpleConnectionManagerTest); CPPUNIT_TEST(firstTest); + CPPUNIT_TEST(bigIntTest); CPPUNIT_TEST_SUITE_END(); protected: @@ -82,6 +83,14 @@ class SimpleConnectionManagerTest : public BaseTestMethod void firstTest(void) throw (CPPUNIT_NS::Exception); + /** + * A test to handle large integers. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + bigIntTest(void) throw (CPPUNIT_NS::Exception); + public: /**