| Home | Libraries | People | FAQ | More

###### any_connection::set_character_set (1 of 2 overloads)

Sets the connection's character set, as per SET NAMES.

###### Synopsis

    void
    set_character_set(
        const character_set& charset,
        error_code& err,
        diagnostics& diag);

###### Description

Sets the connection's character set by running a `SET NAMES` SQL statement, using the passed `character_set::name` as the charset name to set.

This function will also update the value returned by `current_character_set`, so prefer using this function over raw SQL statements.

If the server was unable to set the character set to the requested value (e.g. because the server does not support the requested charset), this function will fail, as opposed to how `connect` behaves when an unsupported collation is passed. This is a limitation of MySQL servers.

You need to perform connection establishment for this function to succeed, since it involves communicating with the server.

###### Object lifetimes

`charset` will be copied as required, and does not need to be kept alive.