Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for .bit & .timestamp, add decode case for .string #131

Merged
merged 3 commits into from Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions Sources/MySQL/Parsing/Row+Parsing.swift
Expand Up @@ -112,7 +112,6 @@ extension Parser {
return .double(Double(bitPattern: num))
case .null:
return .null
case .timestamp: throw MySQLError(.unsupported, source: .capture())
case .longlong:
let num = try self.parseUInt64()

Expand All @@ -124,7 +123,7 @@ extension Parser {
case .int24: throw MySQLError(.unsupported, source: .capture())
case .date: throw MySQLError(.unsupported, source: .capture())
case .time: throw MySQLError(.unsupported, source: .capture())
case .datetime:
case .datetime, .timestamp:
let format = try byte()

let year = try parseUInt16()
Expand Down Expand Up @@ -161,7 +160,13 @@ extension Parser {
case .newdate: throw MySQLError(.unsupported, source: .capture())
case .varchar:
return .varChar(try self.parseLenEncString())
case .bit: throw MySQLError(.unsupported, source: .capture())
case .bit:
let length = try byte()
if length > 8 {
throw MySQLError(.unsupported, source: .capture())
}
let value = try byte()
return .uint8(value)
case .json: throw MySQLError(.unsupported, source: .capture())
case .newdecimal: throw MySQLError(.unsupported, source: .capture())
case .enum: throw MySQLError(.unsupported, source: .capture())
Expand Down
2 changes: 2 additions & 0 deletions Sources/MySQL/Parsing/RowDecoder.swift
Expand Up @@ -66,6 +66,8 @@ final class RowDecoder : DecoderHelper {
func decode(_ type: Column) throws -> String {
if case .varString(let string) = type {
return string
} else if case .string(let string) = type {
return string
} else if case .blob(let data) = type {
guard let string = String(data: data, encoding: .utf8) else {
throw CodableDecodingError.incorrectValue
Expand Down