Skip to content

Commit 879dfab

Browse files
committed
兼容 swift 5
1 parent 67a7f8a commit 879dfab

File tree

12 files changed

+224
-40
lines changed

12 files changed

+224
-40
lines changed

CHANGELOG.md

100644100755
File mode changed.

CONTRIBUTING.md

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Made it through everything above and still having trouble? Sorry!
7474
- Even better: link to a sample project exhibiting the issue.
7575
- Include the SQLite.swift commit or branch experiencing the issue.
7676
- Include devices and operating systems affected.
77-
- Include build information: the Xcode and OS X versions affected.
77+
- Include build information: the Xcode and macOS versions affected.
7878

7979
[installation instructions]: Documentation/Index.md#installation
8080
[See Documentation]: Documentation/Index.md#sqliteswift-documentation

Documentation/Index.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767

6868
## Installation
6969

70-
> _Note:_ SQLite.swift requires Swift 4.1 (and
71-
> [Xcode 9.3](https://developer.apple.com/xcode/downloads/)) or greater.
70+
> _Note:_ SQLite.swift requires Swift 5 (and
71+
> [Xcode 10.2](https://developer.apple.com/xcode/downloads/)) or greater.
7272
7373

7474
### Carthage
@@ -80,7 +80,7 @@ install SQLite.swift with Carthage:
8080
2. Update your Cartfile to include the following:
8181

8282
```ruby
83-
github "stephencelis/SQLite.swift" ~> 0.11.5
83+
github "stephencelis/SQLite.swift" ~> 0.12.0
8484
```
8585

8686
3. Run `carthage update` and [add the appropriate framework][Carthage Usage].
@@ -96,7 +96,7 @@ install SQLite.swift with Carthage:
9696
[CocoaPods][] is a dependency manager for Cocoa projects. To install SQLite.swift with CocoaPods:
9797

9898
1. Make sure CocoaPods is [installed][CocoaPods Installation] (SQLite.swift
99-
requires version 1.0.0 or greater).
99+
requires version 1.6.1 or greater).
100100

101101
```sh
102102
# Using the default Ruby install will require you to use sudo when
@@ -110,7 +110,7 @@ install SQLite.swift with Carthage:
110110
use_frameworks!
111111
112112
target 'YourAppTargetName' do
113-
pod 'SQLite.swift', '~> 0.11.5'
113+
pod 'SQLite.swift', '~> 0.12.0'
114114
end
115115
```
116116

@@ -124,7 +124,7 @@ with the OS you can require the `standalone` subspec:
124124

125125
```ruby
126126
target 'YourAppTargetName' do
127-
pod 'SQLite.swift/standalone', '~> 0.11.5'
127+
pod 'SQLite.swift/standalone', '~> 0.12.0'
128128
end
129129
```
130130

@@ -134,7 +134,7 @@ dependency to sqlite3 or one of its subspecs:
134134

135135
```ruby
136136
target 'YourAppTargetName' do
137-
pod 'SQLite.swift/standalone', '~> 0.11.5'
137+
pod 'SQLite.swift/standalone', '~> 0.12.0'
138138
pod 'sqlite3/fts5', '= 3.15.0' # SQLite 3.15.0 with FTS5 enabled
139139
end
140140
```
@@ -148,7 +148,7 @@ If you want to use [SQLCipher][] with SQLite.swift you can require the
148148

149149
```ruby
150150
target 'YourAppTargetName' do
151-
pod 'SQLite.swift/SQLCipher', '~> 0.11.5'
151+
pod 'SQLite.swift/SQLCipher', '~> 0.12.0'
152152
end
153153
```
154154

@@ -181,7 +181,7 @@ applications.
181181

182182
```swift
183183
dependencies: [
184-
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.11.5")
184+
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.12.0")
185185
]
186186
```
187187

@@ -258,7 +258,7 @@ let path = NSSearchPathForDirectoriesInDomains(
258258
let db = try Connection("\(path)/db.sqlite3")
259259
```
260260

261-
On OS X, you can use your app’s **Application Support** directory:
261+
On macOS, you can use your app’s **Application Support** directory:
262262

263263
```swift
264264
var path = NSSearchPathForDirectoriesInDomains(
@@ -1209,7 +1209,7 @@ We can build an `ALTER TABLE … RENAME TO` statement by calling the `rename`
12091209
function on a `Table` or `VirtualTable`.
12101210

12111211
```swift
1212-
try db.run(users.rename(Table("users_old"))
1212+
try db.run(users.rename(Table("users_old")))
12131213
// ALTER TABLE "users" RENAME TO "users_old"
12141214
```
12151215

@@ -1557,7 +1557,7 @@ Both of the above methods also have the following optional parameter:
15571557
There are a few restrictions on using Codable types:
15581558

15591559
- The encodable and decodable objects can only use the following types:
1560-
- Int, Bool, Float, Double, String, Date
1560+
- Int, Bool, Float, Double, String
15611561
- Nested Codable types that will be encoded as JSON to a single column
15621562
- These methods will not handle object relationships for you. You must write
15631563
your own Codable and Decodable implementations if you wish to support this.

LICENSE.txt

100644100755
File mode changed.

Makefile

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
BUILD_TOOL = xcodebuild
22
BUILD_SCHEME = SQLite Mac
3-
IOS_SIMULATOR = iPhone 6s
4-
IOS_VERSION = 12.1
3+
IOS_SIMULATOR = iPhone XS
4+
IOS_VERSION = 12.2
55
ifeq ($(BUILD_SCHEME),SQLite iOS)
66
BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" -destination "platform=iOS Simulator,name=$(IOS_SIMULATOR),OS=$(IOS_VERSION)"
77
else

Package.swift

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let package = Package(
99
.target(name: "SQLiteObjc"),
1010
.testTarget(name: "SQLiteTests", dependencies: ["SQLite"], path: "Tests/SQLiteTests")
1111
],
12-
swiftLanguageVersions: [4]
12+
swiftLanguageVersions: [4, 5]
1313
)
1414

1515
#if os(Linux)

README.md

100644100755
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SQLite.swift
22

3-
[![Build Status][TravisBadge]][TravisLink] [![CocoaPods Version][CocoaPodsVersionBadge]][CocoaPodsVersionLink] [![Swift4 compatible][Swift4Badge]][Swift4Link] [![Platform][PlatformBadge]][PlatformLink] [![Carthage compatible][CartagheBadge]][CarthageLink] [![Join the chat at https://gitter.im/stephencelis/SQLite.swift][GitterBadge]][GitterLink]
3+
[![Build Status][TravisBadge]][TravisLink] [![CocoaPods Version][CocoaPodsVersionBadge]][CocoaPodsVersionLink] [![Swift5 compatible][Swift5Badge]][Swift5Link] [![Platform][PlatformBadge]][PlatformLink] [![Carthage compatible][CartagheBadge]][CarthageLink] [![Join the chat at https://gitter.im/stephencelis/SQLite.swift][GitterBadge]][GitterLink]
44

55
A type-safe, [Swift][]-language layer over [SQLite3][].
66

@@ -112,7 +112,7 @@ and the [companion repository][SQLiteDataAccessLayer2].
112112

113113
## Installation
114114

115-
> _Note:_ SQLite.swift requires Swift 4.1 (and [Xcode][] 9.3).
115+
> _Note:_ Version 0.12 requires Swift 5 (and [Xcode](https://developer.apple.com/xcode/downloads/) 10.2) or greater. Version 0.11.6 requires Swift 4.2 (and [Xcode](https://developer.apple.com/xcode/downloads/) 10.1) or greater.
116116
117117
### Carthage
118118

@@ -124,7 +124,7 @@ install SQLite.swift with Carthage:
124124
2. Update your Cartfile to include the following:
125125

126126
```ruby
127-
github "stephencelis/SQLite.swift" ~> 0.11.5
127+
github "stephencelis/SQLite.swift" ~> 0.12.0
128128
```
129129

130130
3. Run `carthage update` and
@@ -142,7 +142,7 @@ install SQLite.swift with Carthage:
142142
SQLite.swift with CocoaPods:
143143

144144
1. Make sure CocoaPods is [installed][CocoaPods Installation]. (SQLite.swift
145-
requires version 1.0.0 or greater.)
145+
requires version 1.6.1 or greater.)
146146

147147
```sh
148148
# Using the default Ruby install will require you to use sudo when
@@ -156,7 +156,7 @@ SQLite.swift with CocoaPods:
156156
use_frameworks!
157157
158158
target 'YourAppTargetName' do
159-
pod 'SQLite.swift', '~> 0.11.5'
159+
pod 'SQLite.swift', '~> 0.12.0'
160160
end
161161
```
162162

@@ -174,7 +174,7 @@ Swift code.
174174

175175
```swift
176176
dependencies: [
177-
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.11.5")
177+
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.12.0")
178178
]
179179
```
180180

@@ -285,8 +285,8 @@ Looking for something else? Try another Swift wrapper (or [FMDB][]):
285285
[GitterBadge]: https://badges.gitter.im/stephencelis/SQLite.swift.svg
286286
[GitterLink]: https://gitter.im/stephencelis/SQLite.swift
287287

288-
[Swift4Badge]: https://img.shields.io/badge/swift-4.1-orange.svg?style=flat
289-
[Swift4Link]: https://developer.apple.com/swift/
288+
[Swift5Badge]: https://img.shields.io/badge/swift-5-orange.svg?style=flat
289+
[Swift5Link]: https://developer.apple.com/swift/
290290

291291
[SQLiteMigrationManager.swift]: https://github.com/garriguv/SQLiteMigrationManager.swift
292292
[FMDB]: https://github.com/ccgus/fmdb

SQLite.swift.podspec

100644100755
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "SQLite.swift"
3-
s.version = "0.11.5"
4-
s.summary = "A type-safe, Swift-language layer over SQLite3 for iOS and OS X."
3+
s.version = "0.12.2"
4+
s.summary = "A type-safe, Swift-language layer over SQLite3 for iOS and macOS."
55

66
s.description = <<-DESC
77
SQLite.swift provides compile-time confidence in SQL statement syntax and
@@ -15,14 +15,19 @@ Pod::Spec.new do |s|
1515
s.social_media_url = 'https://twitter.com/stephencelis'
1616

1717
s.module_name = 'SQLite'
18-
s.ios.deployment_target = "8.0"
19-
s.tvos.deployment_target = "9.1"
20-
s.osx.deployment_target = "10.10"
21-
s.watchos.deployment_target = "2.2"
2218
s.default_subspec = 'standard'
23-
s.pod_target_xcconfig = {
24-
'SWIFT_VERSION' => '4.2',
25-
}
19+
s.swift_versions = ['4.2', '5']
20+
21+
22+
ios_deployment_target = '8.0'
23+
tvos_deployment_target = '9.1'
24+
osx_deployment_target = '10.10'
25+
watchos_deployment_target = '2.2'
26+
27+
s.ios.deployment_target = ios_deployment_target
28+
s.tvos.deployment_target = tvos_deployment_target
29+
s.osx.deployment_target = osx_deployment_target
30+
s.watchos.deployment_target = watchos_deployment_target
2631

2732
s.subspec 'standard' do |ss|
2833
ss.source_files = 'Sources/{SQLite,SQLiteObjc}/**/*.{c,h,m,swift}'
@@ -33,6 +38,9 @@ Pod::Spec.new do |s|
3338
ss.test_spec 'tests' do |test_spec|
3439
test_spec.resources = 'Tests/SQLiteTests/fixtures/*'
3540
test_spec.source_files = 'Tests/SQLiteTests/*.swift'
41+
test_spec.ios.deployment_target = ios_deployment_target
42+
test_spec.tvos.deployment_target = tvos_deployment_target
43+
test_spec.osx.deployment_target = osx_deployment_target
3644
end
3745
end
3846

@@ -49,6 +57,9 @@ Pod::Spec.new do |s|
4957
ss.test_spec 'tests' do |test_spec|
5058
test_spec.resources = 'Tests/SQLiteTests/fixtures/*'
5159
test_spec.source_files = 'Tests/SQLiteTests/*.swift'
60+
test_spec.ios.deployment_target = ios_deployment_target
61+
test_spec.tvos.deployment_target = tvos_deployment_target
62+
test_spec.osx.deployment_target = osx_deployment_target
5263
end
5364
end
5465

@@ -64,6 +75,9 @@ Pod::Spec.new do |s|
6475
ss.test_spec 'tests' do |test_spec|
6576
test_spec.resources = 'Tests/SQLiteTests/fixtures/*'
6677
test_spec.source_files = 'Tests/SQLiteTests/*.swift'
78+
test_spec.ios.deployment_target = ios_deployment_target
79+
test_spec.tvos.deployment_target = tvos_deployment_target
80+
test_spec.osx.deployment_target = osx_deployment_target
6781
end
6882
end
6983
end

Sources/SQLiteObjc/SQLiteObjc.m

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//
2+
// SQLite.swift
3+
// https://github.com/stephencelis/SQLite.swift
4+
// Copyright © 2014-2015 Stephen Celis.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
//
24+
25+
#import "SQLiteObjc.h"
26+
#import "fts3_tokenizer.h"
27+
28+
#pragma mark - FTS
29+
30+
typedef struct __SQLiteTokenizer {
31+
sqlite3_tokenizer base;
32+
__unsafe_unretained _SQLiteTokenizerNextCallback callback;
33+
} __SQLiteTokenizer;
34+
35+
typedef struct __SQLiteTokenizerCursor {
36+
void * base;
37+
const char * input;
38+
int inputOffset;
39+
int inputLength;
40+
int idx;
41+
} __SQLiteTokenizerCursor;
42+
43+
static NSMutableDictionary * __SQLiteTokenizerMap;
44+
45+
static int __SQLiteTokenizerCreate(int argc, const char * const * argv, sqlite3_tokenizer ** ppTokenizer) {
46+
__SQLiteTokenizer * tokenizer = (__SQLiteTokenizer *)sqlite3_malloc(sizeof(__SQLiteTokenizer));
47+
if (!tokenizer) {
48+
return SQLITE_NOMEM;
49+
}
50+
memset(tokenizer, 0, sizeof(* tokenizer));
51+
52+
NSString * key = [NSString stringWithUTF8String:argv[0]];
53+
tokenizer->callback = [__SQLiteTokenizerMap objectForKey:key];
54+
if (!tokenizer->callback) {
55+
return SQLITE_ERROR;
56+
}
57+
58+
*ppTokenizer = &tokenizer->base;
59+
return SQLITE_OK;
60+
}
61+
62+
static int __SQLiteTokenizerDestroy(sqlite3_tokenizer * pTokenizer) {
63+
sqlite3_free(pTokenizer);
64+
return SQLITE_OK;
65+
}
66+
67+
static int __SQLiteTokenizerOpen(sqlite3_tokenizer * pTokenizer, const char * pInput, int nBytes, sqlite3_tokenizer_cursor ** ppCursor) {
68+
__SQLiteTokenizerCursor * cursor = (__SQLiteTokenizerCursor *)sqlite3_malloc(sizeof(__SQLiteTokenizerCursor));
69+
if (!cursor) {
70+
return SQLITE_NOMEM;
71+
}
72+
73+
cursor->input = pInput;
74+
cursor->inputOffset = 0;
75+
cursor->inputLength = 0;
76+
cursor->idx = 0;
77+
78+
*ppCursor = (sqlite3_tokenizer_cursor *)cursor;
79+
return SQLITE_OK;
80+
}
81+
82+
static int __SQLiteTokenizerClose(sqlite3_tokenizer_cursor * pCursor) {
83+
sqlite3_free(pCursor);
84+
return SQLITE_OK;
85+
}
86+
87+
static int __SQLiteTokenizerNext(sqlite3_tokenizer_cursor * pCursor, const char ** ppToken, int * pnBytes, int * piStartOffset, int * piEndOffset, int * piPosition) {
88+
__SQLiteTokenizerCursor * cursor = (__SQLiteTokenizerCursor *)pCursor;
89+
__SQLiteTokenizer * tokenizer = (__SQLiteTokenizer *)cursor->base;
90+
91+
cursor->inputOffset += cursor->inputLength;
92+
const char * input = cursor->input + cursor->inputOffset;
93+
const char * token = [tokenizer->callback(input, &cursor->inputOffset, &cursor->inputLength) cStringUsingEncoding:NSUTF8StringEncoding];
94+
if (!token) {
95+
return SQLITE_DONE;
96+
}
97+
98+
*ppToken = token;
99+
*pnBytes = (int)strlen(token);
100+
*piStartOffset = cursor->inputOffset;
101+
*piEndOffset = cursor->inputOffset + cursor->inputLength;
102+
*piPosition = cursor->idx++;
103+
return SQLITE_OK;
104+
}
105+
106+
static const sqlite3_tokenizer_module __SQLiteTokenizerModule = {
107+
0,
108+
__SQLiteTokenizerCreate,
109+
__SQLiteTokenizerDestroy,
110+
__SQLiteTokenizerOpen,
111+
__SQLiteTokenizerClose,
112+
__SQLiteTokenizerNext
113+
};
114+
115+
int _SQLiteRegisterTokenizer(sqlite3 *db, const char * moduleName, const char * submoduleName, _SQLiteTokenizerNextCallback callback) {
116+
static dispatch_once_t onceToken;
117+
dispatch_once(&onceToken, ^{
118+
__SQLiteTokenizerMap = [NSMutableDictionary new];
119+
});
120+
121+
sqlite3_stmt * stmt;
122+
int status = sqlite3_prepare_v2(db, "SELECT fts3_tokenizer(?, ?)", -1, &stmt, 0);
123+
if (status != SQLITE_OK ){
124+
return status;
125+
}
126+
const sqlite3_tokenizer_module * pModule = &__SQLiteTokenizerModule;
127+
sqlite3_bind_text(stmt, 1, moduleName, -1, SQLITE_STATIC);
128+
sqlite3_bind_blob(stmt, 2, &pModule, sizeof(pModule), SQLITE_STATIC);
129+
sqlite3_step(stmt);
130+
status = sqlite3_finalize(stmt);
131+
if (status != SQLITE_OK ){
132+
return status;
133+
}
134+
135+
[__SQLiteTokenizerMap setObject:[callback copy] forKey:[NSString stringWithUTF8String:submoduleName]];
136+
137+
return SQLITE_OK;
138+
}

0 commit comments

Comments
 (0)