Skip to content
Snippets Groups Projects
Commit 1f638790 authored by Steven Murray's avatar Steven Murray
Browse files

Conn::executeNonQuery() now throws an exception if it encounters a semicolon

parent 576612b7
No related branches found
No related tags found
No related merge requests found
......@@ -18,8 +18,10 @@
#include "common/exception/Exception.hpp"
#include "common/utils/utils.hpp"
#include "rdbms/ConnPool.hpp"
#include "rdbms/Conn.hpp"
#include "rdbms/ConnPool.hpp"
#include "rdbms/rdbms.hpp"
#include "rdbms/UnexpectedSemicolon.hpp"
namespace cta {
namespace rdbms {
......@@ -142,6 +144,11 @@ void Conn::executeNonQueries(const std::string &sqlStmts) {
//------------------------------------------------------------------------------
void Conn::executeNonQuery(const std::string &sql) {
if(nullptr != m_connAndStmts && nullptr != m_connAndStmts->conn) {
if(std::string::npos != sql.find(";")) {
UnexpectedSemicolon ex;
ex.getMessage() << "Encountered unexpected semicolon in " << getSqlForException(sql);
throw ex;
}
m_connAndStmts->conn->executeNonQuery(sql);
} else {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Conn does not contain a connection");
......
......@@ -18,8 +18,9 @@
#include "common/exception/Exception.hpp"
#include "rdbms/ConnPool.hpp"
#include "rdbms/Login.hpp"
#include "rdbms/ConnTest.hpp"
#include "rdbms/Login.hpp"
#include "rdbms/UnexpectedSemicolon.hpp"
#include <gtest/gtest.h>
......@@ -148,6 +149,23 @@ TEST_P(cta_rdbms_ConnTest, createTableInMemoryDatabase_executeNonQuery) {
}
}
TEST_P(cta_rdbms_ConnTest, createTableInMemoryDatabase_executeNonQuery_semicolon) {
using namespace cta::rdbms;
const std::string sql = "CREATE TABLE POOLED_STMT_TEST(ID INTEGER);";
{
const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared", "", 0);
const uint64_t maxNbConns = 1;
ConnPool connPool(login, maxNbConns);
auto conn = connPool.getConn();
ASSERT_TRUE(conn.getTableNames().empty());
ASSERT_THROW(conn.executeNonQuery(sql), UnexpectedSemicolon);
}
}
TEST_P(cta_rdbms_ConnTest, createTableInMemoryDatabase_executeNonQueries) {
using namespace cta::rdbms;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment