Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
62fd2020
Commit
62fd2020
authored
Dec 03, 2019
by
Francis Dupont
Browse files
[
#1008
] Addressed comments
parent
c131e65e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lib/mysql/mysql_connection.cc
View file @
62fd2020
...
...
@@ -229,52 +229,65 @@ MySqlConnection::getVersion(const ParameterMap& parameters) {
"statement structure, reason: "
<<
mysql_error
(
conn
.
mysql_
));
}
// Prepare the statement from SQL text.
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_
));
}
try
{
// Execute the prepared statement.
if
(
mysql_stmt_execute
(
stmt
)
!=
0
)
{
isc_throw
(
DbOperationError
,
"cannot execute schema version query <"
<<
version_sql
<<
">, reason: "
<<
mysql_errno
(
conn
.
mysql_
));
}
// Prepare the statement from SQL text.
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_
));
}
// Bind the output of the statement to the appropriate variables.
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_
));
}
// Execute the prepared statement.
if
(
mysql_stmt_execute
(
stmt
)
!=
0
)
{
isc_throw
(
DbOperationError
,
"cannot execute schema version query <"
<<
version_sql
<<
">, reason: "
<<
mysql_errno
(
conn
.
mysql_
));
}
// Fetch the data.
if
(
mysql_stmt_fetch
(
stmt
))
{
// Bind the output of the statement to the appropriate variables.
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
);
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
);
return
(
std
::
make_pair
(
major
,
minor
));
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
...
...
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