Skip to content

Commit

Permalink
Merge pull request #866 from stephencelis/swift-4.2
Browse files Browse the repository at this point in the history
Swift/SQLCipher updates
  • Loading branch information
jberkel authored Dec 19, 2018
2 parents d13baed + cf4183f commit ed8f603
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1
4.2
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: objective-c
rvm: 2.3
osx_image: xcode9.3
# https://docs.travis-ci.com/user/reference/osx
osx_image: xcode10.1
env:
global:
- IOS_SIMULATOR="iPhone 6s"
- IOS_VERSION="11.3"
- IOS_VERSION="12.1"
matrix:
include:
- env: BUILD_SCHEME="SQLite iOS"
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.11.6 (xxx), [diff][diff-0.11.6]
========================================

* Swift 4.2, SQLCipher 4.x ([#866][])

0.11.5 (04-14-2018), [diff][diff-0.11.5]
========================================

Expand Down Expand Up @@ -57,6 +62,7 @@
[diff-0.11.3]: https://github.com/stephencelis/SQLite.swift/compare/0.11.2...0.11.3
[diff-0.11.4]: https://github.com/stephencelis/SQLite.swift/compare/0.11.3...0.11.4
[diff-0.11.5]: https://github.com/stephencelis/SQLite.swift/compare/0.11.4...0.11.5
[diff-0.11.6]: https://github.com/stephencelis/SQLite.swift/compare/0.11.5...0.11.6

[#142]: https://github.com/stephencelis/SQLite.swift/issues/142
[#315]: https://github.com/stephencelis/SQLite.swift/issues/315
Expand Down Expand Up @@ -88,3 +94,4 @@
[#733]: https://github.com/stephencelis/SQLite.swift/pull/733
[#726]: https://github.com/stephencelis/SQLite.swift/pull/726
[#797]: https://github.com/stephencelis/SQLite.swift/pull/797
[#866]: https://github.com/stephencelis/SQLite.swift/pull/866
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BUILD_TOOL = xcodebuild
BUILD_SCHEME = SQLite Mac
IOS_SIMULATOR = iPhone 6s
IOS_VERSION = 11.3
IOS_VERSION = 12.1
ifeq ($(BUILD_SCHEME),SQLite iOS)
BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" -destination "platform=iOS Simulator,name=$(IOS_SIMULATOR),OS=$(IOS_VERSION)"
else
Expand Down
2 changes: 1 addition & 1 deletion SQLite.swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Pod::Spec.new do |s|
s.watchos.deployment_target = "2.2"
s.default_subspec = 'standard'
s.pod_target_xcconfig = {
'SWIFT_VERSION' => '4.1',
'SWIFT_VERSION' => '4.2',
}

s.subspec 'standard' do |ss|
Expand Down
28 changes: 14 additions & 14 deletions SQLite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TVOS_DEPLOYMENT_TARGET = 9.1;
};
name = Debug;
Expand All @@ -1055,7 +1055,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TVOS_DEPLOYMENT_TARGET = 9.1;
};
name = Release;
Expand All @@ -1069,7 +1069,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TVOS_DEPLOYMENT_TARGET = 9.1;
};
name = Debug;
Expand All @@ -1083,7 +1083,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TVOS_DEPLOYMENT_TARGET = 9.1;
};
name = Release;
Expand All @@ -1106,7 +1106,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.2;
};
Expand All @@ -1130,7 +1130,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.2;
};
Expand Down Expand Up @@ -1269,7 +1269,7 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -1291,7 +1291,7 @@
PRODUCT_NAME = SQLite;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -1304,7 +1304,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLiteTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -1317,7 +1317,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLiteTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -1342,7 +1342,7 @@
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -1367,7 +1367,7 @@
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -1383,7 +1383,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -1399,7 +1399,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
5 changes: 5 additions & 0 deletions Sources/SQLite/Extensions/Cipher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import SQLCipher
/// @see [sqlcipher api](https://www.zetetic.net/sqlcipher/sqlcipher-api/)
extension Connection {

/// - Returns: the SQLCipher version
public var cipherVersion: String? {
return (try? scalar("PRAGMA cipher_version")) as? String
}

/// Specify the key for an encrypted database. This routine should be
/// called right after sqlite3_open().
///
Expand Down
3 changes: 1 addition & 2 deletions Sources/SQLiteObjc/include/SQLite-Bridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
//

@import Foundation;

#import "sqlite3.h"
@import SQLite3;

NS_ASSUME_NONNULL_BEGIN
typedef NSString * _Nullable (^_SQLiteTokenizerNextCallback)(const char *input, int *inputOffset, int *inputLength);
Expand Down
2 changes: 1 addition & 1 deletion Tests/CocoaPods/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gem 'cocoapods', '~> 1.5.0'
gem 'cocoapods', '~> 1.6.0beta2'
gem 'minitest'
44 changes: 22 additions & 22 deletions Tests/CocoaPods/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,76 @@ GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.0)
activesupport (4.2.10)
activesupport (4.2.11)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
atomos (0.1.2)
atomos (0.1.3)
claide (1.0.2)
cocoapods (1.5.0)
cocoapods (1.6.0.beta.2)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.5.0)
cocoapods-core (= 1.6.0.beta.2)
cocoapods-deintegrate (>= 1.0.2, < 2.0)
cocoapods-downloader (>= 1.2.0, < 2.0)
cocoapods-downloader (>= 1.2.2, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.3.0, < 2.0)
cocoapods-trunk (>= 1.3.1, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (~> 2.0.1)
gh_inspector (~> 1.0)
molinillo (~> 0.6.5)
molinillo (~> 0.6.6)
nap (~> 1.0)
ruby-macho (~> 1.1)
xcodeproj (>= 1.5.7, < 2.0)
cocoapods-core (1.5.0)
ruby-macho (~> 1.3, >= 1.3.1)
xcodeproj (>= 1.7.0, < 2.0)
cocoapods-core (1.6.0.beta.2)
activesupport (>= 4.0.2, < 6)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.2.0)
cocoapods-downloader (1.2.2)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.3.0)
cocoapods-trunk (1.3.1)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.1.0)
colored2 (3.1.2)
concurrent-ruby (1.0.5)
concurrent-ruby (1.1.4)
escape (0.0.4)
fourflusher (2.0.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
minitest (5.10.1)
molinillo (0.6.5)
nanaimo (0.2.5)
minitest (5.11.3)
molinillo (0.6.6)
nanaimo (0.2.6)
nap (1.1.0)
netrc (0.11.0)
ruby-macho (1.1.0)
ruby-macho (1.3.1)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
xcodeproj (1.5.7)
xcodeproj (1.7.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.2)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.4)
nanaimo (~> 0.2.6)

PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 1.5.0)
cocoapods (~> 1.6.0beta2)
minitest

BUNDLED WITH
1.16.1
1.17.1
2 changes: 1 addition & 1 deletion Tests/CocoaPods/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_pod

def xcodebuild(action, scheme, configuration)
require 'fourflusher'
command = %W(clean #{action} -workspace #{File.join(validation_dir, 'App.xcworkspace')} -scheme #{scheme} -configuration #{configuration})
command = %W(#{action} -workspace #{File.join(validation_dir, 'App.xcworkspace')} -scheme #{scheme} -configuration #{configuration})
case consumer.platform_name
when :osx, :macos
command += %w(CODE_SIGN_IDENTITY=)
Expand Down
10 changes: 8 additions & 2 deletions Tests/SQLiteTests/CipherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ class CipherTests: XCTestCase {
}

func test_open_db_encrypted_with_sqlcipher() {
// $ sqlcipher SQLiteTests/fixtures/encrypted.sqlite
// $ sqlcipher Tests/SQLiteTests/fixtures/encrypted-[version].x.sqlite
// sqlite> pragma key = 'sqlcipher-test';
// sqlite> CREATE TABLE foo (bar TEXT);
// sqlite> INSERT INTO foo (bar) VALUES ('world');
let encryptedFile = fixture("encrypted", withExtension: "sqlite")
guard let cipherVersion:String = db1.cipherVersion,
cipherVersion.starts(with: "3.") || cipherVersion.starts(with: "4.")
else { return }

let encryptedFile = cipherVersion.starts(with: "3.") ?
fixture("encrypted-3.x", withExtension: "sqlite") :
fixture("encrypted-4.x", withExtension: "sqlite")

try! FileManager.default.setAttributes([FileAttributeKey.immutable : 1], ofItemAtPath: encryptedFile)
XCTAssertFalse(FileManager.default.isWritableFile(atPath: encryptedFile))
Expand Down
35 changes: 18 additions & 17 deletions Tests/SQLiteTests/ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,23 @@ class ConnectionTests : SQLiteTestCase {
}

func test_interrupt_interruptsLongRunningQuery() {
try! InsertUsers("abcdefghijklmnopqrstuvwxyz".map { String($0) })
let semaphore = DispatchSemaphore(value: 0)
db.createFunction("sleep") { args in
usleep(UInt32((args[0] as? Double ?? Double(args[0] as? Int64 ?? 1)) * 1_000_000))
DispatchQueue.global(qos: .background).async {
self.db.interrupt()
semaphore.signal()
}
semaphore.wait()
return nil
}

let stmt = try! db.prepare("SELECT *, sleep(?) FROM users", 0.1)
try! stmt.run()

let deadline = DispatchTime.now() + 0.01
_ = DispatchQueue(label: "queue", qos: .background).asyncAfter(deadline: deadline, execute: db.interrupt)
AssertThrows(try stmt.run())
let stmt = try! db.prepare("SELECT sleep()")
XCTAssertThrowsError(try stmt.run()) { error in
if case Result.error(_, let code, _) = error {
XCTAssertEqual(code, SQLITE_INTERRUPT)
} else {
XCTFail("unexpected error: \(error)")
}
}
}

func test_concurrent_access_single_connection() {
Expand All @@ -391,21 +396,17 @@ class ConnectionTests : SQLiteTestCase {
try! conn.execute("DROP TABLE IF EXISTS test; CREATE TABLE test(value);")
try! conn.run("INSERT INTO test(value) VALUES(?)", 0)
let queue = DispatchQueue(label: "Readers", attributes: [.concurrent])

let nReaders = 5
var reads = Array(repeating: 0, count: nReaders)
var finished = false
let semaphores = Array(repeating: DispatchSemaphore(value: 100), count: nReaders)
for index in 0..<nReaders {
queue.async {
while !finished {
while semaphores[index].signal() == 0 {
_ = try! conn.scalar("SELECT value FROM test")
reads[index] += 1
}
}
}
while !finished {
sleep(1)
finished = reads.reduce(true) { $0 && ($1 > 500) }
}
semaphores.forEach { $0.wait() }
}
}

Expand Down
Loading

0 comments on commit ed8f603

Please sign in to comment.