From 6feee21bc42ff8243107bb060db5ad8e5a29fdfe Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Fri, 6 Dec 2019 17:17:28 +0100 Subject: [PATCH] Simplied code within rdbms namespace --- rdbms/Stmt.cpp | 42 +++-------------- rdbms/wrapper/MysqlConn.cpp | 2 +- rdbms/wrapper/MysqlStmt.cpp | 70 ---------------------------- rdbms/wrapper/MysqlStmt.hpp | 56 +---------------------- rdbms/wrapper/OcciConn.cpp | 2 +- rdbms/wrapper/OcciStmt.cpp | 70 ---------------------------- rdbms/wrapper/OcciStmt.hpp | 52 --------------------- rdbms/wrapper/PostgresConn.cpp | 2 +- rdbms/wrapper/PostgresStmt.cpp | 73 ++---------------------------- rdbms/wrapper/PostgresStmt.hpp | 52 --------------------- rdbms/wrapper/PostgresStmtTest.cpp | 20 ++++---- rdbms/wrapper/SqliteConn.cpp | 2 +- rdbms/wrapper/SqliteStmt.cpp | 73 ++---------------------------- rdbms/wrapper/SqliteStmt.hpp | 52 --------------------- rdbms/wrapper/SqliteStmtTest.cpp | 14 +++--- rdbms/wrapper/StmtWrapper.cpp | 7 --- rdbms/wrapper/StmtWrapper.hpp | 62 +------------------------ 17 files changed, 36 insertions(+), 615 deletions(-) diff --git a/rdbms/Stmt.cpp b/rdbms/Stmt.cpp index cd949b6993..1278189c39 100644 --- a/rdbms/Stmt.cpp +++ b/rdbms/Stmt.cpp @@ -121,11 +121,7 @@ uint32_t Stmt::getParamIdx(const std::string ¶mName) const { //----------------------------------------------------------------------------- void Stmt::bindUint8(const std::string ¶mName, const uint8_t paramValue) { try { - if(nullptr != m_stmt) { - return m_stmt->bindUint8(paramName, paramValue); - } else { - throw exception::Exception("Stmt does not contain a cached statement"); - } + bindOptionalUint8(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -153,11 +149,7 @@ void Stmt::bindOptionalUint8(const std::string ¶mName, const optional<uint8_ //----------------------------------------------------------------------------- void Stmt::bindUint16(const std::string ¶mName, const uint16_t paramValue) { try { - if(nullptr != m_stmt) { - return m_stmt->bindUint16(paramName, paramValue); - } else { - throw exception::Exception("Stmt does not contain a cached statement"); - } + bindOptionalUint16(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -185,11 +177,7 @@ void Stmt::bindOptionalUint16(const std::string ¶mName, const optional<uint1 //----------------------------------------------------------------------------- void Stmt::bindUint32(const std::string ¶mName, const uint32_t paramValue) { try { - if(nullptr != m_stmt) { - return m_stmt->bindUint32(paramName, paramValue); - } else { - throw exception::Exception("Stmt does not contain a cached statement"); - } + bindOptionalUint32(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -217,11 +205,7 @@ void Stmt::bindOptionalUint32(const std::string ¶mName, const optional<uint3 //----------------------------------------------------------------------------- void Stmt::bindUint64(const std::string ¶mName, const uint64_t paramValue) { try { - if(nullptr != m_stmt) { - return m_stmt->bindUint64(paramName, paramValue); - } else { - throw exception::Exception("Stmt does not contain a cached statement"); - } + bindOptionalUint64(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -249,11 +233,7 @@ void Stmt::bindOptionalUint64(const std::string ¶mName, const optional<uint6 //----------------------------------------------------------------------------- void Stmt::bindDouble(const std::string ¶mName, const double paramValue) { try { - if(nullptr != m_stmt) { - return m_stmt->bindDouble(paramName, paramValue); - } else { - throw exception::Exception("Stmt does not contain a cached statement"); - } + bindOptionalDouble(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -281,11 +261,7 @@ void Stmt::bindOptionalDouble(const std::string ¶mName, const optional<doubl //----------------------------------------------------------------------------- void Stmt::bindBool(const std::string ¶mName, const bool paramValue) { try { - if(nullptr != m_stmt) { - return m_stmt->bindBool(paramName, paramValue); - } else { - throw exception::Exception("Stmt does not contain a cached statement"); - } + bindOptionalBool(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; @@ -329,11 +305,7 @@ void Stmt::bindBlob(const std::string ¶mName, const std::string ¶mValue) //----------------------------------------------------------------------------- void Stmt::bindString(const std::string ¶mName, const std::string ¶mValue) { try { - if(nullptr != m_stmt) { - return m_stmt->bindString(paramName, paramValue); - } else { - throw exception::Exception("Stmt does not contain a cached statement"); - } + bindOptionalString(paramName, paramValue); } catch(exception::Exception &ex) { ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); throw; diff --git a/rdbms/wrapper/MysqlConn.cpp b/rdbms/wrapper/MysqlConn.cpp index b82ef563a7..47b347f005 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->bindString(":TABLE_NAME", tableName); + stmt->bindOptionalString(":TABLE_NAME", tableName); auto rset = stmt->executeQuery(); while (rset->next()) { auto name = rset->columnOptionalString("COLUMN_NAME"); diff --git a/rdbms/wrapper/MysqlStmt.cpp b/rdbms/wrapper/MysqlStmt.cpp index 3bb54a9619..249ffbf424 100644 --- a/rdbms/wrapper/MysqlStmt.cpp +++ b/rdbms/wrapper/MysqlStmt.cpp @@ -170,18 +170,6 @@ MYSQL_STMT *MysqlStmt::get() const { return m_stmt; } -//------------------------------------------------------------------------------ -// bindUint8 -//------------------------------------------------------------------------------ -void MysqlStmt::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 //------------------------------------------------------------------------------ @@ -216,18 +204,6 @@ void MysqlStmt::bindOptionalUint8(const std::string ¶mName, const optional<u } } -//------------------------------------------------------------------------------ -// bindUint16 -//------------------------------------------------------------------------------ -void MysqlStmt::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 //------------------------------------------------------------------------------ @@ -262,18 +238,6 @@ void MysqlStmt::bindOptionalUint16(const std::string ¶mName, const optional< } } -//------------------------------------------------------------------------------ -// bindUint32 -//------------------------------------------------------------------------------ -void MysqlStmt::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 //------------------------------------------------------------------------------ @@ -308,18 +272,6 @@ void MysqlStmt::bindOptionalUint32(const std::string ¶mName, const optional< } } -//------------------------------------------------------------------------------ -// bindUint64 -//------------------------------------------------------------------------------ -void MysqlStmt::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 //------------------------------------------------------------------------------ @@ -354,17 +306,6 @@ void MysqlStmt::bindOptionalUint64(const std::string ¶mName, const optional< } } -//------------------------------------------------------------------------------ -// bindDouble -//------------------------------------------------------------------------------ -void MysqlStmt::bindDouble(const std::string ¶mName, const double paramValue) { - try { - bindOptionalDouble(paramName, paramValue); - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // bindOptionalDouble //------------------------------------------------------------------------------ @@ -407,17 +348,6 @@ void MysqlStmt::bindBlob(const std::string ¶mName, const std::string ¶mV } } -//------------------------------------------------------------------------------ -// bindString -//------------------------------------------------------------------------------ -void MysqlStmt::bindString(const std::string ¶mName, const std::string ¶mValue) { - try { - bindOptionalString(paramName, paramValue); - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // bindOptionalString //------------------------------------------------------------------------------ diff --git a/rdbms/wrapper/MysqlStmt.hpp b/rdbms/wrapper/MysqlStmt.hpp index fd8842df28..ee2ff15a57 100644 --- a/rdbms/wrapper/MysqlStmt.hpp +++ b/rdbms/wrapper/MysqlStmt.hpp @@ -84,14 +84,6 @@ public: */ MYSQL_STMT *get() const; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint8(const std::string ¶mName, const uint8_t paramValue) override; - /** * Binds an SQL parameter. * @@ -100,14 +92,6 @@ public: */ void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint16(const std::string ¶mName, const uint16_t paramValue) override; - /** * Binds an SQL parameter. * @@ -116,14 +100,6 @@ public: */ void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint32(const std::string ¶mName, const uint32_t paramValue) override; - /** * Binds an SQL parameter. * @@ -132,14 +108,6 @@ public: */ void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; - /** - * 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) override; - /** * Binds an SQL parameter. * @@ -148,14 +116,6 @@ public: */ void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; - /** - * 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) override; - /** * Binds an SQL parameter. * @@ -172,19 +132,7 @@ public: */ void bindBlob(const std::string ¶mName, const std::string ¶mValue) override; - /** - * 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) override; - - /** + /** * Binds an SQL parameter of type optional-string. * * Please note that this method will throw an exception if the optional string @@ -219,8 +167,6 @@ public: Mysql::Placeholder* columnHolder(const std::string &colName) const; - -private: private: /** diff --git a/rdbms/wrapper/OcciConn.cpp b/rdbms/wrapper/OcciConn.cpp index f21a20a60d..2246b1a210 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->bindString(":TABLE_NAME", tableName); + stmt->bindOptionalString(":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 e8e5e1bb11..44d4854a76 100644 --- a/rdbms/wrapper/OcciStmt.cpp +++ b/rdbms/wrapper/OcciStmt.cpp @@ -87,18 +87,6 @@ void OcciStmt::close() { } } -//------------------------------------------------------------------------------ -// bindUint8 -//------------------------------------------------------------------------------ -void OcciStmt::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 //------------------------------------------------------------------------------ @@ -111,18 +99,6 @@ void OcciStmt::bindOptionalUint8(const std::string ¶mName, const optional<ui } } -//------------------------------------------------------------------------------ -// bindUint16 -//------------------------------------------------------------------------------ -void OcciStmt::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 //------------------------------------------------------------------------------ @@ -135,18 +111,6 @@ void OcciStmt::bindOptionalUint16(const std::string ¶mName, const optional<u } } -//------------------------------------------------------------------------------ -// bindUint32 -//------------------------------------------------------------------------------ -void OcciStmt::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 //------------------------------------------------------------------------------ @@ -159,18 +123,6 @@ void OcciStmt::bindOptionalUint32(const std::string ¶mName, const optional<u } } -//------------------------------------------------------------------------------ -// bindUint64 -//------------------------------------------------------------------------------ -void OcciStmt::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 //------------------------------------------------------------------------------ @@ -190,17 +142,6 @@ void OcciStmt::bindBlob(const std::string ¶mName, const std::string ¶mVa throw exception::Exception("OcciStmt::bindBlob not implemented."); } -//------------------------------------------------------------------------------ -// bindDouble -//------------------------------------------------------------------------------ -void OcciStmt::bindDouble(const std::string ¶mName, const double paramValue) { - try { - bindOptionalDouble(paramName, paramValue); - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // bindOptionalDouble //------------------------------------------------------------------------------ @@ -222,17 +163,6 @@ void OcciStmt::bindOptionalDouble(const std::string ¶mName, const optional<d } } -//------------------------------------------------------------------------------ -// bind -//------------------------------------------------------------------------------ -void OcciStmt::bindString(const std::string ¶mName, const std::string ¶mValue) { - try { - bindOptionalString(paramName, paramValue); - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // bindOptionalString //------------------------------------------------------------------------------ diff --git a/rdbms/wrapper/OcciStmt.hpp b/rdbms/wrapper/OcciStmt.hpp index 4b73c4ca6c..613f165c5e 100644 --- a/rdbms/wrapper/OcciStmt.hpp +++ b/rdbms/wrapper/OcciStmt.hpp @@ -81,14 +81,6 @@ public: */ void close() override; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint8(const std::string ¶mName, const uint8_t paramValue) override; - /** * Binds an SQL parameter. * @@ -97,14 +89,6 @@ public: */ void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint16(const std::string ¶mName, const uint16_t paramValue) override; - /** * Binds an SQL parameter. * @@ -113,14 +97,6 @@ public: */ void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint32(const std::string ¶mName, const uint32_t paramValue) override; - /** * Binds an SQL parameter. * @@ -129,14 +105,6 @@ public: */ void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; - /** - * 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) override; - /** * Binds an SQL parameter. * @@ -145,14 +113,6 @@ public: */ void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; - /** - * 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) override; - /** * Binds an SQL parameter. * @@ -169,18 +129,6 @@ public: */ void bindBlob(const std::string ¶mName, const std::string ¶mValue) override; - /** - * 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) override; - /** * Binds an SQL parameter of type optional-string. * diff --git a/rdbms/wrapper/PostgresConn.cpp b/rdbms/wrapper/PostgresConn.cpp index e27ee6792f..bcd4dff4b4 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->bindString(":TABLE_NAME", lowercaseTableName); + stmt->bindOptionalString(":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 745c6d3576..1ca753d2ac 100644 --- a/rdbms/wrapper/PostgresStmt.cpp +++ b/rdbms/wrapper/PostgresStmt.cpp @@ -154,78 +154,11 @@ void PostgresStmt::bindOptionalUint64(const std::string ¶mName, const option } } -void PostgresStmt::bindBlob(const std::string ¶mName, const std::string ¶mValue) { - throw exception::Exception("PostgresStmt::bindBlob not implemented."); -} - -//------------------------------------------------------------------------------ -// bindString -//------------------------------------------------------------------------------ -void PostgresStmt::bindString(const std::string ¶mName, const std::string ¶mValue) { - try { - bindOptionalString(paramName, paramValue); - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - -//------------------------------------------------------------------------------ -// bindUint8 -//------------------------------------------------------------------------------ -void PostgresStmt::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; - } -} - -//------------------------------------------------------------------------------ -// bindUint16 -//------------------------------------------------------------------------------ -void PostgresStmt::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; - } -} - -//------------------------------------------------------------------------------ -// bindUint32 -//------------------------------------------------------------------------------ -void PostgresStmt::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; - } -} - -//------------------------------------------------------------------------------ -// bindUint64 //------------------------------------------------------------------------------ -void PostgresStmt::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; - } -} - +// bindBlob //------------------------------------------------------------------------------ -// bindDouble -//------------------------------------------------------------------------------ -void PostgresStmt::bindDouble(const std::string ¶mName, const double paramValue) { - try { - bindOptionalDouble(paramName, paramValue); - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } +void PostgresStmt::bindBlob(const std::string ¶mName, const std::string ¶mValue) { + throw exception::Exception("PostgresStmt::bindBlob not implemented."); } //------------------------------------------------------------------------------ diff --git a/rdbms/wrapper/PostgresStmt.hpp b/rdbms/wrapper/PostgresStmt.hpp index 26d167aa0a..f9e4b80e46 100644 --- a/rdbms/wrapper/PostgresStmt.hpp +++ b/rdbms/wrapper/PostgresStmt.hpp @@ -116,58 +116,6 @@ public: */ void bindBlob(const std::string ¶mName, const std::string ¶mValue) override; - /** - * 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) override; - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint8(const std::string ¶mName, const uint8_t paramValue) override; - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint16(const std::string ¶mName, const uint16_t paramValue) override; - - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint32(const std::string ¶mName, const uint32_t paramValue) override; - - /** - * 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) override; - - /** - * 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) override; - /** * Binds an SQL parameter. * diff --git a/rdbms/wrapper/PostgresStmtTest.cpp b/rdbms/wrapper/PostgresStmtTest.cpp index 812a70201e..48a9001c7b 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->bindString(":COL1", "one"); - stmt->bindString(":COL2", "two"); - stmt->bindUint64(":COL3", 3); + stmt->bindOptionalString(":COL1", std::string("one")); + stmt->bindOptionalString(":COL2", std::string("two")); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", 1); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", 1); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", 1); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", 1); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", val); + stmt->bindOptionalUint64(":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->bindString(":NEWVAL", "val3"); - stmt->bindString(":OLDVAL", "val1"); + stmt->bindOptionalString(":NEWVAL", std::string("val3")); + stmt->bindOptionalString(":OLDVAL", std::string("val1")); stmt->executeNonQuery(); ASSERT_EQ(2, stmt->getNbAffectedRows()); } diff --git a/rdbms/wrapper/SqliteConn.cpp b/rdbms/wrapper/SqliteConn.cpp index 0b230de140..2c2465a3df 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->bindString(":TABLE_NAME", tableName); + stmt->bindOptionalString(":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 305214eace..09b42c58ea 100644 --- a/rdbms/wrapper/SqliteStmt.cpp +++ b/rdbms/wrapper/SqliteStmt.cpp @@ -149,18 +149,6 @@ sqlite3_stmt *SqliteStmt::get() const { return m_stmt; } -//------------------------------------------------------------------------------ -// bindUint8 -//------------------------------------------------------------------------------ -void SqliteStmt::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 //------------------------------------------------------------------------------ @@ -182,18 +170,6 @@ void SqliteStmt::bindOptionalUint8(const std::string ¶mName, const optional< } } -//------------------------------------------------------------------------------ -// bindUint16 -//------------------------------------------------------------------------------ -void SqliteStmt::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 //------------------------------------------------------------------------------ @@ -215,18 +191,6 @@ void SqliteStmt::bindOptionalUint16(const std::string ¶mName, const optional } } -//------------------------------------------------------------------------------ -// bindUint32 -//------------------------------------------------------------------------------ -void SqliteStmt::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 //------------------------------------------------------------------------------ @@ -248,18 +212,6 @@ void SqliteStmt::bindOptionalUint32(const std::string ¶mName, const optional } } -//------------------------------------------------------------------------------ -// bindUint64 -//------------------------------------------------------------------------------ -void SqliteStmt::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 //------------------------------------------------------------------------------ @@ -281,17 +233,6 @@ void SqliteStmt::bindOptionalUint64(const std::string ¶mName, const optional } } -//------------------------------------------------------------------------------ -// bindDouble -//------------------------------------------------------------------------------ -void SqliteStmt::bindDouble(const std::string ¶mName, const double paramValue) { - try { - bindOptionalDouble(paramName, paramValue); - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // bindOptionalDouble //------------------------------------------------------------------------------ @@ -313,6 +254,9 @@ void SqliteStmt::bindOptionalDouble(const std::string ¶mName, const optional } } +//------------------------------------------------------------------------------ +// bindBlob +//------------------------------------------------------------------------------ void SqliteStmt::bindBlob(const std::string ¶mName, const std::string ¶mValue) { try { const unsigned int paramIdx = getParamIdx(paramName); @@ -328,17 +272,6 @@ void SqliteStmt::bindBlob(const std::string ¶mName, const std::string ¶m } } -//------------------------------------------------------------------------------ -// bindString -//------------------------------------------------------------------------------ -void SqliteStmt::bindString(const std::string ¶mName, const std::string ¶mValue) { - try { - bindOptionalString(paramName, paramValue); - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // bindOptionalString //------------------------------------------------------------------------------ diff --git a/rdbms/wrapper/SqliteStmt.hpp b/rdbms/wrapper/SqliteStmt.hpp index 3213cd090b..4ab98cd947 100644 --- a/rdbms/wrapper/SqliteStmt.hpp +++ b/rdbms/wrapper/SqliteStmt.hpp @@ -75,14 +75,6 @@ public: */ sqlite3_stmt *get() const; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint8(const std::string ¶mName, const uint8_t paramValue) override; - /** * Binds an SQL parameter. * @@ -91,14 +83,6 @@ public: */ void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) override; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint16(const std::string ¶mName, const uint16_t paramValue) override; - /** * Binds an SQL parameter. * @@ -107,14 +91,6 @@ public: */ void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) override; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - void bindUint32(const std::string ¶mName, const uint32_t paramValue) override; - /** * Binds an SQL parameter. * @@ -123,14 +99,6 @@ public: */ void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) override; - /** - * 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) override; - /** * Binds an SQL parameter. * @@ -139,14 +107,6 @@ public: */ void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) override; - /** - * 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) override; - /** * Binds an SQL parameter. * @@ -163,18 +123,6 @@ public: */ void bindBlob(const std::string ¶mName, const std::string ¶mValue) override; - /** - * 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) override; - /** * Binds an SQL parameter of type optional-string. * diff --git a/rdbms/wrapper/SqliteStmtTest.cpp b/rdbms/wrapper/SqliteStmtTest.cpp index 6f286f5302..95a285dbcb 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->bindString(":COL1", "one"); - stmt->bindString(":COL2", "two"); - stmt->bindUint64(":COL3", 3); + stmt->bindOptionalString(":COL1", std::string("one")); + stmt->bindOptionalString(":COL2", std::string("two")); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", 1); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", 1); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", 1); + stmt->bindOptionalUint64(":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->bindUint64(":COL1", 1); + stmt->bindOptionalUint64(":COL1", 1); auto rset = stmt->executeQuery(); ASSERT_THROW(rset->next(), PrimaryKeyError); } diff --git a/rdbms/wrapper/StmtWrapper.cpp b/rdbms/wrapper/StmtWrapper.cpp index fa44824462..7a4bde42c8 100644 --- a/rdbms/wrapper/StmtWrapper.cpp +++ b/rdbms/wrapper/StmtWrapper.cpp @@ -58,13 +58,6 @@ std::string StmtWrapper::getSqlForException(const std::string::size_type maxSqlL return rdbms::getSqlForException(m_sql, maxSqlLenInExceptions); } -//------------------------------------------------------------------------------ -// bindBool -//------------------------------------------------------------------------------ -void StmtWrapper::bindBool(const std::string ¶mName, const bool paramValue) { - bindOptionalBool(paramName, paramValue); -} - //------------------------------------------------------------------------------ // bindOptionalBool //------------------------------------------------------------------------------ diff --git a/rdbms/wrapper/StmtWrapper.hpp b/rdbms/wrapper/StmtWrapper.hpp index f5c54ebd60..15827d7859 100644 --- a/rdbms/wrapper/StmtWrapper.hpp +++ b/rdbms/wrapper/StmtWrapper.hpp @@ -95,14 +95,6 @@ public: */ uint32_t getParamIdx(const std::string ¶mName) const; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - virtual void bindUint8(const std::string ¶mName, const uint8_t paramValue) = 0; - /** * Binds an SQL parameter. * @@ -111,14 +103,6 @@ public: */ virtual void bindOptionalUint8(const std::string ¶mName, const optional<uint8_t> ¶mValue) = 0; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - virtual void bindUint16(const std::string ¶mName, const uint16_t paramValue) = 0; - /** * Binds an SQL parameter. * @@ -127,14 +111,6 @@ public: */ virtual void bindOptionalUint16(const std::string ¶mName, const optional<uint16_t> ¶mValue) = 0; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - virtual void bindUint32(const std::string ¶mName, const uint32_t paramValue) = 0; - /** * Binds an SQL parameter. * @@ -143,14 +119,6 @@ public: */ virtual void bindOptionalUint32(const std::string ¶mName, const optional<uint32_t> ¶mValue) = 0; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - virtual void bindUint64(const std::string ¶mName, const uint64_t paramValue) = 0; - /** * Binds an SQL parameter. * @@ -159,14 +127,6 @@ public: */ virtual void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) = 0; - /** - * Binds an SQL parameter. - * - * @param paramName The name of the parameter. - * @param paramValue The value to be bound. - */ - virtual void bindDouble(const std::string ¶mName, const double paramValue) = 0; - /** * Binds an SQL parameter. * @@ -175,14 +135,6 @@ public: */ virtual void bindOptionalDouble(const std::string ¶mName, const optional<double> ¶mValue) = 0; - /** - * 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. * @@ -199,19 +151,7 @@ public: */ virtual void bindBlob(const std::string ¶mName, const std::string ¶mValue) = 0; - /** - * 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. - */ - virtual void bindString(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 -- GitLab