vapor/mysql-nio

SERVER_MORE_RESULTS_EXISTS support

t-ae opened this issue · 2 comments

t-ae commented

Recently I made PR to make MySQLCapabilities available (#170).

Now we can use CLIENT_MULTI_STATEMENTS. However I found MySQLPacketDecoder doesn't support results of such queries.

The result packet of multi statements query contains the status flag SERVER_MORE_RESULTS_EXISTS, but the decoder doesn't read more.
So if we execute next query, it'll recieves invalid bytes previous query left.

Reproduction code.

let config = MySQLDatabaseConfig(hostname: "localhost",
                                 port: 3306,
                                 username: "root",
                                 password: "PASSWORD",
                                 database: "DATABASE",
                                 capabilities: MySQLCapabilities.default.union([.CLIENT_MULTI_STATEMENTS]))
let mysql = MySQLDatabase(config: config)
let eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let conn = try! mysql.newConnection(on: eventLoop).wait()

let query = """
set time_zone = "+00:00";
select CURRENT_TIMESTAMP;
"""
let res1 = try! conn.simpleQuery(query).wait()
print("res1: ", res1)

// Second query doesn't work well.
let res2 = try! conn.simpleQuery("select * from fluent where id = 0").wait()
print("res2: ", res2)

simpleQuery returns only one result, so we need multiQuery if the decoder supports SERVER_MORE_RESULTS_EXISTS.

I don't know if there's someone who really needs multiple statements (We can split query with ; and execute one by one). So simply forbid using CLIENT_MULTI_STATEMENTS is an option.

I think this package should support SERVER_MORE_RESULTS_EXISTS in a future update.

This issue is related to vapor/mysql-kit#189. When the packet coder state is cleaned up, we should also add support for the more results query type.