Skip to content

Commit

Permalink
Merge pull request #3 from rymcol/vapor-update
Browse files Browse the repository at this point in the history
Update for DEVELOPMENT-SNAPSHOT-2016-07-25-a
  • Loading branch information
tanner0101 authored Aug 5, 2016
2 parents 6490960 + a534dbd commit b184c24
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DEVELOPMENT-SNAPSHOT-2016-06-20-a
DEVELOPMENT-SNAPSHOT-2016-07-25-a
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ os:
language: generic
sudo: required
dist: trusty
osx_image: xcode7.3
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/02090c7ede5a637b76e6df1710e83cd0bbe7dcdf/swiftenv-install.sh)"
osx_image: xcode8
script:
# Build SQLite
- swift build
- swift build --configuration release
# Test SQLite
- swift test

- eval "$(curl -sL swift.qutheory.io/ci)"
- eval "$(curl -sL swift.qutheory.io/codecov)"
26 changes: 13 additions & 13 deletions Sources/SQLite/SQLite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SQLite {
public init(path: String) throws {
let options = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX
if sqlite3_open_v2(path, &database, options, nil) != SQLITE_OK {
throw Error.connection(database?.errorMessage ?? "")
throw SQLiteError.connection(database?.errorMessage ?? "")
}
}

Expand Down Expand Up @@ -64,20 +64,20 @@ public class SQLite {
*/
public func execute(_ queryString: String, prepareClosure: PrepareClosure = { _ in }) throws -> [Result.Row] {
guard let database = self.database else {
throw Error.execute("No database")
throw SQLiteError.execute("No database")
}

let statementContainer = UnsafeMutablePointer<OpaquePointer?>.init(allocatingCapacity: 1)
let statementContainer = UnsafeMutablePointer<OpaquePointer?>.allocate(capacity: 1)
defer {
statementContainer.deallocateCapacity(1)
statementContainer.deallocate(capacity: 1)
}

if sqlite3_prepare_v2(database, queryString, -1, statementContainer, nil) != SQLITE_OK {
throw Error.prepare(database.errorMessage)
throw SQLiteError.prepare(database.errorMessage)
}

guard let statementPointer = statementContainer.pointee else {
throw Error.execute("Statement pointer errror")
throw SQLiteError.execute("Statement pointer errror")
}

let statement = Statement(pointer: statementPointer, database: database)
Expand All @@ -95,7 +95,7 @@ public class SQLite {

var value: String? = nil
if let text = text {
value = String(cString: UnsafePointer(text))
value = String(cString: text)
}

let column: String
Expand All @@ -112,7 +112,7 @@ public class SQLite {
}

if sqlite3_finalize(statement.pointer) != SQLITE_OK {
throw Error.execute(database.errorMessage)
throw SQLiteError.execute(database.errorMessage)
}

return result.rows
Expand All @@ -132,7 +132,7 @@ public class SQLite {
}

//MARK: Error
public enum Error: ErrorProtocol {
public enum SQLiteError: Error {
case connection(String)
case close(String)
case prepare(String)
Expand Down Expand Up @@ -170,7 +170,7 @@ extension SQLite.Database {
*/
var errorMessage: String {
if let raw = sqlite3_errmsg(self) {
return String(cString: raw) ?? "Unknown"
return String(cString: raw)
} else {
return "Unknown"
}
Expand Down Expand Up @@ -210,20 +210,20 @@ extension SQLite {

public func bind(_ value: Double) throws {
if sqlite3_bind_double(pointer, nextBindPosition, value) != SQLITE_OK {
throw Error.bind(database.errorMessage)
throw SQLiteError.bind(database.errorMessage)
}
}

public func bind(_ value: Int) throws {
if sqlite3_bind_int(pointer, nextBindPosition, Int32(value)) != SQLITE_OK {
throw Error.bind(database.errorMessage)
throw SQLiteError.bind(database.errorMessage)
}
}

public func bind(_ value: String) throws {
let strlen = Int32(value.characters.count)
if sqlite3_bind_text(pointer, nextBindPosition, value, strlen, SQLITE_TRANSIENT) != SQLITE_OK {
throw Error.bind(database.errorMessage)
throw SQLiteError.bind(database.errorMessage)
}
}

Expand Down

0 comments on commit b184c24

Please sign in to comment.