Skip to content

Commit ce7c580

Browse files
committed
Update SkipSQLDB with SKIP checks
1 parent 57c8585 commit ce7c580

23 files changed

+201
-112
lines changed

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ let package = Package(
3636
], plugins: [.plugin(name: "skipstone", package: "skip")]),
3737
.target(name: "SkipSQLDB", dependencies: [
3838
"SkipSQL",
39-
], plugins: [/*.plugin(name: "skipstone", package: "skip")*/]),
39+
], plugins: [.plugin(name: "skipstone", package: "skip")]),
4040
.testTarget(name: "SkipSQLDBTests", dependencies: [
4141
"SkipSQLDB",
4242
.product(name: "SkipTest", package: "skip")
43-
], resources: [.process("Resources")], plugins: [/*.plugin(name: "skipstone", package: "skip")*/]),
43+
], resources: [.process("Resources")], plugins: [.plugin(name: "skipstone", package: "skip")]),
4444
.target(name: "SQLExt", dependencies: [
4545
.product(name: "SkipLTC", package: "skip-ltc"),
4646
.product(name: "SkipUnit", package: "skip-unit")

Sources/SkipSQL/SQLiteJLibrary.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal final class SQLiteJNALibrary : SQLiteLibrary {
5151
/* SKIP INSERT: external */ func sqlite3_bind_parameter_name(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr?
5252
/* SKIP INSERT: external */ func sqlite3_bind_parameter_index(_ stmt: OpaquePointer?, _ name: String) -> Int32
5353
/* SKIP INSERT: external */ func sqlite3_clear_bindings(_ stmt: OpaquePointer?) -> Int32
54-
/* SKIP INSERT: external */ func sqlite3_column_name(_ stmt: OpaquePointer?!, _ columnIndex: Int32) -> sqlite3_cstring_ptr?
54+
/* SKIP INSERT: external */ func sqlite3_column_name(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr?
5555
// /* SKIP INSERT: external */ func sqlite3_column_database_name(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr? // unavailable on Android
5656
// /* SKIP INSERT: external */ func sqlite3_column_origin_name(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr?
5757
/* SKIP INSERT: external */ func sqlite3_column_decltype(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr?

Sources/SkipSQLDB/Core/Blob.swift

+2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ public struct Blob {
4444
}
4545
#endif
4646

47+
#if !SKIP // SkipSQLDB TODO
4748
public func toHex() -> String {
4849
bytes.map {
4950
($0 < 16 ? "0" : "") + String($0, radix: 16, uppercase: false)
5051
}.joined(separator: "")
5152
}
53+
#endif
5254
}
5355

5456
extension Blob: CustomStringConvertible {

Sources/SkipSQLDB/Core/Connection.swift

+12-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import Foundation
3333
import Dispatch
3434
import SkipSQL
35+
#if SKIP
36+
import SkipFFI
37+
#endif
3538

3639
/// A connection to SQLite.
3740
public final class Connection {
@@ -104,10 +107,12 @@ public final class Connection {
104107
/// - Returns: A new database connection.
105108
public init(_ location: Location = .inMemory, readonly: Bool = false) throws {
106109
let flags = readonly ? SQLITE_OPEN_READONLY : (SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE)
107-
try check(SQLite3.sqlite3_open_v2(location.description,
108-
&_handle,
109-
flags | SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_URI,
110-
nil))
110+
try check(withUnsafeMutablePointer(to: &_handle) { ptr in
111+
SQLite3.sqlite3_open_v2(location.description,
112+
ptr,
113+
flags | SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_URI,
114+
nil)
115+
})
111116
#if !SKIP // SkipSQLDB TODO
112117
queue.setSpecific(key: Connection.queueKey, value: queueContext)
113118
#endif
@@ -128,7 +133,7 @@ public final class Connection {
128133
///
129134
/// - Returns: A new database connection.
130135
public convenience init(_ filename: String, readonly: Bool = false) throws {
131-
try self.init(.uri(filename), readonly: readonly)
136+
try self.init(Location.uri(filename), readonly: readonly)
132137
}
133138

134139
deinit {
@@ -687,12 +692,13 @@ public final class Connection {
687692
throw error
688693
}
689694

690-
695+
#if !SKIP // SkipSQLDB TODO
691696
fileprivate var queue = DispatchQueue(label: "SQLite.Database", attributes: [])
692697

693698
fileprivate static let queueKey = DispatchSpecificKey<Int>()
694699

695700
fileprivate lazy var queueContext: Int = unsafeBitCast(self, to: Int.self)
701+
#endif
696702

697703
}
698704

Sources/SkipSQLDB/Typed/Expression.swift

+15-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ public protocol ExpressionType: Expressible, CustomStringConvertible { // extens
3636
var template: String { get }
3737
var bindings: [Binding?] { get }
3838

39+
#if !SKIP // SkipSQLDB TODO: Kotlin cannot satisfy a protocol init requirement with a generic constructor
3940
init(_ template: String, _ bindings: [Binding?])
41+
#else
42+
init(_ template: String, _ bindings: [Binding?], _ type: UnderlyingType.self)
43+
#endif
4044

4145
}
4246

@@ -61,11 +65,12 @@ extension ExpressionType {
6165
}
6266
}
6367

68+
69+
#if !SKIP // SkipSQLDB TODO: Kotlin cannot satisfy a protocol init requirement with a generic constructor
70+
6471
@available(*, deprecated, renamed: "SQLExpression")
6572
public typealias Expression<T> = SQLExpression<T>
6673

67-
#if !SKIP // SkipSQLDB TODO
68-
6974
/// An `Expression` represents a raw SQL fragment and any associated bindings.
7075
public struct SQLExpression<Datatype>: ExpressionType {
7176

@@ -74,15 +79,21 @@ public struct SQLExpression<Datatype>: ExpressionType {
7479
public var template: String
7580
public var bindings: [Binding?]
7681

82+
#if !SKIP // SkipSQLDB TODO: Kotlin cannot satisfy a protocol init requirement with a generic constructor
7783
public init(_ template: String, _ bindings: [Binding?]) {
7884
self.template = template
7985
self.bindings = bindings
8086
}
81-
87+
#else
88+
public init(_ template: String, _ bindings: [Binding?], _ type: T.self) {
89+
self.template = template
90+
self.bindings = bindings
91+
}
92+
#endif
8293
}
83-
8494
#endif
8595

96+
8697
public protocol Expressible {
8798

8899
var expression: SQLExpression<Void> { get }

Sources/SkipSQLDB/Typed/Query.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ extension QueryType {
516516
" ".join([
517517
SQLExpression<Void>(literal:
518518
clauses.select.distinct ? "SELECT DISTINCT" : "SELECT"),
519-
", ".join(clauses.select.columns),
519+
", ".join(clauses.select.selectColumns),
520520
SQLExpression<Void>(literal: "FROM"),
521521
tableName(alias: true)
522522
])
@@ -1042,7 +1042,7 @@ extension Connection {
10421042

10431043
private func columnNamesForQuery(_ query: QueryType) throws -> [String: Int] {
10441044
var (columnNames, idx) = ([String: Int](), 0)
1045-
column: for each in query.clauses.select.columns {
1045+
column: for each in query.clauses.select.selectColumns {
10461046
var names = each.expression.template.split { $0 == "." }.map(String.init)
10471047
let column = names.removeLast()
10481048
let namespace = names.joined(separator: ".")
@@ -1285,7 +1285,7 @@ public enum OnConflict: String {
12851285

12861286
public struct QueryClauses {
12871287

1288-
var select = (distinct: false, columns: [SQLExpression<Void>(literal: "*") as Expressible])
1288+
var select = (distinct: false, selectColumns: [SQLExpression<Void>(literal: "*") as Expressible])
12891289

12901290
var from: (name: String, alias: String?, database: String?)
12911291

Sources/SkipSQLPlus/SQLPlusJLibrary.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal final class SQLPlusJNALibrary : SQLiteLibrary {
4141
/* SKIP INSERT: external */ func sqlite3_bind_parameter_name(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr?
4242
/* SKIP INSERT: external */ func sqlite3_bind_parameter_index(_ stmt: OpaquePointer?, _ name: String) -> Int32
4343
/* SKIP INSERT: external */ func sqlite3_clear_bindings(_ stmt: OpaquePointer?) -> Int32
44-
/* SKIP INSERT: external */ func sqlite3_column_name(_ stmt: OpaquePointer?!, _ columnIndex: Int32) -> sqlite3_cstring_ptr?
44+
/* SKIP INSERT: external */ func sqlite3_column_name(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr?
4545
// /* SKIP INSERT: external */ func sqlite3_column_database_name(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr? // unavailable on Android
4646
// /* SKIP INSERT: external */ func sqlite3_column_origin_name(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr?
4747
/* SKIP INSERT: external */ func sqlite3_column_decltype(_ stmt: OpaquePointer?, _ columnIndex: Int32) -> sqlite3_cstring_ptr?

Tests/SkipSQLDBTests/Core/BlobTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ class BlobTests: XCTestCase {
5858
XCTAssertEqual(blob.bytes, [42, 43, 44])
5959
}
6060

61+
#if !SKIP // SkipSQLDB TODO
6162
func test_init_unsafeRawPointer() {
6263
let pointer = UnsafeMutablePointer<UInt8>.allocate(capacity: 3)
6364
pointer.initialize(repeating: 42, count: 3)
6465
let blob = Blob(bytes: pointer, length: 3)
6566
XCTAssertEqual(blob.bytes, [42, 42, 42])
6667
}
68+
#endif
6769

6870
func test_equality() {
6971
let blob1 = Blob(bytes: [42, 42, 42])

Tests/SkipSQLDBTests/Core/ConnectionTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ class ConnectionTests: SQLiteTestCase {
464464
#endif
465465
#endif
466466

467+
#if !SKIP // SkipSQLDB TODO
467468
func test_concurrent_access_single_connection() throws {
468469
// test can fail on iOS/tvOS 9.x: SQLite compile-time differences?
469470
guard #available(iOS 10.0, OSX 10.10, tvOS 10.0, watchOS 2.2, *) else { return }
@@ -484,4 +485,5 @@ class ConnectionTests: SQLiteTestCase {
484485
}
485486
semaphores.forEach { $0.wait() }
486487
}
488+
#endif
487489
}

Tests/SkipSQLDBTests/Core/CoreFunctionsTests.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ class CoreFunctionsTests: XCTestCase {
9494
}
9595

9696
func test_collate_buildsExpressionWithCollateOperator() {
97-
assertSQL("(\"string\" COLLATE BINARY)", string.collate(.binary))
98-
assertSQL("(\"string\" COLLATE NOCASE)", string.collate(.nocase))
99-
assertSQL("(\"string\" COLLATE RTRIM)", string.collate(.rtrim))
100-
assertSQL("(\"string\" COLLATE \"CUSTOM\")", string.collate(.custom("CUSTOM")))
101-
102-
assertSQL("(\"stringOptional\" COLLATE BINARY)", stringOptional.collate(.binary))
103-
assertSQL("(\"stringOptional\" COLLATE NOCASE)", stringOptional.collate(.nocase))
104-
assertSQL("(\"stringOptional\" COLLATE RTRIM)", stringOptional.collate(.rtrim))
105-
assertSQL("(\"stringOptional\" COLLATE \"CUSTOM\")", stringOptional.collate(.custom("CUSTOM")))
97+
assertSQL("(\"string\" COLLATE BINARY)", string.collate(Collation.binary))
98+
assertSQL("(\"string\" COLLATE NOCASE)", string.collate(Collation.nocase))
99+
assertSQL("(\"string\" COLLATE RTRIM)", string.collate(Collation.rtrim))
100+
assertSQL("(\"string\" COLLATE \"CUSTOM\")", string.collate(Collation.custom("CUSTOM")))
101+
102+
assertSQL("(\"stringOptional\" COLLATE BINARY)", stringOptional.collate(Collation.binary))
103+
assertSQL("(\"stringOptional\" COLLATE NOCASE)", stringOptional.collate(Collation.nocase))
104+
assertSQL("(\"stringOptional\" COLLATE RTRIM)", stringOptional.collate(Collation.rtrim))
105+
assertSQL("(\"stringOptional\" COLLATE \"CUSTOM\")", stringOptional.collate(Collation.custom("CUSTOM")))
106106
}
107107

108108
func test_ltrim_wrapsStringWithLtrimFunction() {

Tests/SkipSQLDBTests/Core/ResultTests.swift

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ResultTests: XCTestCase {
5252
XCTAssertNil(Result(errorCode: SQLITE_DONE, connection: connection, statement: nil) as Result?)
5353
}
5454

55+
#if !SKIP // SkipSQLDB TODO
5556
func test_init_with_other_code_returns_error() {
5657
if case .some(.error(let message, let code, let statement)) =
5758
Result(errorCode: SQLITE_MISUSE, connection: connection, statement: nil) {
@@ -63,6 +64,7 @@ class ResultTests: XCTestCase {
6364
XCTFail("no error")
6465
}
6566
}
67+
#endif
6668

6769
func test_description_contains_error_code() {
6870
XCTAssertEqual("not an error (code: 21)",
@@ -75,6 +77,7 @@ class ResultTests: XCTestCase {
7577
Result(errorCode: SQLITE_MISUSE, connection: connection, statement: statement)?.description)
7678
}
7779

80+
#if !SKIP // SkipSQLDB TODO
7881
func test_init_extended_with_other_code_returns_error() {
7982
connection.usesExtendedErrorCodes = true
8083
if case .some(.extendedError(let message, let extendedCode, let statement)) =
@@ -87,4 +90,5 @@ class ResultTests: XCTestCase {
8790
XCTFail("no error")
8891
}
8992
}
93+
#endif
9094
}

Tests/SkipSQLDBTests/Core/StatementTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class StatementTests: SQLiteTestCase {
3838
try createUsersTable()
3939
}
4040

41+
#if !SKIP // SkipSQLDB TODO
4142
func test_cursor_to_blob() throws {
4243
try insertUsers("alice")
4344
let statement = try db.prepare("SELECT email FROM users")
@@ -54,6 +55,7 @@ class StatementTests: SQLiteTestCase {
5455
let blobValue = try db.scalar(blobs.select(blobColumn).limit(1, offset: 0))
5556
XCTAssertEqual([], blobValue.bytes)
5657
}
58+
#endif
5759

5860
func test_prepareRowIterator() throws {
5961
let names = ["a", "b", "c"]

Tests/SkipSQLDBTests/Schema/Connection+SchemaTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class ConnectionSchemaTests: SQLiteTestCase {
6363
XCTAssert(results.isEmpty)
6464
}
6565

66+
#if !SKIP // SkipSQLDB TODO
6667
func test_partial_integrityCheck_table() throws {
6768
guard db.supports(.partialIntegrityCheck) else { return }
6869
let results = try db.integrityCheck(table: "users")
@@ -79,4 +80,5 @@ class ConnectionSchemaTests: SQLiteTestCase {
7980
XCTAssertEqual(message, "no such table: xxx")
8081
}
8182
}
83+
#endif
8284
}

Tests/SkipSQLDBTests/Schema/SchemaChangerTests.swift

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class SchemaChangerTests: SQLiteTestCase {
8989
XCTAssertFalse(columns.contains("age"))
9090
}
9191

92+
#if !SKIP // SkipSQLDB TODO
9293
func test_drop_column_legacy() throws {
9394
schemaChanger = .init(connection: db, version: .init(major: 3, minor: 24)) // DROP COLUMN introduced in 3.35.0
9495

@@ -98,6 +99,7 @@ class SchemaChangerTests: SQLiteTestCase {
9899
let columns = try schema.columnDefinitions(table: "users").map(\.name)
99100
XCTAssertFalse(columns.contains("age"))
100101
}
102+
#endif
101103

102104
func test_rename_column() throws {
103105
try schemaChanger.alter(table: "users") { table in
@@ -109,6 +111,7 @@ class SchemaChangerTests: SQLiteTestCase {
109111
XCTAssertTrue(columns.contains("age2"))
110112
}
111113

114+
#if !SKIP // SkipSQLDB TODO
112115
func test_rename_column_legacy() throws {
113116
schemaChanger = .init(connection: db, version: .init(major: 3, minor: 24)) // RENAME COLUMN introduced in 3.25.0
114117

@@ -137,6 +140,7 @@ class SchemaChangerTests: SQLiteTestCase {
137140

138141
XCTAssertEqual(try db.pluck(users.select(column))?[column], "foo")
139142
}
143+
#endif
140144

141145
func test_add_column_primary_key_fails() throws {
142146
let newColumn = ColumnDefinition(name: "new_column",

Tests/SkipSQLDBTests/Schema/SchemaDefinitionsTests.swift

+8
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ class AffinityTests: XCTestCase {
166166
}
167167
}
168168

169+
#if !SKIP // SkipSQLDB TODO
170+
169171
class IndexDefinitionTests: XCTestCase {
170172
var definition: IndexDefinition!
171173
var expected: String!
@@ -271,6 +273,8 @@ class IndexDefinitionTests: XCTestCase {
271273
}
272274
}
273275

276+
#endif
277+
274278
class ForeignKeyDefinitionTests: XCTestCase {
275279
func test_toSQL() {
276280
XCTAssertEqual(
@@ -349,12 +353,14 @@ class PrimaryKeyTests: XCTestCase {
349353
)
350354
}
351355

356+
#if !SKIP // SkipSQLDB TODO
352357
func test_toSQL_on_conflict() {
353358
XCTAssertEqual(
354359
ColumnDefinition.PrimaryKey(autoIncrement: false, onConflict: .ROLLBACK).toSQL(),
355360
"PRIMARY KEY ON CONFLICT ROLLBACK"
356361
)
357362
}
363+
#endif
358364

359365
func test_fromSQL() {
360366
XCTAssertEqual(
@@ -374,12 +380,14 @@ class PrimaryKeyTests: XCTestCase {
374380
)
375381
}
376382

383+
#if !SKIP // SkipSQLDB TODO
377384
func test_fromSQL_on_conflict() {
378385
XCTAssertEqual(
379386
ColumnDefinition.PrimaryKey(sql: "PRIMARY KEY ON CONFLICT ROLLBACK"),
380387
ColumnDefinition.PrimaryKey(autoIncrement: false, onConflict: .ROLLBACK)
381388
)
382389
}
390+
#endif
383391
}
384392

385393
class LiteralValueTests: XCTestCase {

0 commit comments

Comments
 (0)