Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
0499c320
Commit
0499c320
authored
5 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Added uint-test cta_rdbms_StmtTest.insert_with_bindString
parent
103e044c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rdbms/StmtTest.cpp
+93
-1
93 additions, 1 deletion
rdbms/StmtTest.cpp
rdbms/StmtTest.hpp
+9
-0
9 additions, 0 deletions
rdbms/StmtTest.hpp
with
102 additions
and
1 deletion
rdbms/StmtTest.cpp
+
93
−
1
View file @
0499c320
...
...
@@ -18,6 +18,7 @@
#include
"common/exception/Exception.hpp"
#include
"common/make_unique.hpp"
#include
"common/utils/utils.hpp"
#include
"rdbms/ConnPool.hpp"
#include
"rdbms/StmtTest.hpp"
...
...
@@ -46,7 +47,56 @@ void cta_rdbms_StmtTest::SetUp() {
// Do nothing
}
m_conn
.
executeNonQuery
(
"CREATE TABLE STMT_TEST(DOUBLE_COL FLOAT, UINT64_COL NUMERIC(20, 0))"
);
const
std
::
string
createTableSql
=
getCreateStmtTestTableSql
();
m_conn
.
executeNonQuery
(
createTableSql
);
}
//------------------------------------------------------------------------------
// getStmtTestTableSql
//------------------------------------------------------------------------------
std
::
string
cta_rdbms_StmtTest
::
getCreateStmtTestTableSql
()
{
using
namespace
cta
;
using
namespace
cta
::
rdbms
;
try
{
std
::
string
sql
=
"CREATE TABLE STMT_TEST("
"DOUBLE_COL FLOAT,"
"UINT64_COL NUMERIC(20, 0),"
"STRING_COL VARCHAR(100)"
")"
;
switch
(
m_login
.
dbType
)
{
case
Login
::
DBTYPE_IN_MEMORY
:
break
;
case
Login
::
DBTYPE_ORACLE
:
utils
::
searchAndReplace
(
sql
,
"VARCHAR"
,
"VARCHAR2"
);
break
;
case
Login
::
DBTYPE_SQLITE
:
break
;
case
Login
::
DBTYPE_MYSQL
:
break
;
case
Login
::
DBTYPE_POSTGRESQL
:
break
;
case
Login
::
DBTYPE_NONE
:
{
throw
exception
::
Exception
(
"Cannot create SQL for database type DBTYPE_NONE"
);
}
default
:
{
std
::
ostringstream
msg
;
msg
<<
"Unknown database type: intVal="
<<
m_login
.
dbType
;
throw
exception
::
Exception
(
msg
.
str
());
}
}
return
sql
;
}
catch
(
exception
::
Exception
&
ex
)
{
std
::
ostringstream
msg
;
msg
<<
__FUNCTION__
<<
" failed: "
<<
ex
.
getMessage
().
str
();
ex
.
getMessage
().
str
(
msg
.
str
());
throw
ex
;
}
}
//------------------------------------------------------------------------------
...
...
@@ -222,4 +272,46 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindUint64_2_pow_64_minus_1_not_mysql) {
}
}
TEST_P
(
cta_rdbms_StmtTest
,
insert_with_bindString
)
{
using
namespace
cta
::
rdbms
;
if
(
m_login
.
dbType
==
Login
::
DBTYPE_MYSQL
)
{
return
;
}
const
std
::
string
insertValue
=
"value"
;
// Insert a row into the test table
{
const
char
*
const
sql
=
"INSERT INTO STMT_TEST("
"STRING_COL) "
"VALUES("
":STRING_COL)"
;
auto
stmt
=
m_conn
.
createStmt
(
sql
);
stmt
.
bindString
(
":STRING_COL"
,
insertValue
);
stmt
.
executeNonQuery
();
}
// Select the row back from the table
{
const
char
*
const
sql
=
"SELECT "
"STRING_COL AS STRING_COL "
"FROM "
"STMT_TEST"
;
auto
stmt
=
m_conn
.
createStmt
(
sql
);
auto
rset
=
stmt
.
executeQuery
();
ASSERT_TRUE
(
rset
.
next
());
const
auto
selectValue
=
rset
.
columnOptionalString
(
"STRING_COL"
);
ASSERT_TRUE
((
bool
)
selectValue
);
ASSERT_EQ
(
insertValue
,
selectValue
.
value
());
ASSERT_FALSE
(
rset
.
next
());
}
}
}
// namespace unitTests
This diff is collapsed.
Click to expand it.
rdbms/StmtTest.hpp
+
9
−
0
View file @
0499c320
...
...
@@ -45,6 +45,15 @@ protected:
virtual
void
SetUp
();
/**
* Returns the SQL to create the STMT_TEST table taking into account any
* differences between the various types of database backend.
*
* @return The SQL to create the STMT_TEST table taking into account any
* differences between the various types of database backend.
*/
std
::
string
getCreateStmtTestTableSql
();
virtual
void
TearDown
();
};
// cta_rdbms_StmtTest
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment