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

ClientSettings are used to construct Client objects. More...

Public Member Functions

 ClientSettings (const string &uri)
 Create client settings from a connection string. More...
 
 ClientSettings (const string &uri, ClientSettings &opts)
 Create client settings from a connection string and a ClientSettings object. More...
 
 ClientSettings (const string &uri, const DbDoc &options)
 Create client settings from a connection string and. More...
 
 ClientSettings (const string &uri, const char *options)
 Create client settings from a connection string and. More...
 
template<typename... R>
 ClientSettings (const string &uri, mysqlx::ClientOption opt, R... rest)
 Create client settings from a connection string and client settings as a list of client options. More...
 
Value find (mysqlx::ClientOption opt)
 Find the specified option opt and returns its Value. More...
 
template<typename OPT , typename... R>
void set (OPT opt, R &&... rest)
 Set client and session options. More...
 
void clear ()
 Clear all settings specified so far.
 
void erase (mysqlx::ClientOption opt)
 Remove the given option opt.
 
bool has_option (ClientOption::Enum opt)
 Check if option opt was defined.
 
bool has_option (SessionOption::Enum opt)
 Check if option opt was defined.
 

Detailed Description

ClientSettings are used to construct Client objects.

It can be constructed using a connection string plus a JSON with client options, or by setting each ClientOption and SessionOption with its correspondant value.

Constructor & Destructor Documentation

◆ ClientSettings() [1/5]

ClientSettings ( const string uri)
inline

Create client settings from a connection string.

See also
SessionSettings

◆ ClientSettings() [2/5]

ClientSettings ( const string uri,
ClientSettings opts 
)
inline

Create client settings from a connection string and a ClientSettings object.

See also
SessionSettings

◆ ClientSettings() [3/5]

ClientSettings ( const string uri,
const DbDoc options 
)
inline

Create client settings from a connection string and.

Client options are expressed in JSON format. Here is an example:

{ "pooling": {
"enabled": true,
"maxSize": 25,
"queueTimeout": 1000,
"maxIdleTime": 5000}
}

All options are defined under a document with key vale "pooling". Inside the document, the available options are these:

  • enabled : boolean value that enable or disable connection pooling. If disabled, session created from pool are the same as created directly without client handle. Enabled by default.
  • maxSize : integer that defines the max pooling sessions possible. If uses tries to get session from pool when maximum sessions are used, it will wait for an available session untill queueTimeout. Defaults to 25.
  • queueTimeout : integer value that defines the time, in milliseconds, that client will wait to get an available session. By default it doesn't timeouts.
  • maxIdleTime : integer value that defines the time, in milliseconds, that an available session will wait in the pool before it is removed. By default it doesn't cleans sessions.

◆ ClientSettings() [4/5]

ClientSettings ( const string uri,
const char *  options 
)
inline

Create client settings from a connection string and.

Client options are expressed in JSON format. Here is an example:

{ "pooling": {
"enabled": true,
"maxSize": 25,
"queueTimeout": 1000,
"maxIdleTime": 5000}
}

All options are defined under a document with key vale "pooling". Inside the document, the available options are these:

  • enabled : boolean value that enable or disable connection pooling. If disabled, session created from pool are the same as created directly without client handle. Enabled by default.
  • maxSize : integer that defines the max pooling sessions possible. If uses tries to get session from pool when maximum sessions are used, it will wait for an available session untill queueTimeout. Defaults to 25.
  • queueTimeout : integer value that defines the time, in milliseconds, that client will wait to get an available session. By default it doesn't timeouts.
  • maxIdleTime : integer value that defines the time, in milliseconds, that an available session will wait in the pool before it is removed. By default it doesn't cleans sessions.

◆ ClientSettings() [5/5]

ClientSettings ( const string uri,
mysqlx::ClientOption  opt,
R...  rest 
)
inline

Create client settings from a connection string and client settings as a list of client options.

The list of options consist of a ClientOption constant, identifying the option to set, followed by the value of the option.

Example:

ClientSettings from_option_list( "mysqlx://root@localhost",
ClientOption::POOL_MAX_SIZE, max_connections,
ClientOption::POOL_QUEUE_TIMEOUT, std::chrono::seconds(100),
ClientOption::POOL_MAX_IDLE_TIME, std::chrono::microseconds(1)
);
@ POOLING
Definition: settings.h:128
@ POOL_QUEUE_TIMEOUT
Definition: settings.h:128
@ POOL_MAX_SIZE
Definition: settings.h:128
@ POOL_MAX_IDLE_TIME
Definition: settings.h:128
ClientSettings(const string &uri)
Create client settings from a connection string.
Definition: settings.h:845

ClientOption::POOL_QUEUE_TIMEOUT and ClientOption::POOL_MAX_IDLE_TIME can be specified using std::chrono::duration objects, or by integer values, with the latest to be specified in milliseconds.

See also
SessionSettings

Member Function Documentation

◆ find()

Value find ( mysqlx::ClientOption  opt)
inline

Find the specified option opt and returns its Value.

Returns NULL Value if not found.

◆ set()

void set ( OPT  opt,
R &&...  rest 
)
inline

Set client and session options.

Accepts a list of one or more ClientOption or SessionOption constants, each followed by the option value. Options specified here are added to the current settings.

Repeated HOST, PORT, SOCKET and PRIORITY options build a list of hosts to be used by the fail-over logic. For other options, if they are set again, the new value overrides the previous setting.

Note
When using HOST, PORT and PRIORITY options to specify a single host, all have to be specified in the same set() call.

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