From bea551092d125eccc0cca8ccb89ba4ebcf8ff79b Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 13 Jun 2017 15:27:41 +0300 Subject: [PATCH] MXS-1278: Change modes when 'set sql_mode=' is encountered. The initial setting of sql_mode affects how MaxScale initially behaves with respect to autocommit. When 'set sql_mode=[default|oracle];" is encountered, the query classifier and autocommit modes are adjusted accordingly. --- Documentation/Getting-Started/Configuration-Guide.md | 8 ++++++++ server/core/session.c | 6 ++++++ server/modules/protocol/MySQL/MySQLClient/mysql_client.cc | 2 ++ 3 files changed, 16 insertions(+) diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 6246b93d3..a31823a0a 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -534,6 +534,9 @@ sql_mode=oracle The default value is `default`. +**NOTE** If `sql_mode` is set to `oracle`, then MaxScale will also assume +that `autocommit` initially is off. + At runtime, MariaDB MaxScale will recognize statements like ``` set sql_mode=oracle; @@ -544,6 +547,11 @@ set sql_mode=default; ``` and change mode accordingly. +**NOTE** If `set sql_mode=oracle;` is encountered, then MaxScale will also +behave as if `autocommit` had been turned off and conversely, if +`set sql_mode=default;` is encountered, then MaxScale will also behave +as if `autocommit` had been turned on. + Note that MariaDB MaxScale is **not** explicitly aware of the sql mode of the server, so the value of `sql_mode` should reflect the sql mode used when the server is started. diff --git a/server/core/session.c b/server/core/session.c index fff7f9832..2403532b2 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -112,6 +112,12 @@ session_alloc(SERVICE *service, DCB *client_dcb) session->stats.connect = time(0); session->stmt.buffer = NULL; session->stmt.target = NULL; + + MXS_CONFIG *config = config_get_global_options(); + // If MaxScale is running in Oracle mode, then autocommit needs to + // initially be off. + bool autocommit = (config->qc_sql_mode == QC_SQL_MODE_ORACLE) ? false : true; + session_set_autocommit(session, autocommit); /*< * Associate the session to the client DCB and set the reference count on * the session to indicate that there is a single reference to the diff --git a/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc b/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc index da8b69e5a..6cf503cc4 100644 --- a/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc +++ b/server/modules/protocol/MySQL/MySQLClient/mysql_client.cc @@ -888,10 +888,12 @@ void set_qc_mode(MXS_SESSION* session, GWBUF** read_buffer) switch (sql_mode) { case SetSqlModeParser::ORACLE: + session_set_autocommit(session, false); session->client_protocol_data = QC_SQL_MODE_ORACLE; break; case SetSqlModeParser::DEFAULT: + session_set_autocommit(session, true); session->client_protocol_data = QC_SQL_MODE_DEFAULT; break;