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

update from PerfectlySoft master #1

Merged
merged 4 commits into from
Aug 7, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
DEVELOPMENT-SNAPSHOT-2016-07-25-a
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# Perfect - PostgreSQL Connector

[![GitHub version](https://badge.fury.io/gh/PerfectlySoft%2FPerfect-PostgreSQL.svg)](https://badge.fury.io/gh/PerfectlySoft%2FPerfect-PostgreSQL)
[![Gitter](https://badges.gitter.im/PerfectlySoft/PerfectDocs.svg)](https://gitter.im/PerfectlySoft/PerfectDocs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)


This project provides a Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.

This package builds with Swift Package Manager and is part of the [Perfect](/~https://github.com/PerfectlySoft/Perfect) project. It was written to be stand-alone and so does not require PerfectLib or any other components.

Ensure you have installed and activated the latest Swift 3.0 tool chain.


## Issues

We are transitioning to using JIRA for all bugs and support related issues, therefore the GitHub issues has been disabled.

If you find a mistake, bug, or any other helpful suggestion you'd like to make on the docs please head over to [http://jira.perfect.org:8080/servicedesk/customer/portal/1](http://jira.perfect.org:8080/servicedesk/customer/portal/1) and raise it.

A comprehensive list of open issues can be found at [http://jira.perfect.org:8080/projects/ISS/issues](http://jira.perfect.org:8080/projects/ISS/issues)


## OS X Build Notes

This package requires the [Home Brew](http://brew.sh) build of PostgreSQL.
Expand Down
42 changes: 2 additions & 40 deletions Sources/PostgreSQL/PostgreSQL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,6 @@

import libpq

#if swift(>=3.0)
extension UnsafeMutablePointer {
public static func allocatingCapacity(_ num: Int) -> UnsafeMutablePointer<Pointee> {
return UnsafeMutablePointer<Pointee>(allocatingCapacity: num)
}
}
#else
typealias ErrorProtocol = ErrorType
typealias OpaquePointer = COpaquePointer

extension String {
init?(validatingUTF8: UnsafePointer<Int8>) {
if let s = String.fromCString(validatingUTF8) {
self.init(s)
} else {
return nil
}
}
}
extension UnsafeMutablePointer {
public static func allocatingCapacity(num: Int) -> UnsafeMutablePointer<Memory> {
return UnsafeMutablePointer<Memory>.alloc(num)
}

func deallocateCapacity(num: Int) {
self.dealloc(num)
}

func deinitialize(count count: Int) {
self.destroy(count)
}
}
#endif

/// result object
public final class PGResult {

Expand Down Expand Up @@ -340,13 +306,9 @@ public final class PGConnection {
asStrings.append(String(item))
}
let count = asStrings.count
#if swift(>=3.0)
let values = UnsafeMutablePointer<UnsafePointer<Int8>?>.allocatingCapacity(count)
#else
let values = UnsafeMutablePointer<UnsafePointer<Int8>>.allocatingCapacity(count)
#endif
let values = UnsafeMutablePointer<UnsafePointer<Int8>?>.allocate(capacity: count)
defer {
values.deinitialize(count: count) ; values.deallocateCapacity(count)
values.deinitialize(count: count) ; values.deallocate(capacity: count)
}
var temps = [Array<UInt8>]()
for idx in 0..<count {
Expand Down
4 changes: 2 additions & 2 deletions Tests/PostgreSQL/PostgreSQLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PostgreSQLTests: XCTestCase {
XCTAssert(num > 0)
for x in 0..<num {
let c1 = res.getFieldString(tupleIndex: x, fieldIndex: 0)
XCTAssertTrue(c1?.characters.count > 0)
XCTAssertTrue((c1?.characters.count)! > 0)
let c2 = res.getFieldInt(tupleIndex: x, fieldIndex: 1)
let c3 = res.getFieldInt(tupleIndex: x, fieldIndex: 2)
let c4 = res.getFieldBool(tupleIndex: x, fieldIndex: 3)
Expand All @@ -96,7 +96,7 @@ class PostgreSQLTests: XCTestCase {
XCTAssert(num > 0)
for x in 0..<num {
let c1 = res.getFieldString(tupleIndex: x, fieldIndex: 0)
XCTAssertTrue(c1?.characters.count > 0)
XCTAssertTrue((c1?.characters.count)! > 0)
let c2 = res.getFieldInt(tupleIndex: x, fieldIndex: 1)
let c3 = res.getFieldInt(tupleIndex: x, fieldIndex: 2)
let c4 = res.getFieldBool(tupleIndex: x, fieldIndex: 3)
Expand Down