SQL/MySQL: add options to explicitly specify the protocol type
[ChangeLog][QtSql] Added the ability to specify the MySQL/MariaDB connection type using the "MYSQL_OPT_PROTOCOL" connection string option. In case the connection type is "MEMORY" for shared memory, applications can specify the shared memory segment name using the "MYSQL_SHARED_MEMORY_BASE_NAME" option. Fixes: QTBUG-2551 Change-Id: I91e0981994c045fb74478d0e765e2ec24eefeece Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
e7e1515ead
commit
b73574c4a6
@ -1172,6 +1172,24 @@ static bool setOptionBool(MYSQL *mysql, mysql_option option, QStringView v)
|
||||
return mysql_options(mysql, option, &val) == 0;
|
||||
}
|
||||
|
||||
static bool setOptionProtocol(MYSQL *mysql, mysql_option option, QStringView v)
|
||||
{
|
||||
mysql_protocol_type proto = MYSQL_PROTOCOL_DEFAULT;
|
||||
if (v == "TCP"_L1 || v == "MYSQL_PROTOCOL_TCP"_L1)
|
||||
proto = MYSQL_PROTOCOL_TCP;
|
||||
else if (v == "SOCKET"_L1 || v == "MYSQL_PROTOCOL_SOCKET"_L1)
|
||||
proto = MYSQL_PROTOCOL_SOCKET;
|
||||
else if (v == "PIPE"_L1 || v == "MYSQL_PROTOCOL_PIPE"_L1)
|
||||
proto = MYSQL_PROTOCOL_PIPE;
|
||||
else if (v == "MEMORY"_L1 || v == "MYSQL_PROTOCOL_MEMORY"_L1)
|
||||
proto = MYSQL_PROTOCOL_MEMORY;
|
||||
else if (v == "DEFAULT"_L1 || v == "MYSQL_PROTOCOL_DEFAULT"_L1)
|
||||
proto = MYSQL_PROTOCOL_DEFAULT;
|
||||
else
|
||||
qWarning() << "Unknown protocol '" << v << "' - using MYSQL_PROTOCOL_DEFAULT";
|
||||
return mysql_options(mysql, option, &proto) == 0;
|
||||
}
|
||||
|
||||
bool QMYSQLDriver::open(const QString &db,
|
||||
const QString &user,
|
||||
const QString &password,
|
||||
@ -1214,6 +1232,8 @@ bool QMYSQLDriver::open(const QString &db,
|
||||
{"MYSQL_OPT_WRITE_TIMEOUT"_L1, MYSQL_OPT_WRITE_TIMEOUT, setOptionInt},
|
||||
{"MYSQL_OPT_RECONNECT"_L1, MYSQL_OPT_RECONNECT, setOptionBool},
|
||||
{"MYSQL_OPT_LOCAL_INFILE"_L1, MYSQL_OPT_LOCAL_INFILE, setOptionInt},
|
||||
{"MYSQL_OPT_PROTOCOL"_L1, MYSQL_OPT_PROTOCOL, setOptionProtocol},
|
||||
{"MYSQL_SHARED_MEMORY_BASE_NAME"_L1, MYSQL_SHARED_MEMORY_BASE_NAME, setOptionString},
|
||||
};
|
||||
auto trySetOption = [&](const QStringView &key, const QStringView &value) -> bool {
|
||||
for (const mysqloptions &opt : options) {
|
||||
|
@ -173,9 +173,20 @@
|
||||
\row
|
||||
\li CLIENT_INTERACTIVE
|
||||
\li If set, client is treated as interactive
|
||||
\row
|
||||
\li MYSQL_OPT_PROTOCOL
|
||||
\li explicitly specify the protocol to use:\br
|
||||
MYSQL_PROTOCOL_TCP: use tcp connection (ip/hostname specified through setHostname())
|
||||
MYSQL_PROTOCOL_SOCKET: connect through a socket specified in UNIX_SOCKET
|
||||
MYSQL_PROTOCOL_PIPE: connect through a named pipe specified in UNIX_SOCKET
|
||||
MYSQL_PROTOCOL_MEMORY: connect through shared memory specified in MYSQL_SHARED_MEMORY_BASE_NAME
|
||||
\row
|
||||
\li UNIX_SOCKET
|
||||
\li Specifies the socket or named pipe to use
|
||||
\li Specifies the socket or named pipe to use, even it's called UNIX_SOCKET it
|
||||
can also be used on windows
|
||||
\row
|
||||
\li MYSQL_SHARED_MEMORY_BASE_NAME
|
||||
\li Specified the shared memory segment name to use
|
||||
\row
|
||||
\li MYSQL_OPT_RECONNECT
|
||||
\li TRUE or 1: Automatically reconnect after connection loss\br
|
||||
|
Loading…
Reference in New Issue
Block a user