Skip to content

Commit accb820

Browse files
authored
Merge pull request #179 from vapor/deprecate-eof
fix deprecated EOF support for MySQL 5.5 and 5.6
2 parents d542b2e + dce8587 commit accb820

File tree

7 files changed

+72
-44
lines changed

7 files changed

+72
-44
lines changed

Sources/MySQL/Connection/MySQLConnection+Query.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension MySQLConnection {
1212
var rows: [[MySQLColumn: MySQLData]] = []
1313
return self.query(query) { row in
1414
rows.append(row)
15-
}.map(to: [[MySQLColumn: MySQLData]].self) {
15+
}.map {
1616
return rows
1717
}
1818
}

Sources/MySQL/Connection/MySQLConnection.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,17 @@ public final class MySQLConnection: BasicWorker, DatabaseConnection {
6767

6868
/// Sends `MySQLPacket` to the server.
6969
internal func send(_ messages: [MySQLPacket], onResponse: @escaping (MySQLPacket) throws -> Bool) -> Future<Void> {
70+
// if the connection is closed, fail immidiately
71+
guard !isClosed else {
72+
return eventLoop.newFailedFuture(error: closeError)
73+
}
74+
7075
// if currentSend is not nil, previous send has not completed
7176
assert(currentSend == nil, "Attempting to call `send(...)` again before previous invocation has completed.")
7277
switch handler.state {
7378
case .waiting: break
7479
default: assertionFailure("Attempting to call `send(...)` while handler is still: \(handler.state).")
7580
}
76-
// if the connection is closed, fail immidiately
77-
guard !isClosed else {
78-
return eventLoop.newFailedFuture(error: closeError)
79-
}
8081

8182
// create a new promise and store it
8283
let promise = eventLoop.newPromise(Void.self)

Sources/MySQL/Connection/MySQLConnectionHandler.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,16 @@ final class MySQLConnectionHandler: ChannelInboundHandler {
149149
}
150150

151151
func errorCaught(ctx: ChannelHandlerContext, error: Error) {
152-
readyForQuery?.fail(error: error)
153-
readyForQuery = nil
152+
switch state {
153+
case .nascent:
154+
readyForQuery?.fail(error: error)
155+
readyForQuery = nil
156+
case .callback(let promise, _):
157+
self.state = .waiting
158+
promise.fail(error: error)
159+
case .waiting:
160+
ERROR("Error while waiting: \(error).")
161+
}
154162
}
155163

156164
/// Ask the server if it supports SSL and adds a new OpenSSLClientHandler to pipeline if it does

Sources/MySQL/Pipeline/MySQLPacketDecoder.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ final class MySQLPacketDecoder: ByteToMessageDecoder {
232232
remaining -= 1
233233
if remaining == 0 {
234234
session.connectionState = .statement(.paramsDone(ok: ok))
235+
if !capabilities.contains(.CLIENT_DEPRECATE_EOF) {
236+
let res = try decodeBasicPacket(ctx: ctx, buffer: &buffer, capabilities: capabilities, forwarding: false)
237+
switch res {
238+
case .needMoreData: return .needMoreData
239+
default: break
240+
}
241+
}
235242
} else {
236243
session.connectionState = .statement(.params(ok: ok, remaining: remaining))
237244
}
@@ -242,10 +249,6 @@ final class MySQLPacketDecoder: ByteToMessageDecoder {
242249
} else {
243250
session.connectionState = .statement(.columnsDone)
244251
}
245-
246-
if !capabilities.contains(.CLIENT_DEPRECATE_EOF) {
247-
return try decodeBasicPacket(ctx: ctx, buffer: &buffer, capabilities: capabilities, forwarding: false)
248-
}
249252
case .columns(var remaining):
250253
guard let _ = try buffer.checkPacketLength(source: .capture()) else {
251254
return .needMoreData
@@ -257,15 +260,19 @@ final class MySQLPacketDecoder: ByteToMessageDecoder {
257260
remaining -= 1
258261
if remaining == 0 {
259262
session.connectionState = .statement(.columnsDone)
263+
if !capabilities.contains(.CLIENT_DEPRECATE_EOF) {
264+
let res = try decodeBasicPacket(ctx: ctx, buffer: &buffer, capabilities: capabilities, forwarding: false)
265+
switch res {
266+
case .needMoreData: return .needMoreData
267+
default: break
268+
}
269+
}
260270
} else {
261271
session.connectionState = .statement(.columns(remaining: remaining))
262272
}
263273

264274
ctx.fireChannelRead(wrapInboundOut(.columnDefinition41(column)))
265-
case .columnsDone:
266-
if !capabilities.contains(.CLIENT_DEPRECATE_EOF) {
267-
return try decodeBasicPacket(ctx: ctx, buffer: &buffer, capabilities: capabilities, forwarding: false)
268-
}
275+
case .columnsDone: break
269276
case .waitingExecute:
270277
// check for error or OK packet
271278
let peek = buffer.peekInteger(as: Byte.self, skipping: 4)

Tests/MySQLTests/MySQLTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MySQLTests: XCTestCase {
1919
"hello".convertToMySQLData(),
2020
"world".convertToMySQLData()
2121
])).wait()
22+
print(results)
2223
try XCTAssertEqual(results[0].firstValue(forColumn: "test")?.decode(String.self), "helloworld")
2324
print(results)
2425
}

circle.yml

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
version: 2
22

33
jobs:
4-
5-
6-
macos:
7-
macos:
8-
xcode: "9.2"
9-
steps:
10-
- run: brew install mysql
11-
- run: brew services start mysql
12-
- run: sleep 3 && mysqladmin -uroot create test
13-
- checkout
14-
- run: swift build
15-
- run: echo "CREATE DATABASE vapor_test" | mysql -uroot
16-
# - run: swift build -c release
17-
- run: swift test
18-
194
5.5-linux:
205
docker:
216
- image: codevapor/swift:4.1
@@ -34,7 +19,24 @@ jobs:
3419
- run:
3520
name: Run unit tests
3621
command: swift test
37-
22+
5.6-linux:
23+
docker:
24+
- image: codevapor/swift:4.1
25+
- image: mysql:5.6
26+
environment:
27+
MYSQL_ALLOW_EMPTY_PASSWORD: true
28+
MYSQL_DATABASE: vapor_database
29+
# MYSQL_ROOT_HOST: %
30+
MYSQL_USER: vapor_username
31+
MYSQL_PASSWORD: vapor_password
32+
steps:
33+
- checkout
34+
- run:
35+
name: Compile code
36+
command: swift build
37+
- run:
38+
name: Run unit tests
39+
command: swift test
3840
5.7-linux:
3941
docker:
4042
- image: codevapor/swift:4.1
@@ -53,7 +55,6 @@ jobs:
5355
- run:
5456
name: Run unit tests
5557
command: swift test
56-
5758
8.0-linux:
5859
docker:
5960
- image: codevapor/swift:4.1
@@ -72,7 +73,6 @@ jobs:
7273
- run:
7374
name: Run unit tests
7475
command: swift test -Xswiftc -DSSL_TESTS
75-
7676
mariadb-10.3-linux:
7777
docker:
7878
- image: codevapor/swift:4.1
@@ -91,7 +91,6 @@ jobs:
9191
- run:
9292
name: Run unit tests
9393
command: swift test
94-
9594
8.0-linux-fluent:
9695
docker:
9796
- image: codevapor/swift:4.1
@@ -104,7 +103,7 @@ jobs:
104103
steps:
105104
- run:
106105
name: Clone Fluent MySQL
107-
command: git clone -b gm https://github.com/vapor/fluent-mysql.git
106+
command: git clone -b master https://github.com/vapor/fluent-mysql.git
108107
working_directory: ~/
109108
- run:
110109
name: Switch Fluent MySQL to this MySQL revision
@@ -114,7 +113,6 @@ jobs:
114113
name: Run Fluent MySQL unit tests
115114
command: swift test
116115
working_directory: ~/fluent-mysql
117-
118116
linux-release:
119117
docker:
120118
- image: codevapor/swift:4.1
@@ -123,29 +121,24 @@ jobs:
123121
- run:
124122
name: Compile code with optimizations
125123
command: swift build -c release
126-
127-
128124
workflows:
129125
version: 2
130126
tests:
131127
jobs:
132-
# - macos
133-
# - 5.5-linux
128+
- 5.5-linux
129+
- 5.6-linux
134130
- 5.7-linux
135131
- 8.0-linux
136132
- 8.0-linux-fluent
137133
- mariadb-10.3-linux
138134
- linux-release
139-
140135
nightly:
141136
triggers:
142137
- schedule:
143138
cron: "0 0 * * *"
144139
filters:
145140
branches:
146141
only:
147-
- master
148-
142+
- master
149143
jobs:
150144
- 8.0-linux
151-
# - macos

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,21 @@ services:
1919
MYSQL_PASSWORD: vapor_password
2020
ports:
2121
- 3306:3306
22+
mysql-56:
23+
image: mysql:5.6
24+
environment:
25+
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
26+
MYSQL_DATABASE: vapor_database
27+
MYSQL_USER: vapor_username
28+
MYSQL_PASSWORD: vapor_password
29+
ports:
30+
- 3306:3306
31+
mysql-55:
32+
image: mysql:5.5
33+
environment:
34+
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
35+
MYSQL_DATABASE: vapor_database
36+
MYSQL_USER: vapor_username
37+
MYSQL_PASSWORD: vapor_password
38+
ports:
39+
- 3306:3306

0 commit comments

Comments
 (0)