Skip to content

Commit

Permalink
Merge pull request #131 from PitchLabsAsh/add-bit-and-timestamp
Browse files Browse the repository at this point in the history
Add support for .bit & .timestamp, add decode case for .string
  • Loading branch information
tanner0101 committed Feb 28, 2018
2 parents b0c7a45 + f39b596 commit ceb1d3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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

0 comments on commit ceb1d3c

Please sign in to comment.