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
74bb8d4c
Commit
74bb8d4c
authored
8 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Added method Conn::executeNonQueries()
parent
a6dd5063
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
catalogue/SchemaCreatingSqliteCatalogue.cpp
+11
-12
11 additions, 12 deletions
catalogue/SchemaCreatingSqliteCatalogue.cpp
rdbms/Conn.cpp
+22
-2
22 additions, 2 deletions
rdbms/Conn.cpp
rdbms/Conn.hpp
+14
-1
14 additions, 1 deletion
rdbms/Conn.hpp
with
47 additions
and
15 deletions
catalogue/SchemaCreatingSqliteCatalogue.cpp
+
11
−
12
View file @
74bb8d4c
...
...
@@ -29,24 +29,23 @@ namespace catalogue {
//------------------------------------------------------------------------------
SchemaCreatingSqliteCatalogue
::
SchemaCreatingSqliteCatalogue
(
const
std
::
string
&
filename
,
const
uint64_t
nbConns
)
:
SqliteCatalogue
(
filename
,
nbConns
)
{
createCatalogueSchema
();
try
{
createCatalogueSchema
();
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
}
//------------------------------------------------------------------------------
// createCatalogueSchema
//------------------------------------------------------------------------------
void
SchemaCreatingSqliteCatalogue
::
createCatalogueSchema
()
{
const
InMemoryCatalogueSchema
schema
;
std
::
string
::
size_type
searchPos
=
0
;
std
::
string
::
size_type
findResult
=
std
::
string
::
npos
;
auto
conn
=
m_connPool
.
getConn
();
while
(
std
::
string
::
npos
!=
(
findResult
=
schema
.
sql
.
find
(
';'
,
searchPos
)))
{
const
std
::
string
::
size_type
length
=
findResult
-
searchPos
+
1
;
const
std
::
string
sql
=
schema
.
sql
.
substr
(
searchPos
,
length
);
searchPos
=
findResult
+
1
;
auto
stmt
=
conn
->
createStmt
(
sql
,
rdbms
::
Stmt
::
AutocommitMode
::
ON
);
stmt
->
executeNonQuery
();
try
{
const
InMemoryCatalogueSchema
schema
;
auto
conn
=
m_connPool
.
getConn
();
conn
->
executeNonQueries
(
schema
.
sql
);
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
}
...
...
This diff is collapsed.
Click to expand it.
rdbms/Conn.cpp
+
22
−
2
View file @
74bb8d4c
...
...
@@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"Conn.hpp"
#include
"common/exception/Exception.hpp"
#include
"rdbms/Conn.hpp"
#include
<
memory
>
#include
<
string
>
namespace
cta
{
namespace
rdbms
{
...
...
@@ -30,6 +30,26 @@ namespace rdbms {
Conn
::~
Conn
()
throw
()
{
}
//------------------------------------------------------------------------------
// executeNonQueries
//------------------------------------------------------------------------------
void
Conn
::
executeNonQueries
(
const
std
::
string
&
sqlStmts
)
{
try
{
std
::
string
::
size_type
searchPos
=
0
;
std
::
string
::
size_type
findResult
=
std
::
string
::
npos
;
while
(
std
::
string
::
npos
!=
(
findResult
=
sqlStmts
.
find
(
';'
,
searchPos
)))
{
const
std
::
string
::
size_type
length
=
findResult
-
searchPos
+
1
;
const
std
::
string
sqlStmt
=
sqlStmts
.
substr
(
searchPos
,
length
);
searchPos
=
findResult
+
1
;
executeNonQuery
(
sqlStmt
,
rdbms
::
Stmt
::
AutocommitMode
::
ON
);
}
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
}
//------------------------------------------------------------------------------
// executeNonQuery
//------------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
rdbms/Conn.hpp
+
14
−
1
View file @
74bb8d4c
...
...
@@ -51,7 +51,20 @@ public:
virtual
std
::
unique_ptr
<
Stmt
>
createStmt
(
const
std
::
string
&
sql
,
const
Stmt
::
AutocommitMode
autocommitMode
)
=
0
;
/**
* Convenience function implemented in Conn around Conn::createStmt(),
* Convenience method that parses the specified string of multiple SQL
* statements and calls executeNonQuery() for each individual statement found.
*
* Please note that each statement should be a non-query terminated by a
* semicolon and that each individual statement will be executed with
* autocommit ON.
*
* @param sqlStmts The SQL statements to be executed.
* @param autocommitMode The autocommit mode of the statement.
*/
void
executeNonQueries
(
const
std
::
string
&
sqlStmts
);
/**
* Convenience method that wraps Conn::createStmt() followed by
* Stmt::executeNonQuery().
*
* @param sql The SQL statement.
...
...
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