Skip to content

Commit 9679e30

Browse files
Merge pull request #5646 from yurriy/mysql
Sessions and default database support in MySQL wire protocol
2 parents 73f2820 + 2e29ea7 commit 9679e30

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

dbms/programs/server/MySQLHandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ MySQLHandler::MySQLHandler(IServer & server_, const Poco::Net::StreamSocket & so
4848
void MySQLHandler::run()
4949
{
5050
connection_context = server.context();
51+
connection_context.setSessionContext(connection_context);
5152
connection_context.setDefaultFormat("MySQLWire");
5253

5354
in = std::make_shared<ReadBufferFromPocoSocket>(socket());
@@ -306,7 +307,7 @@ void MySQLHandler::authenticate(const HandshakeResponse & handshake_response, co
306307
try
307308
{
308309
connection_context.setUser(handshake_response.username, password, socket().address(), "");
309-
connection_context.setCurrentDatabase(handshake_response.database);
310+
if (!handshake_response.database.empty()) connection_context.setCurrentDatabase(handshake_response.database);
310311
connection_context.setCurrentQueryId("");
311312
LOG_ERROR(log, "Authentication for user " << handshake_response.username << " succeeded.");
312313
}

dbms/tests/integration/test_mysql_protocol/test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_mysql_client(mysql_client, server_address):
5151
-e "SELECT 'тест' as b;"
5252
'''.format(host=server_address, port=server_port), demux=True)
5353

54-
assert stdout == 'a\n1\nb\nтест\n'
54+
assert stdout == '\n'.join(['a', '1', 'b', 'тест', ''])
5555

5656
code, (stdout, stderr) = mysql_client.exec_run('''
5757
mysql --protocol tcp -h {host} -P {port} default -u default --password=abc -e "select 1 as a;"
@@ -75,14 +75,17 @@ def test_mysql_client(mysql_client, server_address):
7575
mysql --protocol tcp -h {host} -P {port} default -u default --password=123
7676
-e "CREATE DATABASE x;"
7777
-e "USE x;"
78-
-e "CREATE TABLE table1 (a UInt32) ENGINE = Memory;"
78+
-e "CREATE TABLE table1 (column UInt32) ENGINE = Memory;"
7979
-e "INSERT INTO table1 VALUES (0), (1), (5);"
8080
-e "INSERT INTO table1 VALUES (0), (1), (5);"
81-
-e "SELECT * FROM table1 ORDER BY a;"
81+
-e "SELECT * FROM table1 ORDER BY column;"
8282
-e "DROP DATABASE x;"
83+
-e "CREATE TEMPORARY TABLE tmp (tmp_column UInt32);"
84+
-e "INSERT INTO tmp VALUES (0), (1);"
85+
-e "SELECT * FROM tmp ORDER BY tmp_column;"
8386
'''.format(host=server_address, port=server_port), demux=True)
8487

85-
assert stdout == 'a\n0\n0\n1\n1\n5\n5\n'
88+
assert stdout == '\n'.join(['column', '0', '0', '1', '1', '5', '5', 'tmp_column', '0', '1', ''])
8689

8790

8891
def test_python_client(server_address):

0 commit comments

Comments
 (0)