Database Reference
In-Depth Information
my
$ver_num
=
(
get_server_version
(
$dbh
))[
1
];
printf
"Event scheduler: %s\n"
, (
$ver_num
>=
50106
?
"yes"
:
"no"
);
printf
"4-byte Unicode: %s\n"
, (
$ver_num
>=
50503
?
"yes"
:
"no"
);
printf
"Fractional seconds: %s\n"
, (
$ver_num
>=
50604
?
"yes"
:
"no"
);
printf
"SHA-256 passwords: %s\n"
, (
$ver_num
>=
50606
?
"yes"
:
"no"
);
printf
"ALTER USER: %s\n"
, (
$ver_num
>=
50607
?
"yes"
:
"no"
);
printf
"INSERT DELAYED: %s\n"
, (
$ver_num
>=
50700
?
"no"
:
"yes"
);
The
recipes
distribution
metadata
directory contains
get_server_version()
imple‐
mentations in other API languages, and the
routines
directory contains a
server_ver
sion()
stored function for use in SQL statements. The latter function returns only the
numeric value because
VERSION()
already produces the string value. The following ex‐
ample shows how to use it to implement a stored procedure that expires an account
password if the server is recent enough to support the
ALTER
USER
statement (MySQL
5.6.7 or later):
CREATE
PROCEDURE
expire_password
(
user
TEXT
,
host
TEXT
)
BEGIN
DECLARE
account
TEXT
;
SET
account
=
CONCAT
(
QUOTE
(
user
),
'@'
,
QUOTE
(
host
));
IF
server_version
()
>=
50607
AND
user
<>
''
THEN
CALL
exec_stmt
(
CONCAT
(
'ALTER USER '
,
account
,
' PASSWORD EXPIRE'
));
END
IF
;
END
;
expire_password()
requires the
exec_stmt()
helper routine (see
Recipe 9.9
). Both are
available in the
routines
directory. For more information about password expiration,
see
Recipe 23.5
.