Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
f41f767f
Commit
f41f767f
authored
Sep 13, 2019
by
Steven Murray
Browse files
Conn::executeNonQuery() now throws an exception if it encounters a semicolon
parent
b013f9f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
rdbms/Conn.cpp
View file @
f41f767f
...
...
@@ -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"
);
...
...
rdbms/ConnTest.cpp
View file @
f41f767f
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment