Skip to content

Commit

Permalink
Merge pull request #3 from IBM-DTeam/06-20
Browse files Browse the repository at this point in the history
06-20 Snapshot
  • Loading branch information
GWlodarek authored Jul 20, 2016
2 parents 440a8cb + b39b135 commit 64df9a1
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ matrix:
services: docker
sudo: required
- os: osx
osx_image: xcode7.3
osx_image: xcode8
sudo: required

script:
Expand Down
9 changes: 4 additions & 5 deletions Build/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ install_primary="apt-get install -y clang unixodbc-dev unzip wget tar git sudo"
install_cli="wget https://github.com/IBM-DTeam/swift-for-db2-cli/archive/master.zip && unzip master.zip && cd swift-for-db2-cli-master && sudo ./cli.sh && . env.sh && cd .. && rm -f master.zip && rm -rf swift-for-db2-cli-master"

# Get the needed Swift snapshot
get_swift="wget https://swift.org/builds/development/ubuntu1510/swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a/swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a-ubuntu15.10.tar.gz"
open_swift="tar -xvzf swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a-ubuntu15.10.tar.gz"
get_swift="wget https://swift.org/builds/development/ubuntu1510/swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a/swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a-ubuntu15.10.tar.gz"
open_swift="tar -xvzf swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a-ubuntu15.10.tar.gz"
mkdir_swift="mkdir -p /home/root/swift"
cp_swift="cp -r swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a-ubuntu15.10/* /home/root/swift/"
cp_swift="cp -r swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a-ubuntu15.10/* /home/root/swift/"
export_path="export PATH=/home/root/swift/usr/bin:$PATH"

# DB2 database used for testing
Expand All @@ -45,8 +45,7 @@ export_db="export DB2_CONN_STRING=\"DRIVER={DB2};DATABASE=BLUDB;UID=dash6435;PWD
# Dependencies for the dispatch library
install_secondary="apt-get install -y autoconf libtool pkg-config systemtap-sdt-dev libblocksruntime-dev libkqueue-dev libbsd-dev"
ldispatch="git clone -b experimental/foundation https://github.com/apple/swift-corelibs-libdispatch.git && cd swift-corelibs-libdispatch && git submodule init && git submodule update && sh ./autogen.sh && ./configure --with-swift-toolchain=/home/root/swift/usr --prefix=/home/root/swift/usr && make && make install"

# Build the project and test it
build_and_test="cd /swift-for-db2 && swift build -Xcc -fblocks -Xlinker -ldispatch && swift test"
build_and_test="cd /swift-for-db2 && swift build -Xcc -fblocks -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib && swift test"

docker run -v ${TRAVIS_BUILD_DIR}:/swift-for-db2 -i -t ubuntu:wily /bin/bash -c "${update} && ${install_primary} && ${install_cli} && ${get_swift} && ${open_swift} && ${mkdir_swift} && ${cp_swift} && ${export_path} && ${export_db} && ${install_secondary} && ${ldispatch} && ${build_and_test}"
6 changes: 3 additions & 3 deletions Build/osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ brew install wget unixodbc
wget https://github.com/IBM-DTeam/swift-for-db2-cli/archive/master.zip && unzip master.zip && cd swift-for-db2-cli-master && sudo ./cli.sh && . env.sh && cd .. && rm -f master.zip && rm -rf swift-for-db2-cli-master

# Get the needed Swift snapshot
export SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a
wget https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a/swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a-osx.pkg
sudo installer -pkg swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a-osx.pkg -target /
export SWIFT_VERSION=swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a
wget https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a/swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a-osx.pkg
sudo installer -pkg swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a-osx.pkg -target /
export TOOLCHAINS=swift

# DB2 database used for testing
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The Swift SDK for DB2 allows you to connect to your IBM DB2 database or products
- Query your database asynchronously or synchronously.

## Swift Version
The latest version of the Swift SDK for DB2 works with the DEVELOPMENT-SNAPSHOT-2016-05-09-a version of the Swift binaries. You can download this version of the Swift binaries by following this [link](https://swift.org/download/). Compatibility with other Swift versions is not guaranteed.
The latest version of the Swift SDK for DB2 works with the DEVELOPMENT-SNAPSHOT-2016-06-20-a version of the Swift binaries. You can download this version of the Swift binaries by following this [link](https://swift.org/download/). Compatibility with other Swift versions is not guaranteed.

## Installation (OS X)

Expand Down Expand Up @@ -107,7 +107,7 @@ let package = Package(

### Linux
```
swift build -Xcc -fblocks -Xlinker -ldispatch
swift build -Xcc -fblocks -Xcc -I/usr/local/include -Xlinker -L/usr/local/lib
```

3.Wait until the build finishes, then run the project
Expand Down
39 changes: 34 additions & 5 deletions Sources/IBMDB/SwiftDB2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public class IBMDB {

var conn: UnsafeMutablePointer<ODBC>!

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {

func run() -> Void {
// Try to connect to the database.
conn = info.withCString { cString in
db_connect(conn, UnsafeMutablePointer(cString))
Expand Down Expand Up @@ -78,9 +77,18 @@ public class IBMDB {
db_disconnect(conn)
callback(error: error_arr, connection: nil)
}
}


#if os(Linux)
dispatch_async(dispatch_get_global_queue(Int(DISPATCH_QUEUE_PRIORITY_HIGH), 0), {
run()
})
#else
DispatchQueue.main.async {
run()
}
#endif


}

Expand Down Expand Up @@ -167,7 +175,8 @@ public class Connection {
* Executes the callback upon completion.
*/
public func query(query:String, callback: (result: [[NSDictionary]], error: [DBError]?) -> Void) -> Void {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {

func run() -> Void {
var data = [[NSDictionary]]()

var response = self.data_fetch(query: query, data: &data)
Expand All @@ -182,7 +191,17 @@ public class Connection {
callback(result: data, error: nil)
}
}
}

#if os(Linux)
dispatch_async(dispatch_get_global_queue(Int(DISPATCH_QUEUE_PRIORITY_HIGH), 0), {
run()
})
#else
DispatchQueue.main.async {
run()
}
#endif
}


Expand Down Expand Up @@ -316,13 +335,23 @@ public class Connection {
* Disconnect asynchronously from the database associated with this Connection object.
*/
public func disconnect(callback: () -> Void) -> Void {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
func run() -> Void {
if self.conn != nil {
db_disconnect(self.conn)
self.conn = nil
}
callback()
}

#if os(Linux)
dispatch_async(dispatch_get_global_queue(Int(DISPATCH_QUEUE_PRIORITY_HIGH), 0), {
run()
})
#else
DispatchQueue.main.async {
run()
}
#endif
}


Expand Down
Empty file modified Sources/IBMDBLinkerDarwin/empty.c
100644 → 100755
Empty file.
Empty file modified Sources/IBMDBLinkerDarwin/include/module.modulemap
100644 → 100755
Empty file.
Empty file modified Tests/IBMDB/ConnectSyncTests.swift
100644 → 100755
Empty file.
Empty file modified Tests/IBMDB/ConnectTests.swift
100644 → 100755
Empty file.
Empty file modified Tests/IBMDB/DisconnectSyncTests.swift
100644 → 100755
Empty file.
Empty file modified Tests/IBMDB/DisconnectTests.swift
100644 → 100755
Empty file.
56 changes: 55 additions & 1 deletion Tests/IBMDB/QuerySyncTests.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ extension String {
var randomString: String = ""

for _ in 0..<length {
#if os(Linux)
let randomValue = random() % base.characters.count
#else
let randomValue = Int(arc4random_uniform(UInt32(base.characters.count)))
#endif

var current = 0
for character in base.characters {
Expand Down Expand Up @@ -75,7 +79,7 @@ class QuerySyncTests : XCTestCase {
#if os(Linux)
private static var tableName = "DB2_TEST_TABLE_LINUX_" + String.getRandom(length: 1 + Int(random() % (100)))
#else
private static var tableName = "DB2_TEST_TABLE_DARWIN_" + String.getRandom(length: 1 + Int(random() % (100)))
private static var tableName = "DB2_TEST_TABLE_DARWIN_" + String.getRandom(length: 1 + Int(arc4random_uniform(100)))
#endif

override func setUp() {
Expand Down Expand Up @@ -139,7 +143,11 @@ class QuerySyncTests : XCTestCase {

let conn = info.connection

#if os(Linux)
let id = 1 + Int(random() % (1101))
#else
let id = 1 + Int(arc4random_uniform(1101))
#endif
let query = "SELECT * FROM \(QuerySyncTests.tableName) WHERE ID=\(id)"

let response = conn!.querySync(query: query)
Expand Down Expand Up @@ -173,7 +181,13 @@ class QuerySyncTests : XCTestCase {
let conn = info.connection

for _ in 1...100 {

#if os(Linux)
let id = 1 + Int(random() % (1101))
#else
let id = 1 + Int(arc4random_uniform(1101))
#endif

let query = "SELECT * FROM \(QuerySyncTests.tableName) WHERE ID=\(id)"

let response = conn!.querySync(query: query)
Expand Down Expand Up @@ -209,7 +223,13 @@ class QuerySyncTests : XCTestCase {
let conn = info.connection

for _ in 1...1000 {

#if os(Linux)
let id = 1 + Int(random() % (1101))
#else
let id = 1 + Int(arc4random_uniform(1101))
#endif

let query = "SELECT * FROM \(QuerySyncTests.tableName) WHERE ID=\(id)"

let response = conn!.querySync(query: query)
Expand Down Expand Up @@ -339,7 +359,12 @@ class QuerySyncTests : XCTestCase {

let conn = info.connection

#if os(Linux)
let randomString = String.getRandom(length: 1 + Int(random() % (256)))
#else
let randomString = String.getRandom(length: 1 + Int(arc4random_uniform(256)))
#endif

let query = "UPDATE \(QuerySyncTests.tableName) SET TEXT='\(randomString)' WHERE ID=1"

let response = conn!.querySync(query: query)
Expand Down Expand Up @@ -371,7 +396,13 @@ class QuerySyncTests : XCTestCase {
let conn = info.connection

for id in 2...101 {

#if os(Linux)
let randomString = String.getRandom(length: 1 + Int(random() % (256)))
#else
let randomString = String.getRandom(length: 1 + Int(arc4random_uniform(256)))
#endif

let query = "UPDATE \(QuerySyncTests.tableName) SET TEXT='\(randomString)' WHERE ID=\(id)"

let response = conn!.querySync(query: query)
Expand Down Expand Up @@ -405,7 +436,13 @@ class QuerySyncTests : XCTestCase {
let conn = info.connection

for id in 102...1101 {

#if os(Linux)
let randomString = String.getRandom(length: 1 + Int(random() % (256)))
#else
let randomString = String.getRandom(length: 1 + Int(arc4random_uniform(256)))
#endif

let query = "UPDATE \(QuerySyncTests.tableName) SET TEXT='\(randomString)' WHERE ID=\(id)"

let response = conn!.querySync(query: query)
Expand Down Expand Up @@ -437,7 +474,12 @@ class QuerySyncTests : XCTestCase {

let conn = info.connection

#if os(Linux)
let randomString = String.getRandom(length: 1 + Int(random() % (256)))
#else
let randomString = String.getRandom(length: 1 + Int(arc4random_uniform(256)))
#endif

let query = "INSERT INTO \(QuerySyncTests.tableName) (ID, TEXT) VALUES (1, '\(randomString)')"

let response = conn!.querySync(query: query)
Expand Down Expand Up @@ -470,7 +512,13 @@ class QuerySyncTests : XCTestCase {
let conn = info.connection

for id in 2...101 {

#if os(Linux)
let randomString = String.getRandom(length: 1 + Int(random() % (256)))
#else
let randomString = String.getRandom(length: 1 + Int(arc4random_uniform(256)))
#endif

let query = "INSERT INTO \(QuerySyncTests.tableName) (ID, TEXT) VALUES (\(id), '\(randomString)')"

let response = conn!.querySync(query: query)
Expand Down Expand Up @@ -504,7 +552,13 @@ class QuerySyncTests : XCTestCase {
let conn = info.connection

for id in 102...1101 {

#if os(Linux)
let randomString = String.getRandom(length: 1 + Int(random() % (256)))
#else
let randomString = String.getRandom(length: 1 + Int(arc4random_uniform(256)))
#endif

let query = "INSERT INTO " + QuerySyncTests.tableName + " (ID, TEXT) VALUES (\(id), '\(randomString)')"

let response = conn!.querySync(query: query)
Expand Down
Loading

0 comments on commit 64df9a1

Please sign in to comment.