MySQL Connector/C++  8.0.5
MySQL connector library for C and C++ applications
Public Types | Public Member Functions | List of all members
SessionSettings Class Reference

Represents session options to be passed at Session object creation. More...

Public Types

enum  Options {
  URI, HOST, PORT, PRIORITY,
  USER, PWD, DB, SSL_MODE,
  SSL_CA
}
 Session creation options. More...
 
enum  SSLMode { DISABLED, REQUIRED, VERIFY_CA, VERIFY_IDENTITY }
 Modes to be used by SSL_MODE option. More...
 

Public Member Functions

 SessionSettings (const string &uri)
 Get settings from a connection string or URI. More...
 
 SessionSettings (const std::string &host, unsigned port, const string &user, const char *pwd=NULL, const string &db=string())
 Explicitly specify basic connection settings. More...
 
 SessionSettings (const std::string &host, const string &user, const char *pwd=NULL, const string &db=string())
 Basic settings with the default port. More...
 
 SessionSettings (unsigned port, const string &user, const char *pwd=NULL, const string &db=string())
 Basic settings for a session on the localhost. More...
 
template<typename V , typename... R>
 SessionSettings (Options opt, V val, R...rest)
 Specify settings as a list of session options. More...
 
iterator begin ()
 Returns an iterator pointing to the first element of the SessionSettings.
 
iterator end ()
 Returns an iterator pointing to the last element of the SessionSettings.
 
Valuefind (Options opt)
 Finds element of specified opt and returns its Value. More...
 
template<typename V , typename... R>
void set (Options opt, V v, R...rest)
 Set list of Options to given values. More...
 
void clear ()
 Clears all settings specified so far.
 
void erase (Options opt)
 Remove all settings for the given option opt. More...
 
bool has_option (Options opt)
 Check if option opt was defined.
 

Detailed Description

Represents session options to be passed at Session object creation.

SessionSettings can be constructed using URL string, common connect options (host, port, user, password, database) or with a list of SessionSettings::Options constants followed by option value.

Examples:

SessionSettings from_url("mysqlx://user:pwd@host:port/db?ssl-mode=required");
SessionSettings from_options("host", port, "user", "pwd", "db");
SessionSettings from_option_list(
);

Some settings, such as HOST, can be specified several times to build a list of hosts to be used by connection fail-over logic.

Member Enumeration Documentation

◆ Options

enum Options

Session creation options.

Note
PRIORITY should be defined after a HOST (PORT) definition
Specifying SSL_CA option requires SSL_MODE value of VERIFY_CA or VERIFY_IDENTITY. If SSL_MODE is not explicitly given then setting SSL_CA implies VERIFY_CA.
Enumerator
URI 

connection URI or string

HOST 

DNS name of the host, IPv4 address or IPv6 address

PORT 

X Plugin port to connect to

PRIORITY 

define priority on a multiple host connection

USER 

user name

PWD 

password

DB 

default database

SSL_MODE 

define SSLMode option to be used

SSL_CA 

path to a PEM file specifying trusted root certificates

◆ SSLMode

enum SSLMode
strong

Modes to be used by SSL_MODE option.

Enumerator
DISABLED 

Establish an unencrypted connection.

REQUIRED 

Establish a secure connection if the server supports secure connections. The connection attempt fails if a secure connection cannot be established. This is the default if SSL_MODE is not specified.

VERIFY_CA 

Like REQUIRED, but additionally verify the server TLS certificate against the configured Certificate Authority (CA) certificates (defined by SSL_CA Option). The connection attempt fails if no valid matching CA certificates are found.

VERIFY_IDENTITY 

Like VERIFY_CA, but additionally verify that the server certificate matches the host to which the connection is attempted.

Constructor & Destructor Documentation

◆ SessionSettings() [1/5]

SessionSettings ( const string uri)
inline

Get settings from a connection string or URI.

Connection sting has the form "user:pass\@host:port/?option&option", valid URI is like a connection string with a mysqlx:// prefix. Host is specified as either DNS name, IPv4 address of the form "nn.nn.nn.nn" or IPv6 address of the form "[nn:nn:nn:...]".

Possible connection options are:

  • ssl-mode : define SSLMode option to be used
  • ssl-ca=path : path to a PEM file specifying trusted root certificates

◆ SessionSettings() [2/5]

SessionSettings ( const std::string &  host,
unsigned  port,
const string user,
const char *  pwd = NULL,
const string db = string() 
)
inline

Explicitly specify basic connection settings.

Note
Session settings constructed this way request an SSL connection by default.

◆ SessionSettings() [3/5]

SessionSettings ( const std::string &  host,
const string user,
const char *  pwd = NULL,
const string db = string() 
)
inline

Basic settings with the default port.

Note
Session settings constructed this way request an SSL connection by default.

◆ SessionSettings() [4/5]

SessionSettings ( unsigned  port,
const string user,
const char *  pwd = NULL,
const string db = string() 
)
inline

Basic settings for a session on the localhost.

Note
Session settings constructed this way request an SSL connection by default.

◆ SessionSettings() [5/5]

SessionSettings ( Options  opt,
val,
R...  rest 
)
inline

Specify settings as a list of session options.

The list of options consist of SessionSettings::Options constant identifying the option to set, followed by option value.

Example:

See also
SessionSettings::Options.

Member Function Documentation

◆ find()

Value& find ( Options  opt)

Finds element of specified opt and returns its Value.

Will throw Error if not found.

◆ set()

void set ( Options  opt,
v,
R...  rest 
)
inline

Set list of Options to given values.

When using HOST, PORT and PRIORITY, all have to be defined in the same set() call.

◆ erase()

void erase ( Options  opt)
inline

Remove all settings for the given option opt.

Note
For option such as HOST, which can repeat several times in the settings, all occurences are erased.

The documentation for this class was generated from the following file: