![]() |
Home | Libraries | People | FAQ | More |
Retrieves the connection id associated to the current session.
boost::optional< std::uint32_t > connection_id() const noexcept;
If a session has been established, returns its associated connection id.
If no session has been established (i.e. async_connect
hasn't been called
yet) or the session has been terminated (i.e. async_close
has been called),
an empty optional is returned.
The connection id is a 4 byte value that uniquely identifies a client session
at a given point in time. It can be used with the KILL
SQL statement to cancel
queries and terminate connections.
The server sends the connection id assigned to the current session as part of the handshake process. The value is stored and made available through this function. The same id can also be obtained by calling the CONNECTION_ID() SQL function. However, this function is faster and more reliable, since it does not entail communication with the server.
This function is equivalent to the mysql_thread_id
function in the
C connector. This function works properly in 64-bit systems, as opposed
to what the official docs suggest (see this
changelog).
It is safe to call this function while an async operation is outstanding,
except for async_connect
and async_close
.
No-throw guarantee.