diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 144c068d9554b93fb93d616c9f4fc130d1d0ef88..f8fa6150fd1511fd0ab5b3112b5057ae2564ee6e 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -752,7 +752,7 @@ void RdbmsCatalogue::createTapePool( stmt.bindString(":VO", vo); stmt.bindUint64(":NB_PARTIAL_TAPES", nbPartialTapes); stmt.bindBool(":IS_ENCRYPTED", encryptionValue); - stmt.bindOptionalString(":SUPPLY", supply); + stmt.bindString(":SUPPLY", supply); stmt.bindString(":USER_COMMENT", comment); @@ -1281,7 +1281,7 @@ void RdbmsCatalogue::modifyTapePoolSupply(const common::dataStructures::Security "TAPE_POOL_NAME = :TAPE_POOL_NAME"; auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql); - stmt.bindOptionalString(":SUPPLY", optionalSupply); + stmt.bindString(":SUPPLY", optionalSupply); stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); stmt.bindUint64(":LAST_UPDATE_TIME", now); @@ -2701,7 +2701,7 @@ uint64_t RdbmsCatalogue::getNbFilesOnTape(rdbms::Conn& conn, const std::string& "WHERE VID = :VID "; auto stmt = conn.createStmt(sql); - + stmt.bindString(":VID", vid); auto rset = stmt.executeQuery(); rset.next(); @@ -3101,7 +3101,7 @@ void RdbmsCatalogue::modifyTapeEncryptionKeyName(const common::dataStructures::S "VID = :VID"; auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql); - stmt.bindOptionalString(":ENCRYPTION_KEY_NAME", optionalEncryptionKeyName); + stmt.bindString(":ENCRYPTION_KEY_NAME", optionalEncryptionKeyName); stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); stmt.bindUint64(":LAST_UPDATE_TIME", now); @@ -4677,7 +4677,7 @@ void RdbmsCatalogue::createActivitiesFairShareWeight(const common::dataStructure stmt.bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt.bindString(":ACTIVITY", activity); stmt.bindString(":WEIGHT", std::to_string(weight)); - + stmt.bindString(":USER_COMMENT", comment); stmt.bindString(":CREATION_LOG_USER_NAME", admin.username); @@ -4739,7 +4739,7 @@ void RdbmsCatalogue::modifyActivitiesFairShareWeight(const common::dataStructure stmt.bindString(":DISK_INSTANCE_NAME", diskInstanceName); stmt.bindString(":ACTIVITY", activity); stmt.bindString(":WEIGHT", std::to_string(weight)); - + stmt.bindString(":USER_COMMENT", comment); stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); @@ -4969,22 +4969,22 @@ void RdbmsCatalogue::createDiskSystem( ":LAST_UPDATE_TIME)"; auto stmt = conn.createStmt(sql); - stmt.bindString(":DISK_SYSTEM_NAME", name); - stmt.bindString(":FILE_REGEXP", fileRegexp); - stmt.bindString(":FREE_SPACE_QUERY_URL", freeSpaceQueryURL); - stmt.bindUint64(":REFRESH_INTERVAL", refreshInterval); - stmt.bindUint64(":TARGETED_FREE_SPACE", targetedFreeSpace); - stmt.bindUint64(":SLEEP_TIME", sleepTime); + stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.bindString(":FILE_REGEXP", fileRegexp); + stmt.bindString(":FREE_SPACE_QUERY_URL", freeSpaceQueryURL); + stmt.bindUint64(":REFRESH_INTERVAL", refreshInterval); + stmt.bindUint64(":TARGETED_FREE_SPACE", targetedFreeSpace); + stmt.bindUint64(":SLEEP_TIME", sleepTime); - stmt.bindString(":USER_COMMENT", comment); + stmt.bindString(":USER_COMMENT", comment); - stmt.bindString(":CREATION_LOG_USER_NAME", admin.username); - stmt.bindString(":CREATION_LOG_HOST_NAME", admin.host); - stmt.bindUint64(":CREATION_LOG_TIME", now); + stmt.bindString(":CREATION_LOG_USER_NAME", admin.username); + stmt.bindString(":CREATION_LOG_HOST_NAME", admin.host); + stmt.bindUint64(":CREATION_LOG_TIME", now); - stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); - stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); - stmt.bindUint64(":LAST_UPDATE_TIME", now); + stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); + stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); + stmt.bindUint64(":LAST_UPDATE_TIME", now); stmt.executeNonQuery(); } catch(exception::UserError &) { @@ -5008,7 +5008,7 @@ void RdbmsCatalogue::deleteDiskSystem(const std::string &name) { "DISK_SYSTEM_NAME = :DISK_SYSTEM_NAME"; auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(delete_sql); - stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.bindString(":DISK_SYSTEM_NAME", name); stmt.executeNonQuery(); // The delete statement will effect no rows and will not raise an error if @@ -5133,11 +5133,11 @@ void RdbmsCatalogue::modifyDiskSystemRefreshInterval(const common::dataStructure "DISK_SYSTEM_NAME = :DISK_SYSTEM_NAME"; auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql); - stmt.bindUint64(":REFRESH_INTERVAL", refreshInterval); - stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); - stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); - stmt.bindUint64(":LAST_UPDATE_TIME", now); - stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.bindUint64(":REFRESH_INTERVAL", refreshInterval); + stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); + stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); + stmt.bindUint64(":LAST_UPDATE_TIME", now); + stmt.bindString(":DISK_SYSTEM_NAME", name); stmt.executeNonQuery(); if(0 == stmt.getNbAffectedRows()) { @@ -5174,11 +5174,11 @@ void RdbmsCatalogue::modifyDiskSystemTargetedFreeSpace(const common::dataStructu "DISK_SYSTEM_NAME = :DISK_SYSTEM_NAME"; auto conn = m_connPool.getConn(); auto stmt = conn.createStmt(sql); - stmt.bindUint64(":TARGETED_FREE_SPACE", targetedFreeSpace); - stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); - stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); - stmt.bindUint64(":LAST_UPDATE_TIME", now); - stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.bindUint64(":TARGETED_FREE_SPACE", targetedFreeSpace); + stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); + stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); + stmt.bindUint64(":LAST_UPDATE_TIME", now); + stmt.bindString(":DISK_SYSTEM_NAME", name); stmt.executeNonQuery(); if(0 == stmt.getNbAffectedRows()) { @@ -6340,12 +6340,12 @@ void RdbmsCatalogue::insertTapeFile( " ( TAPE_FILE.VID <> :NEW_VID2 OR TAPE_FILE.FSEQ <> :NEW_FSEQ2 )"; auto stmt = conn.createStmt(sql); - stmt.bindString(":NEW_VID",tapeFile.vid); - stmt.bindUint64(":NEW_FSEQ",tapeFile.fSeq); - stmt.bindString(":NEW_VID2",tapeFile.vid); - stmt.bindUint64(":NEW_FSEQ2",tapeFile.fSeq); - stmt.bindUint64(":ARCHIVE_FILE_ID",archiveFileId); - stmt.bindUint64(":COPY_NB",tapeFile.copyNb); + stmt.bindString(":NEW_VID", tapeFile.vid); + stmt.bindUint64(":NEW_FSEQ", tapeFile.fSeq); + stmt.bindString(":NEW_VID2", tapeFile.vid); + stmt.bindUint64(":NEW_FSEQ2", tapeFile.fSeq); + stmt.bindUint64(":ARCHIVE_FILE_ID", archiveFileId); + stmt.bindUint64(":COPY_NB", tapeFile.copyNb); stmt.executeNonQuery(); } conn.commit(); diff --git a/rdbms/Stmt.cpp b/rdbms/Stmt.cpp index 1278189c39df651e07bb01071bf14efc2b511cd6..8377399c1cbe69a8a4e5c66f9e7c29333591c243 100644 --- a/rdbms/Stmt.cpp +++ b/rdbms/Stmt.cpp @@ -119,22 +119,10 @@ uint32_t Stmt::getParamIdx(const std::string ¶mName) const { //----------------------------------------------------------------------------- // bindUint8 //----------------------------------------------------------------------------- -void Stmt::bindUint8(const std::string ¶mName, const uint8_t paramValue) { - try { - bindOptionalUint8(paramName, paramValue); - } catch(exception::Exception &ex) { - ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - throw; - } -} - -//----------------------------------------------------------------------------- -// bindOptionalUint8 -//----------------------------------------------------------------------------- -void Stmt::bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { +void Stmt::bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { try { if(nullptr != m_stmt) { - return m_stmt->bindOptionalUint8(paramName, paramValue); + return m_stmt->bindUint8(paramName, paramValue); } else { throw exception::Exception("Stmt does not contain a cached statement"); } @@ -147,22 +135,10 @@ void Stmt::bindOptionalUint8(const std::string ¶mName, const optional<uint8_ //----------------------------------------------------------------------------- // bindUint16 //----------------------------------------------------------------------------- -void Stmt::bindUint16(const std::string ¶mName, const uint16_t paramValue) { - try { - bindOptionalUint16(paramName, paramValue); - } catch(exception::Exception &ex) { - ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - throw; - } -} - -//----------------------------------------------------------------------------- -// bindOptionalUint16 -//----------------------------------------------------------------------------- -void Stmt::bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { +void Stmt::bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { try { if(nullptr != m_stmt) { - return m_stmt->bindOptionalUint16(paramName, paramValue); + return m_stmt->bindUint16(paramName, paramValue); } else { throw exception::Exception("Stmt does not contain a cached statement"); } @@ -175,22 +151,10 @@ void Stmt::bindOptionalUint16(const std::string ¶mName, const optional<uint1 //----------------------------------------------------------------------------- // bindUint32 //----------------------------------------------------------------------------- -void Stmt::bindUint32(const std::string ¶mName, const uint32_t paramValue) { - try { - bindOptionalUint32(paramName, paramValue); - } catch(exception::Exception &ex) { - ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - throw; - } -} - -//----------------------------------------------------------------------------- -// bindOptionalUint32 -//----------------------------------------------------------------------------- -void Stmt::bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { +void Stmt::bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { try { if(nullptr != m_stmt) { - return m_stmt->bindOptionalUint32(paramName, paramValue); + return m_stmt->bindUint32(paramName, paramValue); } else { throw exception::Exception("Stmt does not contain a cached statement"); } @@ -203,22 +167,10 @@ void Stmt::bindOptionalUint32(const std::string ¶mName, const optional<uint3 //----------------------------------------------------------------------------- // bindUint64 //----------------------------------------------------------------------------- -void Stmt::bindUint64(const std::string ¶mName, const uint64_t paramValue) { - try { - bindOptionalUint64(paramName, paramValue); - } catch(exception::Exception &ex) { - ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - throw; - } -} - -//----------------------------------------------------------------------------- -// bindOptionalUint64 -//----------------------------------------------------------------------------- -void Stmt::bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { +void Stmt::bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { try { if(nullptr != m_stmt) { - return m_stmt->bindOptionalUint64(paramName, paramValue); + return m_stmt->bindUint64(paramName, paramValue); } else { throw exception::Exception("Stmt does not contain a cached statement"); } @@ -231,22 +183,10 @@ void Stmt::bindOptionalUint64(const std::string ¶mName, const optional<uint6 //----------------------------------------------------------------------------- // bindDouble //----------------------------------------------------------------------------- -void Stmt::bindDouble(const std::string ¶mName, const double paramValue) { - try { - bindOptionalDouble(paramName, paramValue); - } catch(exception::Exception &ex) { - ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - throw; - } -} - -//----------------------------------------------------------------------------- -// bindOptionalDouble -//----------------------------------------------------------------------------- -void Stmt::bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) { +void Stmt::bindDouble(const std::string ¶mName, const optional<double> ¶mValue) { try { if(nullptr != m_stmt) { - return m_stmt->bindOptionalDouble(paramName, paramValue); + return m_stmt->bindDouble(paramName, paramValue); } else { throw exception::Exception("Stmt does not contain a cached statement"); } @@ -259,22 +199,10 @@ void Stmt::bindOptionalDouble(const std::string ¶mName, const optional<doubl //----------------------------------------------------------------------------- // bindBool //----------------------------------------------------------------------------- -void Stmt::bindBool(const std::string ¶mName, const bool paramValue) { - try { - bindOptionalBool(paramName, paramValue); - } catch(exception::Exception &ex) { - ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - throw; - } -} - -//----------------------------------------------------------------------------- -// bindOptionalBool -//----------------------------------------------------------------------------- -void Stmt::bindOptionalBool(const std::string ¶mName, const optional<bool> ¶mValue) { +void Stmt::bindBool(const std::string ¶mName, const optional<bool> ¶mValue) { try { if(nullptr != m_stmt) { - return m_stmt->bindOptionalBool(paramName, paramValue); + return m_stmt->bindBool(paramName, paramValue); } else { throw exception::Exception("Stmt does not contain a cached statement"); } @@ -285,7 +213,7 @@ void Stmt::bindOptionalBool(const std::string ¶mName, const optional<bool> & } //----------------------------------------------------------------------------- -// bindString +// bindBlob //----------------------------------------------------------------------------- void Stmt::bindBlob(const std::string ¶mName, const std::string ¶mValue) { try { @@ -303,22 +231,10 @@ void Stmt::bindBlob(const std::string ¶mName, const std::string ¶mValue) //----------------------------------------------------------------------------- // bindString //----------------------------------------------------------------------------- -void Stmt::bindString(const std::string ¶mName, const std::string ¶mValue) { - try { - bindOptionalString(paramName, paramValue); - } catch(exception::Exception &ex) { - ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - throw; - } -} - -//----------------------------------------------------------------------------- -// bindOptionalString -//----------------------------------------------------------------------------- -void Stmt::bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) { +void Stmt::bindString(const std::string ¶mName, const optional<std::string> ¶mValue) { try { if(nullptr != m_stmt) { - return m_stmt->bindOptionalString(paramName, paramValue); + return m_stmt->bindString(paramName, paramValue); } else { throw exception::Exception("Stmt does not contain a cached statement"); } diff --git a/rdbms/Stmt.hpp b/rdbms/Stmt.hpp index 46ca37676837d91200d4c7143dd503b4a20d1626..1e795a9f375242d3c031799fc3334a40a22286b6 100644 --- a/rdbms/Stmt.hpp +++ b/rdbms/Stmt.hpp @@ -109,7 +109,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindUint8(const std::string ¶mName, const uint8_t paramValue); + void bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue); /** * Binds an SQL parameter. @@ -117,7 +117,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue); + void bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue); /** * Binds an SQL parameter. @@ -125,7 +125,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindUint16(const std::string ¶mName, const uint16_t paramValue); + void bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue); /** * Binds an SQL parameter. @@ -133,7 +133,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue); + void bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue); /** * Binds an SQL parameter. @@ -141,7 +141,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindUint32(const std::string ¶mName, const uint32_t paramValue); + void bindDouble(const std::string ¶mName, const optional<double> ¶mValue); /** * Binds an SQL parameter. @@ -149,55 +149,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue); - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint64(const std::string ¶mName, const uint64_t paramValue); - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue); - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindDouble(const std::string ¶mName, const double paramValue); - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue); - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindBool(const std::string ¶mName, const bool paramValue); - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindOptionalBool(const std::string ¶mName, const optional<bool> ¶mValue); + void bindBool(const std::string ¶mName, const optional<bool> ¶mValue); /** * Binds an SQL parameter of type binary blob. @@ -207,18 +159,6 @@ public: */ void bindBlob(const std::string ¶mName, const std::string ¶mValue); - /** - * Binds an SQL parameter of type string. - * - * Please note that this method will throw an exception if the string - * parameter is empty. If a null value is to be bound then the - * bindOptionalString() method should be used. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindString(const std::string ¶mName, const std::string ¶mValue); - /** * Binds an SQL parameter of type optional-string. * @@ -229,7 +169,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue); + void bindString(const std::string ¶mName, const optional<std::string> ¶mValue); /** * Executes the statement and returns the result set. diff --git a/rdbms/StmtTest.cpp b/rdbms/StmtTest.cpp index 34dff45f94f2a9b9a5a7d9b737bae20f013f84ea..3d38d61907083dea9055ffee1ec5b3ec849a43e7 100644 --- a/rdbms/StmtTest.cpp +++ b/rdbms/StmtTest.cpp @@ -188,7 +188,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindDouble) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalDouble_null) { +TEST_P(cta_rdbms_StmtTest, insert_with_bindDouble_null) { using namespace cta::rdbms; const cta::optional<double> insertValue; // Null value @@ -203,7 +203,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalDouble_null) { " 1," "\n" " :DOUBLE_COL)"; auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalDouble(":DOUBLE_COL", insertValue); + stmt.bindDouble(":DOUBLE_COL", insertValue); stmt.executeNonQuery(); } @@ -316,7 +316,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindUint8_2_pow_8_minus_1) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint8_null) { +TEST_P(cta_rdbms_StmtTest, insert_with_bindUint8_null) { using namespace cta::rdbms; const cta::optional<uint8_t> insertValue; // Null value @@ -331,7 +331,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint8_null) { " 1," "\n" " :UINT8_COL)"; auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalUint8(":UINT8_COL", insertValue); + stmt.bindUint8(":UINT8_COL", insertValue); stmt.executeNonQuery(); } @@ -356,47 +356,6 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint8_null) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint8) { - using namespace cta::rdbms; - - const cta::optional<uint8_t> insertValue = 123; - - // Insert a row into the test table - { - const char *const sql = - "INSERT INTO STMT_TEST(" "\n" - " ID," "\n" - " UINT8_COL) " "\n" - "VALUES(" "\n" - " 1," "\n" - " :UINT8_COL)"; - auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalUint8(":UINT8_COL", insertValue); - stmt.executeNonQuery(); - } - - // Select the row back from the table - { - const char *const sql = - "SELECT" "\n" - " UINT8_COL AS UINT8_COL" "\n" - "FROM" "\n" - " STMT_TEST"; - auto stmt = m_conn.createStmt(sql); - auto rset = stmt.executeQuery(); - ASSERT_TRUE(rset.next()); - - const auto selectValue = rset.columnOptionalUint8("UINT8_COL"); - - ASSERT_TRUE((bool)selectValue); - - ASSERT_EQ(insertValue, selectValue.value()); - - ASSERT_EQ(insertValue, rset.columnUint8("UINT8_COL")); - - ASSERT_FALSE(rset.next()); - } -} TEST_P(cta_rdbms_StmtTest, insert_with_bindUint16) { using namespace cta::rdbms; @@ -482,7 +441,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindUint16_2_pow_16_minus_1) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint16_null) { +TEST_P(cta_rdbms_StmtTest, insert_with_bindUint16_null) { using namespace cta::rdbms; const cta::optional<uint16_t> insertValue; // Null value @@ -497,7 +456,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint16_null) { " 1," "\n" " :UINT16_COL)"; auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalUint16(":UINT16_COL", insertValue); + stmt.bindUint16(":UINT16_COL", insertValue); stmt.executeNonQuery(); } @@ -522,48 +481,6 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint16_null) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint16) { - using namespace cta::rdbms; - - const cta::optional<uint16_t> insertValue = 1234; - - // Insert a row into the test table - { - const char *const sql = - "INSERT INTO STMT_TEST(" "\n" - " ID," "\n" - " UINT16_COL) " "\n" - "VALUES(" "\n" - " 1," "\n" - " :UINT16_COL)"; - auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalUint16(":UINT16_COL", insertValue); - stmt.executeNonQuery(); - } - - // Select the row back from the table - { - const char *const sql = - "SELECT" "\n" - " UINT16_COL AS UINT16_COL" "\n" - "FROM" "\n" - " STMT_TEST"; - auto stmt = m_conn.createStmt(sql); - auto rset = stmt.executeQuery(); - ASSERT_TRUE(rset.next()); - - const auto selectValue = rset.columnOptionalUint16("UINT16_COL"); - - ASSERT_TRUE((bool)selectValue); - - ASSERT_EQ(insertValue, selectValue.value()); - - ASSERT_EQ(insertValue, rset.columnUint16("UINT16_COL")); - - ASSERT_FALSE(rset.next()); - } -} - TEST_P(cta_rdbms_StmtTest, insert_with_bindUint32) { using namespace cta::rdbms; @@ -647,7 +564,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindUint32_2_pow_32_minus_1) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint32_null) { +TEST_P(cta_rdbms_StmtTest, insert_with_bindUint32_null) { using namespace cta::rdbms; const cta::optional<uint32_t> insertValue; // Null value @@ -662,7 +579,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint32_null) { " 1," "\n" " :UINT32_COL)"; auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalUint32(":UINT32_COL", insertValue); + stmt.bindUint32(":UINT32_COL", insertValue); stmt.executeNonQuery(); } @@ -687,48 +604,6 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint32_null) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalUint32) { - using namespace cta::rdbms; - - const cta::optional<uint32_t> insertValue = 1234; - - // Insert a row into the test table - { - const char *const sql = - "INSERT INTO STMT_TEST(" "\n" - " ID," "\n" - " UINT32_COL) " "\n" - "VALUES(" "\n" - " 1," "\n" - " :UINT32_COL)"; - auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalUint32(":UINT32_COL", insertValue); - stmt.executeNonQuery(); - } - - // Select the row back from the table - { - const char *const sql = - "SELECT" "\n" - " UINT32_COL AS UINT32_COL" "\n" - "FROM" "\n" - " STMT_TEST"; - auto stmt = m_conn.createStmt(sql); - auto rset = stmt.executeQuery(); - ASSERT_TRUE(rset.next()); - - const auto selectValue = rset.columnOptionalUint32("UINT32_COL"); - - ASSERT_TRUE((bool)selectValue); - - ASSERT_EQ(insertValue, selectValue.value()); - - ASSERT_EQ(insertValue, rset.columnOptionalUint32("UINT32_COL")); - - ASSERT_FALSE(rset.next()); - } -} - TEST_P(cta_rdbms_StmtTest, insert_with_bindUint64) { using namespace cta::rdbms; @@ -855,7 +730,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindUint64_2_pow_64_minus_2) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalString_null) { +TEST_P(cta_rdbms_StmtTest, insert_with_bindString_null) { using namespace cta::rdbms; const cta::optional<std::string> insertValue; // Null value @@ -870,7 +745,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalString_null) { " 1," "\n" " :STRING_COL)"; auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalString(":STRING_COL", insertValue); + stmt.bindString(":STRING_COL", insertValue); stmt.executeNonQuery(); } @@ -937,7 +812,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindString) { } } -TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalBool_null) { +TEST_P(cta_rdbms_StmtTest, insert_with_bindBool_null) { using namespace cta::rdbms; const cta::optional<bool> insertValue; // Null value @@ -952,7 +827,7 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindOptionalBool_null) { " 1," "\n" " :BOOL_COL)"; auto stmt = m_conn.createStmt(sql); - stmt.bindOptionalBool(":BOOL_COL", insertValue); + stmt.bindBool(":BOOL_COL", insertValue); stmt.executeNonQuery(); } diff --git a/rdbms/wrapper/MysqlConn.cpp b/rdbms/wrapper/MysqlConn.cpp index 47b347f005c3d74c5b890da11d1896d2d297ac0e..1a93a556c8c43f6f62371fe570735dd314f8f92e 100644 --- a/rdbms/wrapper/MysqlConn.cpp +++ b/rdbms/wrapper/MysqlConn.cpp @@ -219,7 +219,7 @@ std::map<std::string, std::string> MysqlConn::getColumns(const std::string &tabl "TABLE_NAME = :TABLE_NAME"; auto stmt = createStmt(sql); - stmt->bindOptionalString(":TABLE_NAME", tableName); + stmt->bindString(":TABLE_NAME", tableName); auto rset = stmt->executeQuery(); while (rset->next()) { auto name = rset->columnOptionalString("COLUMN_NAME"); diff --git a/rdbms/wrapper/MysqlConnTest.cpp b/rdbms/wrapper/MysqlConnTest.cpp index e7fa24fa3dcae255fac46f98cf3e874f8db50db4..46fd4ba104c1f57d2b02dae3eb53230c95d08d5e 100644 --- a/rdbms/wrapper/MysqlConnTest.cpp +++ b/rdbms/wrapper/MysqlConnTest.cpp @@ -194,14 +194,14 @@ TEST_F(DISABLED_cta_rdbms_wrapper_MysqlConnTest, create_stmt_named_binding) { // try to test with null stmt->bindUint64(":col1", 1); - stmt->bindOptionalString(":col2", optional<std::string>()); - // stmt->bindOptionalString(":col2", nullopt); + stmt->bindString(":col2", optional<std::string>()); + // stmt->bindString(":col2", nullopt); stmt->bindUint64(":col3", 3); stmt->executeNonQuery(AutocommitMode::AUTOCOMMIT_OFF); - stmt->bindOptionalUint64(":col1", nullopt); - stmt->bindOptionalString(":col2", optional<std::string>()); - // stmt->bindOptionalString(":col2", nullopt); + stmt->bindUint64(":col1", nullopt); + stmt->bindString(":col2", optional<std::string>()); + // stmt->bindString(":col2", nullopt); stmt->bindUint64(":col3", 3); stmt->executeNonQuery(AutocommitMode::AUTOCOMMIT_OFF); diff --git a/rdbms/wrapper/MysqlStmt.cpp b/rdbms/wrapper/MysqlStmt.cpp index 249ffbf424b15242021d53008cb11bf6231362e7..375a61572fc56e3355ea16cffc401a436fd15a9b 100644 --- a/rdbms/wrapper/MysqlStmt.cpp +++ b/rdbms/wrapper/MysqlStmt.cpp @@ -171,9 +171,9 @@ MYSQL_STMT *MysqlStmt::get() const { } //------------------------------------------------------------------------------ -// bindOptionalUint8 +// bindUint8 //------------------------------------------------------------------------------ -void MysqlStmt::bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { +void MysqlStmt::bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); // starts from 1. const unsigned int idx = paramIdx - 1; @@ -205,9 +205,9 @@ void MysqlStmt::bindOptionalUint8(const std::string ¶mName, const optional<u } //------------------------------------------------------------------------------ -// bindOptionalUint16 +// bindUint16 //------------------------------------------------------------------------------ -void MysqlStmt::bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { +void MysqlStmt::bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); // starts from 1. const unsigned int idx = paramIdx - 1; @@ -239,9 +239,9 @@ void MysqlStmt::bindOptionalUint16(const std::string ¶mName, const optional< } //------------------------------------------------------------------------------ -// bindOptionalUint32 +// bindUint32 //------------------------------------------------------------------------------ -void MysqlStmt::bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { +void MysqlStmt::bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); // starts from 1. const unsigned int idx = paramIdx - 1; @@ -273,9 +273,9 @@ void MysqlStmt::bindOptionalUint32(const std::string ¶mName, const optional< } //------------------------------------------------------------------------------ -// bindOptionalUint64 +// bindUint64 //------------------------------------------------------------------------------ -void MysqlStmt::bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { +void MysqlStmt::bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); // starts from 1. const unsigned int idx = paramIdx - 1; @@ -307,9 +307,9 @@ void MysqlStmt::bindOptionalUint64(const std::string ¶mName, const optional< } //------------------------------------------------------------------------------ -// bindOptionalDouble +// bindDouble //------------------------------------------------------------------------------ -void MysqlStmt::bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) { +void MysqlStmt::bindDouble(const std::string ¶mName, const optional<double> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); // starts from 1. const unsigned int idx = paramIdx - 1; @@ -342,16 +342,16 @@ void MysqlStmt::bindOptionalDouble(const std::string ¶mName, const optional< void MysqlStmt::bindBlob(const std::string ¶mName, const std::string ¶mValue) { try { - bindOptionalString(paramName, paramValue); + bindString(paramName, paramValue); } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } } //------------------------------------------------------------------------------ -// bindOptionalString +// bindString //------------------------------------------------------------------------------ -void MysqlStmt::bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) { +void MysqlStmt::bindString(const std::string ¶mName, const optional<std::string> ¶mValue) { try { if(paramValue && paramValue.value().empty()) { throw exception::Exception(std::string("Optional string parameter ") + paramName + " is an empty string. " diff --git a/rdbms/wrapper/MysqlStmt.hpp b/rdbms/wrapper/MysqlStmt.hpp index ee2ff15a578e414c351bad0aae3867f3215b3c84..7e78973f6f896de78c663d33ccf0aa1393b8a9ff 100644 --- a/rdbms/wrapper/MysqlStmt.hpp +++ b/rdbms/wrapper/MysqlStmt.hpp @@ -90,7 +90,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; + void bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -98,7 +98,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; + void bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -106,7 +106,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; + void bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -114,7 +114,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; + void bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -122,7 +122,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) override; + void bindDouble(const std::string ¶mName, const optional<double> ¶mValue) override; /** * Binds an SQL parameter of type binary string (byte array). @@ -142,7 +142,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) override; + void bindString(const std::string ¶mName, const optional<std::string> ¶mValue) override; /** * Executes the statement and returns the result set. diff --git a/rdbms/wrapper/OcciConn.cpp b/rdbms/wrapper/OcciConn.cpp index 2246b1a210738b0d47c76b5e15e7a62f45080acc..f21a20a60da3784161759a12f28a5a0f98332a08 100644 --- a/rdbms/wrapper/OcciConn.cpp +++ b/rdbms/wrapper/OcciConn.cpp @@ -177,7 +177,7 @@ std::map<std::string, std::string> OcciConn::getColumns(const std::string &table "TABLE_NAME = :TABLE_NAME"; auto stmt = createStmt(sql); - stmt->bindOptionalString(":TABLE_NAME", tableName); + stmt->bindString(":TABLE_NAME", tableName); auto rset = stmt->executeQuery(); while (rset->next()) { auto name = rset->columnOptionalString("COLUMN_NAME"); diff --git a/rdbms/wrapper/OcciStmt.cpp b/rdbms/wrapper/OcciStmt.cpp index 44d4854a76908203d21bb6e094ebc72e3d884341..84ee44bc4891c58cfbc1082cc3129b732d31e73a 100644 --- a/rdbms/wrapper/OcciStmt.cpp +++ b/rdbms/wrapper/OcciStmt.cpp @@ -88,11 +88,11 @@ void OcciStmt::close() { } //------------------------------------------------------------------------------ -// bindOptionalUint8 +// bindUint8 //------------------------------------------------------------------------------ -void OcciStmt::bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { +void OcciStmt::bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { try { - return bindOptionalInteger<uint8_t>(paramName, paramValue); + return bindInteger<uint8_t>(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -100,11 +100,11 @@ void OcciStmt::bindOptionalUint8(const std::string ¶mName, const optional<ui } //------------------------------------------------------------------------------ -// bindOptionalUint16 +// bindUint16 //------------------------------------------------------------------------------ -void OcciStmt::bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { +void OcciStmt::bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { try { - return bindOptionalInteger<uint16_t>(paramName, paramValue); + return bindInteger<uint16_t>(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -112,11 +112,11 @@ void OcciStmt::bindOptionalUint16(const std::string ¶mName, const optional<u } //------------------------------------------------------------------------------ -// bindOptionalUint32 +// bindUint32 //------------------------------------------------------------------------------ -void OcciStmt::bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { +void OcciStmt::bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { try { - return bindOptionalInteger<uint32_t>(paramName, paramValue); + return bindInteger<uint32_t>(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -124,11 +124,11 @@ void OcciStmt::bindOptionalUint32(const std::string ¶mName, const optional<u } //------------------------------------------------------------------------------ -// bindOptionalUint64 +// bindUint64 //------------------------------------------------------------------------------ -void OcciStmt::bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { +void OcciStmt::bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { try { - return bindOptionalInteger<uint64_t>(paramName, paramValue); + return bindInteger<uint64_t>(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -143,9 +143,9 @@ void OcciStmt::bindBlob(const std::string ¶mName, const std::string ¶mVa } //------------------------------------------------------------------------------ -// bindOptionalDouble +// bindDouble //------------------------------------------------------------------------------ -void OcciStmt::bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) { +void OcciStmt::bindDouble(const std::string ¶mName, const optional<double> ¶mValue) { try { const unsigned paramIdx = getParamIdx(paramName); if(paramValue) { @@ -164,9 +164,9 @@ void OcciStmt::bindOptionalDouble(const std::string ¶mName, const optional<d } //------------------------------------------------------------------------------ -// bindOptionalString +// bindString //------------------------------------------------------------------------------ -void OcciStmt::bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) { +void OcciStmt::bindString(const std::string ¶mName, const optional<std::string> ¶mValue) { try { if(paramValue && paramValue.value().empty()) { throw exception::Exception(std::string("Optional string parameter ") + paramName + " is an empty string. " diff --git a/rdbms/wrapper/OcciStmt.hpp b/rdbms/wrapper/OcciStmt.hpp index 613f165c5ec247b02abc09eb8f08bcd9f58d3b4f..e9d1d9a958c77e790acd9b2cb1c8deaf9cd414c3 100644 --- a/rdbms/wrapper/OcciStmt.hpp +++ b/rdbms/wrapper/OcciStmt.hpp @@ -87,7 +87,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; + void bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -95,7 +95,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; + void bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -103,7 +103,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; + void bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -111,7 +111,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; + void bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -119,7 +119,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) override; + void bindDouble(const std::string ¶mName, const optional<double> ¶mValue) override; /** * Binds an SQL parameter of type binary string (byte array). @@ -139,7 +139,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) override; + void bindString(const std::string ¶mName, const optional<std::string> ¶mValue) override; /** * Executes the statement and returns the result set. @@ -215,7 +215,7 @@ private: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - template <typename IntegerType> void bindOptionalInteger(const std::string ¶mName, + template <typename IntegerType> void bindInteger(const std::string ¶mName, const optional<IntegerType> ¶mValue) { try { const unsigned paramIdx = getParamIdx(paramName); diff --git a/rdbms/wrapper/PostgresConn.cpp b/rdbms/wrapper/PostgresConn.cpp index bcd4dff4b491c5fce06ccf1e5e15fdacb710f06e..e27ee6792f14e7e0b40beb5de3b21b9c5fced5c7 100644 --- a/rdbms/wrapper/PostgresConn.cpp +++ b/rdbms/wrapper/PostgresConn.cpp @@ -215,7 +215,7 @@ std::map<std::string, std::string> PostgresConn::getColumns(const std::string &t "TABLE_NAME = :TABLE_NAME"; auto stmt = createStmt(sql); - stmt->bindOptionalString(":TABLE_NAME", lowercaseTableName); + stmt->bindString(":TABLE_NAME", lowercaseTableName); auto rset = stmt->executeQuery(); while (rset->next()) { auto name = rset->columnOptionalString("COLUMN_NAME"); diff --git a/rdbms/wrapper/PostgresStmt.cpp b/rdbms/wrapper/PostgresStmt.cpp index 1ca753d2acff0a129638737f8da2079c26261f46..ee2ee006cfacd6e8a3a480a1e7eac00b67c0f7e1 100644 --- a/rdbms/wrapper/PostgresStmt.cpp +++ b/rdbms/wrapper/PostgresStmt.cpp @@ -69,9 +69,9 @@ PostgresStmt::~PostgresStmt() { } //------------------------------------------------------------------------------ -// bindOptionalString +// bindString //------------------------------------------------------------------------------ -void PostgresStmt::bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) { +void PostgresStmt::bindString(const std::string ¶mName, const optional<std::string> ¶mValue) { threading::RWLockWrLocker locker(m_lock); try { if(paramValue && paramValue.value().empty()) { @@ -103,11 +103,11 @@ void PostgresStmt::bindOptionalString(const std::string ¶mName, const option } //------------------------------------------------------------------------------ -// bindOptionalUint8 +// bindUint8 //------------------------------------------------------------------------------ -void PostgresStmt::bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { +void PostgresStmt::bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { try { - return bindOptionalInteger<uint8_t>(paramName, paramValue); + return bindInteger<uint8_t>(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed for SQL statement " + getSqlForException() + ": " + ex.getMessage().str()); @@ -116,11 +116,11 @@ void PostgresStmt::bindOptionalUint8(const std::string ¶mName, const optiona } //------------------------------------------------------------------------------ -// bindOptionalUint16 +// bindUint16 //------------------------------------------------------------------------------ -void PostgresStmt::bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { +void PostgresStmt::bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { try { - return bindOptionalInteger<uint16_t>(paramName, paramValue); + return bindInteger<uint16_t>(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed for SQL statement " + getSqlForException() + ": " + ex.getMessage().str()); @@ -129,11 +129,11 @@ void PostgresStmt::bindOptionalUint16(const std::string ¶mName, const option } //------------------------------------------------------------------------------ -// bindOptionalUint32 +// bindUint32 //------------------------------------------------------------------------------ -void PostgresStmt::bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { +void PostgresStmt::bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { try { - return bindOptionalInteger<uint32_t>(paramName, paramValue); + return bindInteger<uint32_t>(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed for SQL statement " + getSqlForException() + ": " + ex.getMessage().str()); @@ -142,11 +142,11 @@ void PostgresStmt::bindOptionalUint32(const std::string ¶mName, const option } //------------------------------------------------------------------------------ -// bindOptionalUint64 +// bindUint64 //------------------------------------------------------------------------------ -void PostgresStmt::bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { +void PostgresStmt::bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { try { - return bindOptionalInteger<uint64_t>(paramName, paramValue); + return bindInteger<uint64_t>(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed for SQL statement " + getSqlForException() + ": " + ex.getMessage().str()); @@ -162,9 +162,9 @@ void PostgresStmt::bindBlob(const std::string ¶mName, const std::string &par } //------------------------------------------------------------------------------ -// bindOptionalDouble +// bindDouble //------------------------------------------------------------------------------ -void PostgresStmt::bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) { +void PostgresStmt::bindDouble(const std::string ¶mName, const optional<double> ¶mValue) { threading::RWLockWrLocker locker(m_lock); try { diff --git a/rdbms/wrapper/PostgresStmt.hpp b/rdbms/wrapper/PostgresStmt.hpp index f9e4b80e462915ba729f3b4ab03f7a5e55777dff..3c16642df85270bef09b4e7cb16e9e857e5ba92d 100644 --- a/rdbms/wrapper/PostgresStmt.hpp +++ b/rdbms/wrapper/PostgresStmt.hpp @@ -74,7 +74,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) override; + void bindString(const std::string ¶mName, const optional<std::string> ¶mValue) override; /** * Binds an SQL parameter. @@ -82,7 +82,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; + void bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -90,7 +90,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; + void bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -98,7 +98,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; + void bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -106,7 +106,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; + void bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; /** * Binds an SQL parameter of type binary string (byte array). @@ -122,7 +122,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) override; + void bindDouble(const std::string ¶mName, const optional<double> ¶mValue) override; /** * Clears the prepared statement so that it is ready to be reused. @@ -311,7 +311,7 @@ private: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - template <typename IntegerType> void bindOptionalInteger(const std::string ¶mName, + template <typename IntegerType> void bindInteger(const std::string ¶mName, const optional<IntegerType> ¶mValue) { threading::RWLockWrLocker locker(m_lock); diff --git a/rdbms/wrapper/PostgresStmtTest.cpp b/rdbms/wrapper/PostgresStmtTest.cpp index 48a9001c7b6a01aa4afc98aa04a94ab495dda0e9..812a70201e44edcc34a976d4a84ab7248db9b859 100644 --- a/rdbms/wrapper/PostgresStmtTest.cpp +++ b/rdbms/wrapper/PostgresStmtTest.cpp @@ -250,9 +250,9 @@ TEST_F(DISABLED_cta_rdbms_wrapper_PostgresStmtTest, insert_with_bind) { ":COL2," ":COL3);"; auto stmt = m_conn->createStmt(sql); - stmt->bindOptionalString(":COL1", std::string("one")); - stmt->bindOptionalString(":COL2", std::string("two")); - stmt->bindOptionalUint64(":COL3", 3); + stmt->bindString(":COL1", "one"); + stmt->bindString(":COL2", "two"); + stmt->bindUint64(":COL3", 3); stmt->executeNonQuery(); } @@ -402,7 +402,7 @@ TEST_F(DISABLED_cta_rdbms_wrapper_PostgresStmtTest, executeNonQuery_insert_viola "VALUES(" ":COL1);"; auto stmt = conn.createStmt(sql); - stmt->bindOptionalUint64(":COL1", 1); + stmt->bindUint64(":COL1", 1); stmt->executeNonQuery(); } @@ -414,7 +414,7 @@ TEST_F(DISABLED_cta_rdbms_wrapper_PostgresStmtTest, executeNonQuery_insert_viola "VALUES(" ":COL1);"; auto stmt = conn.createStmt(sql); - stmt->bindOptionalUint64(":COL1", 1); + stmt->bindUint64(":COL1", 1); ASSERT_THROW(stmt->executeNonQuery(), exception::Exception); } } @@ -445,7 +445,7 @@ TEST_F(DISABLED_cta_rdbms_wrapper_PostgresStmtTest, executeQuery_insert_violatin "VALUES(" ":COL1);"; auto stmt = m_conn->createStmt(sql); - stmt->bindOptionalUint64(":COL1", 1); + stmt->bindUint64(":COL1", 1); stmt->executeNonQuery(); } @@ -457,7 +457,7 @@ TEST_F(DISABLED_cta_rdbms_wrapper_PostgresStmtTest, executeQuery_insert_violatin "VALUES(" ":COL1);"; auto stmt = m_conn->createStmt(sql); - stmt->bindOptionalUint64(":COL1", 1); + stmt->bindUint64(":COL1", 1); auto rset = stmt->executeQuery(); ASSERT_THROW(rset->next(), exception::Exception); } @@ -489,7 +489,7 @@ TEST_F(DISABLED_cta_rdbms_wrapper_PostgresStmtTest, insert_with_large_uint64) { "VALUES(" ":COL1);"; auto stmt = m_conn->createStmt(sql); - stmt->bindOptionalUint64(":COL1", val); + stmt->bindUint64(":COL1", val); stmt->executeNonQuery(); } @@ -664,8 +664,8 @@ TEST_F(DISABLED_cta_rdbms_wrapper_PostgresStmtTest, nbaffected) { "UPDATE TEST SET COL1=:NEWVAL WHERE COL1=:OLDVAL"; auto stmt = m_conn->createStmt(sql); - stmt->bindOptionalString(":NEWVAL", std::string("val3")); - stmt->bindOptionalString(":OLDVAL", std::string("val1")); + stmt->bindString(":NEWVAL", "val3"); + stmt->bindString(":OLDVAL", "val1"); stmt->executeNonQuery(); ASSERT_EQ(2, stmt->getNbAffectedRows()); } diff --git a/rdbms/wrapper/SqliteConn.cpp b/rdbms/wrapper/SqliteConn.cpp index 2c2465a3dfd51c7b5e7888ceabda95c71c20de09..0b230de140033fcf964bb14412a3ba3db45f2149 100644 --- a/rdbms/wrapper/SqliteConn.cpp +++ b/rdbms/wrapper/SqliteConn.cpp @@ -252,7 +252,7 @@ std::map<std::string, std::string> SqliteConn::getColumns(const std::string &tab "BLOB"; auto stmt = createStmt(sql); - stmt->bindOptionalString(":TABLE_NAME", tableName); + stmt->bindString(":TABLE_NAME", tableName); auto rset = stmt->executeQuery(); if (rset->next()) { auto tableSql = rset->columnOptionalString("SQL").value(); diff --git a/rdbms/wrapper/SqliteStmt.cpp b/rdbms/wrapper/SqliteStmt.cpp index 09b42c58ea31fb8e7a6561af675a3c918c51b7d7..ee75525ba38913ad8ecf781bdabdf8f88699ab44 100644 --- a/rdbms/wrapper/SqliteStmt.cpp +++ b/rdbms/wrapper/SqliteStmt.cpp @@ -150,9 +150,9 @@ sqlite3_stmt *SqliteStmt::get() const { } //------------------------------------------------------------------------------ -// bindOptionalUint8 +// bindUint8 //------------------------------------------------------------------------------ -void SqliteStmt::bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { +void SqliteStmt::bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); int bindRc = 0; @@ -171,9 +171,9 @@ void SqliteStmt::bindOptionalUint8(const std::string ¶mName, const optional< } //------------------------------------------------------------------------------ -// bindOptionalUint16 +// bindUint16 //------------------------------------------------------------------------------ -void SqliteStmt::bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { +void SqliteStmt::bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); int bindRc = 0; @@ -192,9 +192,9 @@ void SqliteStmt::bindOptionalUint16(const std::string ¶mName, const optional } //------------------------------------------------------------------------------ -// bindOptionalUint32 +// bindUint32 //------------------------------------------------------------------------------ -void SqliteStmt::bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { +void SqliteStmt::bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); int bindRc = 0; @@ -213,9 +213,9 @@ void SqliteStmt::bindOptionalUint32(const std::string ¶mName, const optional } //------------------------------------------------------------------------------ -// bindOptionalUint64 +// bindUint64 //------------------------------------------------------------------------------ -void SqliteStmt::bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { +void SqliteStmt::bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); int bindRc = 0; @@ -234,9 +234,9 @@ void SqliteStmt::bindOptionalUint64(const std::string ¶mName, const optional } //------------------------------------------------------------------------------ -// bindOptionalDouble +// bindDouble //------------------------------------------------------------------------------ -void SqliteStmt::bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) { +void SqliteStmt::bindDouble(const std::string ¶mName, const optional<double> ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); int bindRc = 0; @@ -273,9 +273,9 @@ void SqliteStmt::bindBlob(const std::string ¶mName, const std::string ¶m } //------------------------------------------------------------------------------ -// bindOptionalString +// bindString //------------------------------------------------------------------------------ -void SqliteStmt::bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) { +void SqliteStmt::bindString(const std::string ¶mName, const optional<std::string> ¶mValue) { try { if(paramValue && paramValue.value().empty()) { throw exception::Exception(std::string("Optional string parameter ") + paramName + " is an empty string. " diff --git a/rdbms/wrapper/SqliteStmt.hpp b/rdbms/wrapper/SqliteStmt.hpp index 4ab98cd947616fbdff6f41286af20db144c73eba..46005c6441fd22eb55d5e8cbfcd1bdaf1769ddbf 100644 --- a/rdbms/wrapper/SqliteStmt.hpp +++ b/rdbms/wrapper/SqliteStmt.hpp @@ -81,7 +81,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; + void bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -89,7 +89,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; + void bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -97,7 +97,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; + void bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -105,7 +105,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; + void bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; /** * Binds an SQL parameter. @@ -113,7 +113,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) override; + void bindDouble(const std::string ¶mName, const optional<double> ¶mValue) override; /** * Binds an SQL parameter of type binary string (byte array). @@ -133,7 +133,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) override; + void bindString(const std::string ¶mName, const optional<std::string> ¶mValue) override; /** * Executes the statement and returns the result set. diff --git a/rdbms/wrapper/SqliteStmtTest.cpp b/rdbms/wrapper/SqliteStmtTest.cpp index 95a285dbcbf72c324b0a9f3598abdca8cfdf895b..6f286f530286dd14062bdce40a8d25853cc1c79f 100644 --- a/rdbms/wrapper/SqliteStmtTest.cpp +++ b/rdbms/wrapper/SqliteStmtTest.cpp @@ -266,9 +266,9 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, insert_with_bind) { ":COL2," ":COL3);"; auto stmt = conn.createStmt(sql); - stmt->bindOptionalString(":COL1", std::string("one")); - stmt->bindOptionalString(":COL2", std::string("two")); - stmt->bindOptionalUint64(":COL3", 3); + stmt->bindString(":COL1", "one"); + stmt->bindString(":COL2", "two"); + stmt->bindUint64(":COL3", 3); stmt->executeNonQuery(); } @@ -390,7 +390,7 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeNonQuery_insert_violating_primar "VALUES(" ":COL1);"; auto stmt = conn.createStmt(sql); - stmt->bindOptionalUint64(":COL1", 1); + stmt->bindUint64(":COL1", 1); stmt->executeNonQuery(); } @@ -402,7 +402,7 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeNonQuery_insert_violating_primar "VALUES(" ":COL1);"; auto stmt = conn.createStmt(sql); - stmt->bindOptionalUint64(":COL1", 1); + stmt->bindUint64(":COL1", 1); ASSERT_THROW(stmt->executeNonQuery(), PrimaryKeyError); } } @@ -437,7 +437,7 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeQuery_insert_violating_primary_k "VALUES(" ":COL1);"; auto stmt = conn.createStmt(sql); - stmt->bindOptionalUint64(":COL1", 1); + stmt->bindUint64(":COL1", 1); stmt->executeNonQuery(); } @@ -449,7 +449,7 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeQuery_insert_violating_primary_k "VALUES(" ":COL1);"; auto stmt = conn.createStmt(sql); - stmt->bindOptionalUint64(":COL1", 1); + stmt->bindUint64(":COL1", 1); auto rset = stmt->executeQuery(); ASSERT_THROW(rset->next(), PrimaryKeyError); } diff --git a/rdbms/wrapper/StmtWrapper.cpp b/rdbms/wrapper/StmtWrapper.cpp index 7a4bde42c802ea0be6b33cb9371fcb2e58a40955..c3ad7554b23bf7f531bf2d8c7d112fc2b77cfa90 100644 --- a/rdbms/wrapper/StmtWrapper.cpp +++ b/rdbms/wrapper/StmtWrapper.cpp @@ -59,13 +59,13 @@ std::string StmtWrapper::getSqlForException(const std::string::size_type maxSqlL } //------------------------------------------------------------------------------ -// bindOptionalBool +// bindBool //------------------------------------------------------------------------------ -void StmtWrapper::bindOptionalBool(const std::string ¶mName, const optional<bool> ¶mValue) { +void StmtWrapper::bindBool(const std::string ¶mName, const optional<bool> ¶mValue) { if(paramValue) { - bindOptionalString(paramName, std::string(paramValue.value() ? "1" : "0")); + bindString(paramName, paramValue.value() ? "1" : "0"); } else { - bindOptionalString(paramName, nullopt); + bindString(paramName, nullopt); } } diff --git a/rdbms/wrapper/StmtWrapper.hpp b/rdbms/wrapper/StmtWrapper.hpp index 15827d785900d6561437398a8e6f4409da01713b..84534efcb5bf28e36a3cf95ef64cd14eb4958c67 100644 --- a/rdbms/wrapper/StmtWrapper.hpp +++ b/rdbms/wrapper/StmtWrapper.hpp @@ -101,7 +101,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - virtual void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) = 0; + virtual void bindUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) = 0; /** * Binds an SQL parameter. @@ -109,7 +109,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - virtual void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) = 0; + virtual void bindUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) = 0; /** * Binds an SQL parameter. @@ -117,7 +117,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - virtual void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) = 0; + virtual void bindUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) = 0; /** * Binds an SQL parameter. @@ -125,7 +125,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - virtual void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) = 0; + virtual void bindUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) = 0; /** * Binds an SQL parameter. @@ -133,7 +133,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - virtual void bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) = 0; + virtual void bindDouble(const std::string ¶mName, const optional<double> ¶mValue) = 0; /** * Binds an SQL parameter. @@ -141,7 +141,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - void bindOptionalBool(const std::string ¶mName, const optional<bool> ¶mValue); + void bindBool(const std::string ¶mName, const optional<bool> ¶mValue); /** * Binds an SQL parameter of type binary string (byte array). @@ -151,6 +151,21 @@ public: */ virtual void bindBlob(const std::string ¶mName, const std::string ¶mValue) = 0; + /** + * Binds an SQL parameter of type optional-string. + * + * Please note that this method will throw an exception if the optional string + * parameter has the empty string as its value. An optional string parameter + * should either have a non-empty string value or no value at all. + * + * @param paramName The name of the parameter. + * @param paramValue The value to be bound. + */ + void bindString(const std::string ¶mName, const std::string ¶mValue) { + const optional<std::string> optionalParamValue(paramValue); + bindString(paramName, optionalParamValue); + } + /** * Binds an SQL parameter of type optional-string. * @@ -161,7 +176,7 @@ public: * @param paramName The name of the parameter. * @param paramValue The value to be bound. */ - virtual void bindOptionalString(const std::string ¶mName, const optional<std::string> ¶mValue) = 0; + virtual void bindString(const std::string ¶mName, const optional<std::string> ¶mValue) = 0; /** * Executes the statement and returns the result set.