-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from noppoMan/lazy-result-set
API design changes for 0.2.x
- Loading branch information
Showing
21 changed files
with
817 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// Error.swift | ||
// SwiftMysqlPackageDescription | ||
// | ||
// Created by Yuki Takei on 2017/11/06. | ||
// | ||
|
||
import Foundation | ||
|
||
func createErrorFrom(errorPacket bytes :[UInt8]) -> MysqlError { | ||
if bytes[0] != 0xff { | ||
return MysqlClientError.error(code: -1, message: "EOF encountered") | ||
} | ||
|
||
let errno = bytes[1...3].uInt16() | ||
var pos = 3 | ||
|
||
if bytes[3] == 0x23 { | ||
pos = 9 | ||
} | ||
var d1 = Array(bytes[pos..<bytes.count]) | ||
d1.append(0) | ||
let errStr = d1.string() | ||
|
||
if errno > 2000 { | ||
return MysqlClientError.error(code: Int16(errno), message: errStr ?? "Unknown") | ||
} | ||
|
||
return MysqlServerError.error(code: Int16(errno), message: errStr ?? "Unknown") | ||
} | ||
|
||
public protocol MysqlError: Error { | ||
var code: Int16 { get } | ||
var message: String { get } | ||
} | ||
|
||
public enum MysqlClientError: MysqlError { | ||
case commandsOutOfSync | ||
case error(code: Int16, message: String) | ||
} | ||
|
||
extension MysqlClientError { | ||
public var code: Int16 { | ||
switch self { | ||
case .commandsOutOfSync: | ||
return 2014 | ||
case .error(let code, _): | ||
return code | ||
} | ||
} | ||
|
||
public var message: String { | ||
switch self { | ||
case .commandsOutOfSync: | ||
return "Commands out of sync; you can't run this command now" | ||
case .error(_, let mes): | ||
return mes | ||
} | ||
} | ||
} | ||
|
||
extension MysqlClientError: CustomStringConvertible { | ||
public var description: String { | ||
return "MYSQL CLIENT ERROR \(code): \(message)" | ||
} | ||
} | ||
|
||
public enum MysqlServerError: MysqlError { | ||
case error(code: Int16, message: String) | ||
} | ||
|
||
extension MysqlServerError { | ||
public var code: Int16 { | ||
switch self { | ||
case .error(let code, _): | ||
return code | ||
} | ||
} | ||
|
||
public var message: String { | ||
switch self { | ||
case .error(_, let mes): | ||
return mes | ||
} | ||
} | ||
} | ||
|
||
extension MysqlServerError: CustomStringConvertible { | ||
public var description: String { | ||
return "MYSQL SERVER ERROR \(code): \(message)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.