add fail-readonly connection string parameter

This commit is contained in:
Günter Obiltschnig 2020-02-08 15:41:43 +01:00
parent 8bf5fceaaf
commit 506049e360
2 changed files with 12 additions and 1 deletions

View File

@ -47,7 +47,7 @@ public:
/// Connection string format:
/// <str> == <assignment> | <assignment> ';' <str>
/// <assignment> == <name> '=' <value>
/// <name> == 'host' | 'port' | 'user' | 'password' | 'db' | 'compress' | 'auto-reconnect' | 'reset'
/// <name> == 'host' | 'port' | 'user' | 'password' | 'db' | 'compress' | 'auto-reconnect' | 'reset' | 'fail-readonly'
/// <value> == [~;]*
///
/// The following settings are supported:
@ -61,6 +61,9 @@ public:
/// - character-set: connection character set (default: utf8)
/// - reset: reset connection when returned to SessionPool by calling
/// mysql_reset_connection().
/// - fail-readonly: if set to true, the session will fail
/// if the database becomes read-only. This corresponds to
/// setFailIfInnoReadOnly(true).
///
/// Warning: Due to a bug in MySQL, resetting the connection with mysql_reset_connection()
/// could change the character encoding used for the connection. Therefore the

View File

@ -92,6 +92,7 @@ void SessionImpl::open(const std::string& connect)
options["secure-auth"] = "";
options["character-set"] = "utf8";
options["reset"] = "";
options["fail-readonly"] = "";
const std::string& connString = connectionString();
for (std::string::const_iterator start = connString.begin();;)
@ -153,6 +154,13 @@ void SessionImpl::open(const std::string& connect)
else if (!options["reset"].empty())
throw MySQLException("create session: specify correct reset option (true or false)");
if (options["fail-readonly"] == "true")
_failIfInnoReadOnly = true;
else if (options["fail-readonly"] == "false")
_failIfInnoReadOnly = false;
else if (!options["fail-readonly"].empty())
throw MySQLException("create session: specify correct fail-readonly option (true or false)");
// Real connect
_handle.connect(options["host"].c_str(),
options["user"].c_str(),