Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ISC Open Source Projects
Kea
Commits
62fd2020
Commit
62fd2020
authored
Dec 03, 2019
by
Francis Dupont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[
#1008
] Addressed comments
parent
c131e65e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
40 deletions
+53
-40
src/lib/mysql/mysql_connection.cc
src/lib/mysql/mysql_connection.cc
+53
-40
No files found.
src/lib/mysql/mysql_connection.cc
View file @
62fd2020
...
@@ -229,52 +229,65 @@ MySqlConnection::getVersion(const ParameterMap& parameters) {
...
@@ -229,52 +229,65 @@ MySqlConnection::getVersion(const ParameterMap& parameters) {
"statement structure, reason: "
<<
mysql_error
(
conn
.
mysql_
));
"statement structure, reason: "
<<
mysql_error
(
conn
.
mysql_
));
}
}
// Prepare the statement from SQL text.
try
{
const
char
*
version_sql
=
"SELECT version, minor FROM schema_version"
;
int
status
=
mysql_stmt_prepare
(
stmt
,
version_sql
,
strlen
(
version_sql
));
if
(
status
!=
0
)
{
isc_throw
(
DbOperationError
,
"unable to prepare MySQL statement <"
<<
version_sql
<<
">, reason: "
<<
mysql_error
(
conn
.
mysql_
));
}
// Execute the prepared statement.
// Prepare the statement from SQL text.
if
(
mysql_stmt_execute
(
stmt
)
!=
0
)
{
const
char
*
version_sql
=
"SELECT version, minor FROM schema_version"
;
isc_throw
(
DbOperationError
,
"cannot execute schema version query <"
int
status
=
mysql_stmt_prepare
(
stmt
,
version_sql
,
strlen
(
version_sql
));
<<
version_sql
<<
">, reason: "
<<
mysql_errno
(
conn
.
mysql_
));
if
(
status
!=
0
)
{
}
isc_throw
(
DbOperationError
,
"unable to prepare MySQL statement <"
<<
version_sql
<<
">, reason: "
<<
mysql_error
(
conn
.
mysql_
));
}
// Bind the output of the statement to the appropriate variables.
// Execute the prepared statement.
MYSQL_BIND
bind
[
2
];
if
(
mysql_stmt_execute
(
stmt
)
!=
0
)
{
memset
(
bind
,
0
,
sizeof
(
bind
));
isc_throw
(
DbOperationError
,
"cannot execute schema version query <"
<<
version_sql
<<
">, reason: "
uint32_t
major
;
<<
mysql_errno
(
conn
.
mysql_
));
bind
[
0
].
buffer_type
=
MYSQL_TYPE_LONG
;
}
bind
[
0
].
is_unsigned
=
1
;
bind
[
0
].
buffer
=
&
major
;
bind
[
0
].
buffer_length
=
sizeof
(
major
);
uint32_t
minor
;
bind
[
1
].
buffer_type
=
MYSQL_TYPE_LONG
;
bind
[
1
].
is_unsigned
=
1
;
bind
[
1
].
buffer
=
&
minor
;
bind
[
1
].
buffer_length
=
sizeof
(
minor
);
if
(
mysql_stmt_bind_result
(
stmt
,
bind
))
{
isc_throw
(
DbOperationError
,
"unable to bind result set for <"
<<
version_sql
<<
">, reason: "
<<
mysql_errno
(
conn
.
mysql_
));
}
// Fetch the data.
// Bind the output of the statement to the appropriate variables.
if
(
mysql_stmt_fetch
(
stmt
))
{
MYSQL_BIND
bind
[
2
];
memset
(
bind
,
0
,
sizeof
(
bind
));
uint32_t
major
;
bind
[
0
].
buffer_type
=
MYSQL_TYPE_LONG
;
bind
[
0
].
is_unsigned
=
1
;
bind
[
0
].
buffer
=
&
major
;
bind
[
0
].
buffer_length
=
sizeof
(
major
);
uint32_t
minor
;
bind
[
1
].
buffer_type
=
MYSQL_TYPE_LONG
;
bind
[
1
].
is_unsigned
=
1
;
bind
[
1
].
buffer
=
&
minor
;
bind
[
1
].
buffer_length
=
sizeof
(
minor
);
if
(
mysql_stmt_bind_result
(
stmt
,
bind
))
{
isc_throw
(
DbOperationError
,
"unable to bind result set for <"
<<
version_sql
<<
">, reason: "
<<
mysql_errno
(
conn
.
mysql_
));
}
// Fetch the data.
if
(
mysql_stmt_fetch
(
stmt
))
{
isc_throw
(
DbOperationError
,
"unable to bind result set for <"
<<
version_sql
<<
">, reason: "
<<
mysql_errno
(
conn
.
mysql_
));
}
// Discard the statement and its resources
mysql_stmt_close
(
stmt
);
mysql_stmt_close
(
stmt
);
isc_throw
(
DbOperationError
,
"unable to bind result set for <"
<<
version_sql
<<
">, reason: "
<<
mysql_errno
(
conn
.
mysql_
));
}
// Discard the statement and its resources
return
(
std
::
make_pair
(
major
,
minor
));
mysql_stmt_close
(
stmt
);
return
(
std
::
make_pair
(
major
,
minor
));
}
catch
(
const
std
::
exception
&
)
{
// Avoid a memory leak on error.
mysql_stmt_close
(
stmt
);
// Send the exception to the caller.
throw
;
}
}
}
// Prepared statement setup. The textual form of an SQL statement is stored
// Prepared statement setup. The textual form of an SQL statement is stored
...
...
Write
Preview
Markdown
is supported
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