Skip to content

Commit

Permalink
undo merge revert(c72f801)
Browse files Browse the repository at this point in the history
  • Loading branch information
novi committed Sep 20, 2016
1 parent 36956cb commit 714a82b
Show file tree
Hide file tree
Showing 29 changed files with 241 additions and 223 deletions.
24 changes: 15 additions & 9 deletions .travis.yml
@@ -1,14 +1,19 @@
os:
- linux
- osx
language: generic
sudo: required
dist: trusty
osx_image: xcode7.3
matrix:
include:
- os: linux
dist: trusty
env: PERFORM_MAKE_TEST=1
- os: osx
osx_image: xcode8
env: PERFORM_XCODEBUILD=1 PERFORM_MAKE_TEST=1
addons:
mariadb: '10.1'
env:
- SWIFT_VERSION=DEVELOPMENT-SNAPSHOT-2016-06-06-a
global:
- SWIFT_VERSION=DEVELOPMENT-SNAPSHOT-2016-09-04-a
- TOOLCHAINS=org.swift.3020160904a
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install mariadb; fi
Expand All @@ -18,7 +23,8 @@ before_script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mysql.server start; fi
- mysql -u root -e "create database IF NOT EXISTS test;"
script:
- make
- make test
#- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xcodebuild -project OSX\ Projects/MySQL/MySQL.xcodeproj -scheme MySQL build test ; fi
- make debug
- make release
- if [[ "$PERFORM_MAKE_TEST" == "1" ]]; then make test; fi
- if [[ "$PERFORM_XCODEBUILD" == "1" ]]; then xcodebuild -project OSX\ Projects/MySQL/MySQL.xcodeproj -scheme MySQL build test ; fi

35 changes: 23 additions & 12 deletions Makefile
@@ -1,24 +1,35 @@
BUILDOPTS=-Xlinker -L/usr/lib
BUILD_OPTS=-Xlinker -L/usr/lib

SWIFTC=swiftc
SWIFT=swift
ifdef SWIFTPATH
SWIFTC=$(SWIFTPATH)/bin/swiftc
SWIFT=$(SWIFTPATH)/bin/swift
SWIFTC=$(SWIFTPATH)/bin/swiftc
SWIFT=$(SWIFTPATH)/bin/swift
endif

OS := $(shell uname)
ifeq ($(OS),Darwin)
SWIFTC=xcrun -sdk macosx swiftc
BUILDOPTS=-Xlinker -L/usr/local/lib -Xcc -I/usr/local/include/mysql -Xcc -I/usr/local/include
SWIFTC=xcrun -sdk macosx swiftc
BUILD_OPTS=-Xlinker -L/usr/local/opt/mariadb/lib -Xlinker -L/usr/local/opt/openssl/lib -Xcc -I/usr/local/include/mysql -Xcc -I/usr/local/include
endif

all: build

build:
$(SWIFT) build -v $(BUILDOPTS)

test: build
$(SWIFT) test
all: debug test

release: CONF_ENV=release
release: build_;

debug: CONF_ENV=debug
debug: build_;

build_:
$(SWIFT) build -v --configuration $(CONF_ENV) $(BUILD_OPTS)

clean:
$(SWIFT) build --clean build

distclean:
$(SWIFT) build --clean dist

test:
$(SWIFT) test -v $(BUILD_OPTS)

135 changes: 72 additions & 63 deletions OSX Projects/MySQL/MySQL.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
22 changes: 13 additions & 9 deletions OSX Projects/SQLFormatter/SQLFormatter.xcodeproj/project.pbxproj
Expand Up @@ -7,7 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
52547E671CBF7E2A00B42F71 /* SQLFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52547E661CBF7E2A00B42F71 /* SQLFormatterTests.swift */; };
525B38411D5AF3C400AE29A5 /* SQLFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525B38401D5AF3C400AE29A5 /* SQLFormatterTests.swift */; };
5298287C1CB3E258001FE958 /* SQLFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 5298287B1CB3E258001FE958 /* SQLFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; };
529828831CB3E258001FE958 /* SQLFormatter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 529828781CB3E258001FE958 /* SQLFormatter.framework */; };
529828A01CB3E290001FE958 /* QueryFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5298289D1CB3E290001FE958 /* QueryFormatter.swift */; };
Expand All @@ -25,7 +25,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
52547E661CBF7E2A00B42F71 /* SQLFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLFormatterTests.swift; sourceTree = "<group>"; };
525B38401D5AF3C400AE29A5 /* SQLFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLFormatterTests.swift; sourceTree = "<group>"; };
529828781CB3E258001FE958 /* SQLFormatter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SQLFormatter.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5298287B1CB3E258001FE958 /* SQLFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQLFormatter.h; sourceTree = "<group>"; };
5298287D1CB3E258001FE958 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -54,13 +54,13 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
52547E651CBF7E2A00B42F71 /* SQLFormatter */ = {
525B383F1D5AF3C400AE29A5 /* SQLFormatterTests */ = {
isa = PBXGroup;
children = (
52547E661CBF7E2A00B42F71 /* SQLFormatterTests.swift */,
525B38401D5AF3C400AE29A5 /* SQLFormatterTests.swift */,
);
name = SQLFormatter;
path = ../../../Tests/SQLFormatter;
name = SQLFormatterTests;
path = ../../../Tests/SQLFormatterTests;
sourceTree = "<group>";
};
5298286E1CB3E258001FE958 = {
Expand Down Expand Up @@ -94,7 +94,7 @@
529828861CB3E258001FE958 /* SQLFormatterTests */ = {
isa = PBXGroup;
children = (
52547E651CBF7E2A00B42F71 /* SQLFormatter */,
525B383F1D5AF3C400AE29A5 /* SQLFormatterTests */,
529828891CB3E258001FE958 /* Info.plist */,
);
path = SQLFormatterTests;
Expand Down Expand Up @@ -167,7 +167,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Yusuke Ito";
TargetAttributes = {
529828771CB3E258001FE958 = {
Expand Down Expand Up @@ -227,7 +227,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
52547E671CBF7E2A00B42F71 /* SQLFormatterTests.swift in Sources */,
525B38411D5AF3C400AE29A5 /* SQLFormatterTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -285,6 +285,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -325,6 +326,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.11;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -365,6 +367,7 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.novi.SQLFormatter;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand All @@ -387,6 +390,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = jp.novi.SQLFormatterTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -101,8 +101,8 @@ $ brew install mariadb

## Ubuntu Linux

* Install `libmysqlclient`
* Follow [Setting up MariaDB Repositories](https://downloads.mariadb.org/mariadb/repositories/#mirror=yamagata-university) and set up your repository for operating system.
* Install `libmariadbclient`
* Follow [Setting up MariaDB Repositories](https://downloads.mariadb.org/mariadb/repositories/#mirror=yamagata-university) and set up your repository.

```sh
$ sudo apt-get install libmariadbclient-dev
Expand Down
59 changes: 9 additions & 50 deletions Sources/MySQL/Connection.swift
Expand Up @@ -8,6 +8,7 @@

import CMySQL
import CoreFoundation
import Foundation

internal struct MySQLUtil {
internal static func getMySQLError(_ mysqlPtr: UnsafeMutablePointer<MYSQL>?) -> String {
Expand All @@ -31,7 +32,7 @@ public protocol ConnectionOption {
var user: String { get }
var password: String { get }
var database: String { get }
var timeZone: Connection.TimeZone { get }
var timeZone: TimeZone { get }
var encoding: Connection.Encoding { get }
var timeout: Int { get }
var reconnect: Bool { get }
Expand All @@ -40,8 +41,8 @@ public protocol ConnectionOption {

public extension ConnectionOption {
// Provide default options
var timeZone: Connection.TimeZone {
return Connection.TimeZone(GMTOffset: 0)
var timeZone: TimeZone {
return TimeZone(identifier: "UTC")!
}
var encoding: Connection.Encoding {
return .UTF8
Expand All @@ -58,57 +59,15 @@ public extension ConnectionOption {
}

extension Connection {

public final class TimeZone: Equatable, Hashable {
let timeZone: CFTimeZone
public init(name: String) {
#if os(Linux)
let s = name.withCString { p in
CFStringCreateWithCString(nil, p, UInt32(kCFStringEncodingUTF8))
}
#elseif os(OSX)
let s = name.withCString { p in
CFStringCreateWithCString(nil, p, CFStringBuiltInEncodings.UTF8.rawValue)
}
#endif

self.timeZone = CFTimeZoneCreateWithName(nil, s, true)
}
public init(GMTOffset: Int) {
self.timeZone = CFTimeZoneCreateWithTimeIntervalFromGMT(nil, Double(GMTOffset))
}
public var hashValue: Int {
return Int(bitPattern: CFHash(timeZone))
}
}

public enum Encoding: String {
case UTF8 = "utf8"
case UTF8MB4 = "utf8mb4"
}

}

extension Connection.TimeZone: CustomStringConvertible {
public var description: String {
return "\(timeZone)"
}
}

public func ==(lhs: Connection.TimeZone, rhs: Connection.TimeZone) -> Bool {
#if os(Linux)
return CFEqual(lhs.timeZone, rhs.timeZone) ||
CFTimeZoneGetSecondsFromGMT(lhs.timeZone, 0) == CFTimeZoneGetSecondsFromGMT(rhs.timeZone, 0) ||
CFStringCompare(CFTimeZoneGetName(lhs.timeZone), CFTimeZoneGetName(rhs.timeZone), 0) == kCFCompareEqualTo
#elseif os(OSX)
return CFEqual(lhs.timeZone, rhs.timeZone) ||
CFTimeZoneGetSecondsFromGMT(lhs.timeZone, 0) == CFTimeZoneGetSecondsFromGMT(rhs.timeZone, 0) ||
CFStringCompare(CFTimeZoneGetName(lhs.timeZone), CFTimeZoneGetName(rhs.timeZone), []) == .compareEqualTo
#endif
}

extension Connection {
public enum Error: ErrorProtocol {
public enum Error: Swift.Error {
case connectionError(String)
case connectionPoolGetConnectionError
}
Expand Down Expand Up @@ -139,17 +98,17 @@ public final class Connection {
fatalError("mysql_init() failed.")
}

var timeoutPtr = UnsafeMutablePointer<Int>(allocatingCapacity: 1)
var timeoutPtr = UnsafeMutablePointer<Int>.allocate(capacity: 1)
timeoutPtr.pointee = options.timeout
defer {
timeoutPtr.deallocateCapacity(1)
timeoutPtr.deallocate(capacity: 1)
}
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, timeoutPtr)

var reconnectPtr = UnsafeMutablePointer<my_bool>(allocatingCapacity: 1)
var reconnectPtr = UnsafeMutablePointer<my_bool>.allocate(capacity: 1)
reconnectPtr.pointee = options.reconnect == false ? 0 : 1
defer {
reconnectPtr.deallocateCapacity(1)
reconnectPtr.deallocate(capacity: 1)
}

if mysql_real_connect(mysql,
Expand Down
8 changes: 4 additions & 4 deletions Sources/MySQL/ConnectionPool.swift
Expand Up @@ -33,10 +33,10 @@ final public class ConnectionPool: CustomStringConvertible {
public init(options: ConnectionOption) {
self.options = options

if self.dynamicType.libraryInitialized == false && mysql_server_init(0, nil, nil) != 0 { // mysql_library_init
if type(of: self).libraryInitialized == false && mysql_server_init(0, nil, nil) != 0 { // mysql_library_init
fatalError("could not initialize MySQL library")
}
self.dynamicType.libraryInitialized = true
type(of: self).libraryInitialized = true


for _ in 0..<initialConnections {
Expand Down Expand Up @@ -99,12 +99,12 @@ final public class ConnectionPool: CustomStringConvertible {

extension ConnectionPool {

public func execute<T>( _ block: @noescape(conn: Connection) throws -> T ) throws -> T {
public func execute<T>( _ block: @noescape(_ conn: Connection) throws -> T ) throws -> T {
let conn = try getConnection()
defer {
releaseConnection(conn)
}
return try block(conn: conn)
return try block(conn)
}

}

0 comments on commit 714a82b

Please sign in to comment.