mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Xcode 8 WIP
This commit is contained in:
1 parent
d52c552721
commit
f45b9a3757
33 files changed
+505
-495
No files matched your search
@@ -188,7 +188,7 @@ extension PersonsViewController {
|
||||
setEditing(false, animated: true)
|
||||
|
||||
for _ in 0..<1000 {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
|
||||
DispatchQueue.global(attributes: [.qosDefault]).async {
|
||||
try! dbQueue.inTransaction { db in
|
||||
if Person.fetchCount(db) == 0 {
|
||||
// Insert persons
|
||||
|
||||
@@ -174,10 +174,10 @@
|
||||
560FC59B1CB00B880014AA8E /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */; };
|
||||
560FC59C1CB00B880014AA8E /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; };
|
||||
560FC59D1CB00B880014AA8E /* TableMapping+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6A1C53D3E8005A543B /* TableMapping+QueryInterfaceRequestTests.swift */; };
|
||||
560FC59E1CB00B880014AA8E /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
560FC59E1CB00B880014AA8E /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DateTests.swift */; };
|
||||
560FC59F1CB00B880014AA8E /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238131B9C74A90082EB20 /* DatabaseTests.swift */; };
|
||||
560FC5A01CB00B880014AA8E /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */; };
|
||||
560FC5A11CB00B880014AA8E /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
560FC5A11CB00B880014AA8E /* DateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */; };
|
||||
560FC5A21CB00B880014AA8E /* FunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560C97C61BFD0B8400BF8471 /* FunctionTests.swift */; };
|
||||
560FC5A41CB00B880014AA8E /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */; };
|
||||
560FC5A51CB00B880014AA8E /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; };
|
||||
@@ -323,10 +323,10 @@
|
||||
567156591CB16729007DC145 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */; };
|
||||
5671565A1CB16729007DC145 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; };
|
||||
5671565B1CB16729007DC145 /* TableMapping+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6A1C53D3E8005A543B /* TableMapping+QueryInterfaceRequestTests.swift */; };
|
||||
5671565C1CB16729007DC145 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
5671565C1CB16729007DC145 /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DateTests.swift */; };
|
||||
5671565D1CB16729007DC145 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238131B9C74A90082EB20 /* DatabaseTests.swift */; };
|
||||
5671565E1CB16729007DC145 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */; };
|
||||
5671565F1CB16729007DC145 /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
5671565F1CB16729007DC145 /* DateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */; };
|
||||
567156601CB16729007DC145 /* FunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560C97C61BFD0B8400BF8471 /* FunctionTests.swift */; };
|
||||
567156611CB16729007DC145 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */; };
|
||||
567156621CB16729007DC145 /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; };
|
||||
@@ -579,10 +579,10 @@
|
||||
56AFCA6B1CB1AA9900F48B96 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */; };
|
||||
56AFCA6C1CB1AA9900F48B96 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; };
|
||||
56AFCA6D1CB1AA9900F48B96 /* TableMapping+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6A1C53D3E8005A543B /* TableMapping+QueryInterfaceRequestTests.swift */; };
|
||||
56AFCA6E1CB1AA9900F48B96 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
56AFCA6E1CB1AA9900F48B96 /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DateTests.swift */; };
|
||||
56AFCA6F1CB1AA9900F48B96 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238131B9C74A90082EB20 /* DatabaseTests.swift */; };
|
||||
56AFCA701CB1AA9900F48B96 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */; };
|
||||
56AFCA711CB1AA9900F48B96 /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
56AFCA711CB1AA9900F48B96 /* DateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */; };
|
||||
56AFCA721CB1AA9900F48B96 /* FunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560C97C61BFD0B8400BF8471 /* FunctionTests.swift */; };
|
||||
56AFCA731CB1AA9900F48B96 /* InMemoryDatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238141B9C74A90082EB20 /* InMemoryDatabaseTests.swift */; };
|
||||
56AFCA741CB1AA9900F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */; };
|
||||
@@ -648,10 +648,10 @@
|
||||
56AFCAC41CB1ABC800F48B96 /* DatabaseTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238B51B9CA2590082EB20 /* DatabaseTimestampTests.swift */; };
|
||||
56AFCAC51CB1ABC800F48B96 /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; };
|
||||
56AFCAC61CB1ABC800F48B96 /* TableMapping+QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B6A1C53D3E8005A543B /* TableMapping+QueryInterfaceRequestTests.swift */; };
|
||||
56AFCAC71CB1ABC800F48B96 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
56AFCAC71CB1ABC800F48B96 /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DateTests.swift */; };
|
||||
56AFCAC81CB1ABC800F48B96 /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238131B9C74A90082EB20 /* DatabaseTests.swift */; };
|
||||
56AFCAC91CB1ABC800F48B96 /* QueryInterfaceRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56300B5D1C53C38F005A543B /* QueryInterfaceRequestTests.swift */; };
|
||||
56AFCACA1CB1ABC800F48B96 /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
56AFCACA1CB1ABC800F48B96 /* DateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */; };
|
||||
56AFCACB1CB1ABC800F48B96 /* FunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560C97C61BFD0B8400BF8471 /* FunctionTests.swift */; };
|
||||
56AFCACC1CB1ABC800F48B96 /* InMemoryDatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238141B9C74A90082EB20 /* InMemoryDatabaseTests.swift */; };
|
||||
56AFCACD1CB1ABC800F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */; };
|
||||
@@ -710,10 +710,10 @@
|
||||
56EB0AB31BCD787300A3DC55 /* DataMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */; };
|
||||
56EE573D1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EE573C1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift */; };
|
||||
56EE573E1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56EE573C1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift */; };
|
||||
56F0B98F1B6001C600A2F135 /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
56F0B9901B6001C600A2F135 /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
56F0B9911B6001C600A2F135 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
56F0B9921B6001C600A2F135 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
56F0B98F1B6001C600A2F135 /* DateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */; };
|
||||
56F0B9901B6001C600A2F135 /* DateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */; };
|
||||
56F0B9911B6001C600A2F135 /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DateTests.swift */; };
|
||||
56F0B9921B6001C600A2F135 /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DateTests.swift */; };
|
||||
56F26C1C1CEE3F32007969C4 /* AdapterRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* AdapterRowTests.swift */; };
|
||||
56F26C241CEE3F34007969C4 /* AdapterRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F03C11CE5D3AA00DE108F /* AdapterRowTests.swift */; };
|
||||
56FC78661BBAEB8C00CA1285 /* MappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FC78641BBAEB8C00CA1285 /* MappingTests.swift */; };
|
||||
@@ -975,13 +975,13 @@
|
||||
F3BA81061CFB3052003DC1BA /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */; };
|
||||
F3BA81071CFB3053003DC1BA /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */; };
|
||||
F3BA81081CFB3056003DC1BA /* DatabaseCoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4361BE4C11200E39BBF /* DatabaseCoderTests.swift */; };
|
||||
F3BA81091CFB3056003DC1BA /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
F3BA810A1CFB3056003DC1BA /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
F3BA81091CFB3056003DC1BA /* DateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */; };
|
||||
F3BA810A1CFB3056003DC1BA /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DateTests.swift */; };
|
||||
F3BA810B1CFB3056003DC1BA /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; };
|
||||
F3BA810C1CFB3056003DC1BA /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; };
|
||||
F3BA810D1CFB3057003DC1BA /* DatabaseCoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4361BE4C11200E39BBF /* DatabaseCoderTests.swift */; };
|
||||
F3BA810E1CFB3057003DC1BA /* NSDateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */; };
|
||||
F3BA810F1CFB3057003DC1BA /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* NSDateTests.swift */; };
|
||||
F3BA810E1CFB3057003DC1BA /* DateComponentsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */; };
|
||||
F3BA810F1CFB3057003DC1BA /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F0B98E1B6001C600A2F135 /* DateTests.swift */; };
|
||||
F3BA81101CFB3057003DC1BA /* Row+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */; };
|
||||
F3BA81111CFB3057003DC1BA /* StatementArguments+FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */; };
|
||||
F3BA81121CFB3059003DC1BA /* DatabaseMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238241B9C74A90082EB20 /* DatabaseMigratorTests.swift */; };
|
||||
@@ -1393,8 +1393,8 @@
|
||||
56EA869D1C932597002BB4DF /* DatabasePoolReadOnlyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolReadOnlyTests.swift; sourceTree = "<group>"; };
|
||||
56EB0AB11BCD787300A3DC55 /* DataMemoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataMemoryTests.swift; sourceTree = "<group>"; };
|
||||
56EE573C1BB317B7007A6A95 /* SQLiteStatementConversionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLiteStatementConversionTests.swift; sourceTree = "<group>"; };
|
||||
56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDateComponentsTests.swift; sourceTree = "<group>"; };
|
||||
56F0B98E1B6001C600A2F135 /* NSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDateTests.swift; sourceTree = "<group>"; };
|
||||
56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateComponentsTests.swift; sourceTree = "<group>"; };
|
||||
56F0B98E1B6001C600A2F135 /* DateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateTests.swift; sourceTree = "<group>"; };
|
||||
56FC78641BBAEB8C00CA1285 /* MappingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MappingTests.swift; sourceTree = "<group>"; };
|
||||
56FC78651BBAEB8C00CA1285 /* ManagedDataControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedDataControllerTests.swift; sourceTree = "<group>"; };
|
||||
56FDECE11BB32DFD009AD709 /* MetalRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalRowTests.swift; sourceTree = "<group>"; };
|
||||
@@ -2077,8 +2077,8 @@
|
||||
children = (
|
||||
56B7F4361BE4C11200E39BBF /* DatabaseCoderTests.swift */,
|
||||
EED6C2EB1D00DF5F00F8E701 /* DatabaseValue+FoundationTests.swift */,
|
||||
56F0B98D1B6001C600A2F135 /* NSDateComponentsTests.swift */,
|
||||
56F0B98E1B6001C600A2F135 /* NSDateTests.swift */,
|
||||
56F0B98D1B6001C600A2F135 /* DateComponentsTests.swift */,
|
||||
56F0B98E1B6001C600A2F135 /* DateTests.swift */,
|
||||
565D5D701BBC694D00DC9BD4 /* Row+FoundationTests.swift */,
|
||||
565D5D731BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift */,
|
||||
);
|
||||
@@ -3042,10 +3042,10 @@
|
||||
560FC59C1CB00B880014AA8E /* StatementArguments+FoundationTests.swift in Sources */,
|
||||
560FC59D1CB00B880014AA8E /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
5634B0741CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
560FC59E1CB00B880014AA8E /* NSDateTests.swift in Sources */,
|
||||
560FC59E1CB00B880014AA8E /* DateTests.swift in Sources */,
|
||||
560FC59F1CB00B880014AA8E /* DatabaseTests.swift in Sources */,
|
||||
560FC5A01CB00B880014AA8E /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
560FC5A11CB00B880014AA8E /* NSDateComponentsTests.swift in Sources */,
|
||||
560FC5A11CB00B880014AA8E /* DateComponentsTests.swift in Sources */,
|
||||
560FC5A21CB00B880014AA8E /* FunctionTests.swift in Sources */,
|
||||
560FC5A41CB00B880014AA8E /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
560FC5A51CB00B880014AA8E /* CGFloatTests.swift in Sources */,
|
||||
@@ -3147,13 +3147,13 @@
|
||||
567156591CB16729007DC145 /* DatabaseTimestampTests.swift in Sources */,
|
||||
5671565A1CB16729007DC145 /* StatementArguments+FoundationTests.swift in Sources */,
|
||||
5671565B1CB16729007DC145 /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
5671565C1CB16729007DC145 /* NSDateTests.swift in Sources */,
|
||||
5671565C1CB16729007DC145 /* DateTests.swift in Sources */,
|
||||
5671565D1CB16729007DC145 /* DatabaseTests.swift in Sources */,
|
||||
5671565E1CB16729007DC145 /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
569178481CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */,
|
||||
5634B1091CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */,
|
||||
5634B0751CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
5671565F1CB16729007DC145 /* NSDateComponentsTests.swift in Sources */,
|
||||
5671565F1CB16729007DC145 /* DateComponentsTests.swift in Sources */,
|
||||
567156601CB16729007DC145 /* FunctionTests.swift in Sources */,
|
||||
567156611CB16729007DC145 /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
567156621CB16729007DC145 /* CGFloatTests.swift in Sources */,
|
||||
@@ -3290,10 +3290,10 @@
|
||||
56AFCA6B1CB1AA9900F48B96 /* DatabaseTimestampTests.swift in Sources */,
|
||||
56AFCA6C1CB1AA9900F48B96 /* StatementArguments+FoundationTests.swift in Sources */,
|
||||
56AFCA6D1CB1AA9900F48B96 /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
56AFCA6E1CB1AA9900F48B96 /* NSDateTests.swift in Sources */,
|
||||
56AFCA6E1CB1AA9900F48B96 /* DateTests.swift in Sources */,
|
||||
56AFCA6F1CB1AA9900F48B96 /* DatabaseTests.swift in Sources */,
|
||||
56AFCA701CB1AA9900F48B96 /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
56AFCA711CB1AA9900F48B96 /* NSDateComponentsTests.swift in Sources */,
|
||||
56AFCA711CB1AA9900F48B96 /* DateComponentsTests.swift in Sources */,
|
||||
5634B10B1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */,
|
||||
5634B0771CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
56AFCA721CB1AA9900F48B96 /* FunctionTests.swift in Sources */,
|
||||
@@ -3382,11 +3382,11 @@
|
||||
56AFCAC41CB1ABC800F48B96 /* DatabaseTimestampTests.swift in Sources */,
|
||||
56AFCAC51CB1ABC800F48B96 /* StatementArguments+FoundationTests.swift in Sources */,
|
||||
56AFCAC61CB1ABC800F48B96 /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
56AFCAC71CB1ABC800F48B96 /* NSDateTests.swift in Sources */,
|
||||
56AFCAC71CB1ABC800F48B96 /* DateTests.swift in Sources */,
|
||||
56AFCAC81CB1ABC800F48B96 /* DatabaseTests.swift in Sources */,
|
||||
56AFCAC91CB1ABC800F48B96 /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
5691784B1CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */,
|
||||
56AFCACA1CB1ABC800F48B96 /* NSDateComponentsTests.swift in Sources */,
|
||||
56AFCACA1CB1ABC800F48B96 /* DateComponentsTests.swift in Sources */,
|
||||
56AFCACB1CB1ABC800F48B96 /* FunctionTests.swift in Sources */,
|
||||
56AFCACC1CB1ABC800F48B96 /* InMemoryDatabaseTests.swift in Sources */,
|
||||
56AFCACD1CB1ABC800F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
@@ -3525,10 +3525,10 @@
|
||||
56A238B71B9CA2590082EB20 /* DatabaseTimestampTests.swift in Sources */,
|
||||
565D5D751BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift in Sources */,
|
||||
56300B6C1C53D3E8005A543B /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
56F0B9921B6001C600A2F135 /* NSDateTests.swift in Sources */,
|
||||
56F0B9921B6001C600A2F135 /* DateTests.swift in Sources */,
|
||||
56A238381B9C74A90082EB20 /* DatabaseTests.swift in Sources */,
|
||||
56300B5F1C53C38F005A543B /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
56F0B9901B6001C600A2F135 /* NSDateComponentsTests.swift in Sources */,
|
||||
56F0B9901B6001C600A2F135 /* DateComponentsTests.swift in Sources */,
|
||||
5634B10A1CF9B970005360B9 /* TransactionObserverSavepointsTests.swift in Sources */,
|
||||
5634B0761CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
560C97C81BFD0B8400BF8471 /* FunctionTests.swift in Sources */,
|
||||
@@ -3615,11 +3615,11 @@
|
||||
565D5D741BBC70AE00DC9BD4 /* StatementArguments+FoundationTests.swift in Sources */,
|
||||
567404931CF02B56003ED5CC /* AdapterRowTests.swift in Sources */,
|
||||
56300B6B1C53D3E8005A543B /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
56F0B9911B6001C600A2F135 /* NSDateTests.swift in Sources */,
|
||||
56F0B9911B6001C600A2F135 /* DateTests.swift in Sources */,
|
||||
5634B0731CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
56A238371B9C74A90082EB20 /* DatabaseTests.swift in Sources */,
|
||||
56300B661C53C8A7005A543B /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
56F0B98F1B6001C600A2F135 /* NSDateComponentsTests.swift in Sources */,
|
||||
56F0B98F1B6001C600A2F135 /* DateComponentsTests.swift in Sources */,
|
||||
560C97C71BFD0B8400BF8471 /* FunctionTests.swift in Sources */,
|
||||
56A238391B9C74A90082EB20 /* InMemoryDatabaseTests.swift in Sources */,
|
||||
56A5E4091BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
@@ -3755,7 +3755,7 @@
|
||||
F3BA81251CFB3063003DC1BA /* RecordAwakeFromFetchTests.swift in Sources */,
|
||||
EED6C2DD1D00B6D500F8E701 /* NSURLTests.swift in Sources */,
|
||||
F3BA81181CFB305E003DC1BA /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
F3BA810A1CFB3056003DC1BA /* NSDateTests.swift in Sources */,
|
||||
F3BA810A1CFB3056003DC1BA /* DateTests.swift in Sources */,
|
||||
F3BA80E51CFB3011003DC1BA /* FunctionTests.swift in Sources */,
|
||||
F3BA80531CFB2B59003DC1BA /* DataMemoryTests.swift in Sources */,
|
||||
F3BA80BC1CFB2FD1003DC1BA /* DatabasePoolFileAttributesTests.swift in Sources */,
|
||||
@@ -3796,7 +3796,7 @@
|
||||
F3BA81261CFB3063003DC1BA /* RecordCopyTests.swift in Sources */,
|
||||
F3BA80D61CFB2FFD003DC1BA /* DatabaseReaderTests.swift in Sources */,
|
||||
F3BA80F91CFB3021003DC1BA /* UpdateStatementTests.swift in Sources */,
|
||||
F3BA81091CFB3056003DC1BA /* NSDateComponentsTests.swift in Sources */,
|
||||
F3BA81091CFB3056003DC1BA /* DateComponentsTests.swift in Sources */,
|
||||
F3BA80DA1CFB300E003DC1BA /* DatabaseTimestampTests.swift in Sources */,
|
||||
F3BA81201CFB3063003DC1BA /* PrimaryKeyMultipleTests.swift in Sources */,
|
||||
F3BA812B1CFB3063003DC1BA /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
@@ -3911,7 +3911,7 @@
|
||||
F3BA80FF1CFB3025003DC1BA /* TransactionObserverSavepointsTests.swift in Sources */,
|
||||
F3BA80EF1CFB3017003DC1BA /* MetalRowTests.swift in Sources */,
|
||||
F3BA80B01CFB2FB2003DC1BA /* CollationTests.swift in Sources */,
|
||||
F3BA810F1CFB3057003DC1BA /* NSDateTests.swift in Sources */,
|
||||
F3BA810F1CFB3057003DC1BA /* DateTests.swift in Sources */,
|
||||
F3BA80F51CFB301E003DC1BA /* SQLiteStatementConversionTests.swift in Sources */,
|
||||
F3BA80A61CFB2F91003DC1BA /* GRDBTestCase.swift in Sources */,
|
||||
F3BA811C1CFB305F003DC1BA /* SQLSupportTests.swift in Sources */,
|
||||
@@ -3956,7 +3956,7 @@
|
||||
F3BA812D1CFB3064003DC1BA /* MinimalPrimaryKeySingleTests.swift in Sources */,
|
||||
F3BA811B1CFB305F003DC1BA /* RowConvertible+QueryInterfaceRequestTests.swift in Sources */,
|
||||
F3BA811A1CFB305F003DC1BA /* Record+QueryInterfaceRequestTests.swift in Sources */,
|
||||
F3BA810E1CFB3057003DC1BA /* NSDateComponentsTests.swift in Sources */,
|
||||
F3BA810E1CFB3057003DC1BA /* DateComponentsTests.swift in Sources */,
|
||||
F3BA81111CFB3057003DC1BA /* StatementArguments+FoundationTests.swift in Sources */,
|
||||
F3BA81371CFB3064003DC1BA /* RecordInitializersTests.swift in Sources */,
|
||||
F3BA810D1CFB3057003DC1BA /* DatabaseCoderTests.swift in Sources */,
|
||||
|
||||
@@ -177,7 +177,7 @@ public final class DatabasePool {
|
||||
releaseMemory()
|
||||
} else {
|
||||
// Perform releaseMemory() asynchronously.
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
|
||||
DispatchQueue.global(attributes: [.qosDefault]).async {
|
||||
self.releaseMemory()
|
||||
application.endBackgroundTask(task)
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public final class DatabasePool {
|
||||
}
|
||||
|
||||
@objc private func applicationDidReceiveMemoryWarning(_ notification: NSNotification) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
|
||||
DispatchQueue.global(attributes: [.qosDefault]).async {
|
||||
self.releaseMemory()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public final class DatabaseQueue {
|
||||
releaseMemory()
|
||||
} else {
|
||||
// Perform releaseMemory() asynchronously.
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
|
||||
DispatchQueue.global(attributes: [.qosDefault]).async {
|
||||
self.releaseMemory()
|
||||
application.endBackgroundTask(task)
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public final class DatabaseQueue {
|
||||
}
|
||||
|
||||
@objc private func applicationDidReceiveMemoryWarning(_ notification: NSNotification) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
|
||||
DispatchQueue.global(attributes: [.qosDefault]).async {
|
||||
self.releaseMemory()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ class DatabaseStore {
|
||||
// This require a file descriptor on the directory.
|
||||
let directoryDescriptor = open(directoryPath, O_EVTONLY)
|
||||
guard directoryDescriptor != -1 else {
|
||||
// Let NSFileManager throw a nice NSError
|
||||
// Let FileManager throw a nice NSError
|
||||
try FileManager.default().contentsOfDirectory(atPath: directoryPath)
|
||||
// Come on, NSFileManager... OK just throw something that is somewhat relevant
|
||||
// Come on, FileManager... OK just throw something that is somewhat relevant
|
||||
throw NSError(domain: NSCocoaErrorDomain, code: NSFileReadUnknownError, userInfo: nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -176,8 +176,8 @@ final class ReadWriteBox<T> {
|
||||
/// maximum number of elements is reached. In this case, the get() method
|
||||
/// blocks the current thread, until an element eventually turns available again.
|
||||
///
|
||||
/// let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
/// dispatch_apply(6, queue) { _ in
|
||||
/// let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
/// queue.apply(applier: 6) { _ in
|
||||
/// pool.get { n in
|
||||
/// print("got \(n)")
|
||||
/// }
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
//
|
||||
// func databaseWillCommit() throws {
|
||||
// do {
|
||||
// let fm = NSFileManager.default()
|
||||
// let fm = FileManager.default()
|
||||
// for (_, managedData) in pendingManagedDatas.sort({ $0.0 < $1.0 }) {
|
||||
// if let forbiddenData = forbiddenData, let data = managedData.data where forbiddenData == data {
|
||||
// throw NSError(domain: "ManagedDataController", code: 0, userInfo: nil)
|
||||
@@ -106,7 +106,7 @@
|
||||
//
|
||||
// func databaseDidRollback(_ db: Database) {
|
||||
// if restoreFileSystemAfterRollback {
|
||||
// let fm = NSFileManager.default()
|
||||
// let fm = FileManager.default()
|
||||
//
|
||||
// for managedData in storedManagedDatas {
|
||||
// if fm.fileExistsAtPath(storageDataPath(managedData)) {
|
||||
@@ -141,7 +141,7 @@
|
||||
// guard managedData.rowID != nil else {
|
||||
// return nil
|
||||
// }
|
||||
// let fm = NSFileManager.default()
|
||||
// let fm = FileManager.default()
|
||||
// if fm.fileExistsAtPath(storageDataPath(managedData)) {
|
||||
// return Data(contentsOfFile: storageDataPath(managedData))!
|
||||
// } else {
|
||||
@@ -168,7 +168,7 @@
|
||||
// }
|
||||
//
|
||||
// private func setupDirectories() {
|
||||
// let fm = NSFileManager.default()
|
||||
// let fm = FileManager.default()
|
||||
// try! fm.createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil)
|
||||
// try! fm.createDirectoryAtPath(temporaryDirectoryPath, withIntermediateDirectories: true, attributes: nil)
|
||||
// }
|
||||
|
||||
@@ -97,7 +97,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
assert(Int.fetchOne(db, "SELECT MIN(i0) FROM items")! == 0)
|
||||
assert(Int.fetchOne(db, "SELECT MAX(i9) FROM items")! == insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
@@ -22,7 +22,7 @@ class GRDBTestCase: XCTestCase {
|
||||
|
||||
// Builds a database queue based on dbConfiguration
|
||||
func makeDatabaseQueue(filename: String = "db.sqlite") throws -> DatabaseQueue {
|
||||
try NSFileManager.default().createDirectory(atPath: dbDirectoryPath, withIntermediateDirectories: true, attributes: nil)
|
||||
try FileManager.default().createDirectory(atPath: dbDirectoryPath, withIntermediateDirectories: true, attributes: nil)
|
||||
let dbPath = (dbDirectoryPath as NSString).appendingPathComponent(filename)
|
||||
let dbQueue = try DatabaseQueue(path: dbPath, configuration: dbConfiguration)
|
||||
try setup(dbQueue)
|
||||
@@ -31,7 +31,7 @@ class GRDBTestCase: XCTestCase {
|
||||
|
||||
// Builds a database pool based on dbConfiguration
|
||||
func makeDatabasePool(filename: String = "db.sqlite") throws -> DatabasePool {
|
||||
try NSFileManager.default().createDirectory(atPath: dbDirectoryPath, withIntermediateDirectories: true, attributes: nil)
|
||||
try FileManager.default().createDirectory(atPath: dbDirectoryPath, withIntermediateDirectories: true, attributes: nil)
|
||||
let dbPath = (dbDirectoryPath as NSString).appendingPathComponent(filename)
|
||||
let dbPool = try DatabasePool(path: dbPath, configuration: dbConfiguration)
|
||||
try setup(dbPool)
|
||||
@@ -55,9 +55,9 @@ class GRDBTestCase: XCTestCase {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
let dbPoolDirectoryName = "GRDBTestCase-\(NSProcessInfo.processInfo().globallyUniqueString)"
|
||||
let dbPoolDirectoryName = "GRDBTestCase-\(ProcessInfo.processInfo().globallyUniqueString)"
|
||||
dbDirectoryPath = (NSTemporaryDirectory() as NSString).appendingPathComponent(dbPoolDirectoryName)
|
||||
do { try NSFileManager.default().removeItem(atPath: dbDirectoryPath) } catch { }
|
||||
do { try FileManager.default().removeItem(atPath: dbDirectoryPath) } catch { }
|
||||
|
||||
dbConfiguration = Configuration()
|
||||
|
||||
@@ -107,7 +107,7 @@ class GRDBTestCase: XCTestCase {
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
do { try NSFileManager.default().removeItem(atPath: dbDirectoryPath) } catch { }
|
||||
do { try FileManager.default().removeItem(atPath: dbDirectoryPath) } catch { }
|
||||
}
|
||||
|
||||
func assertNoError(file: StaticString = #file, line: UInt = #line, _ test: @noescape(Void) throws -> Void) {
|
||||
|
||||
@@ -17,11 +17,11 @@ class InsertNamedValuesTests: XCTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MIN(i0) FROM items")!, 0)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MAX(i9) FROM items")!, insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)
|
||||
dbQueue.inDatabase { db in
|
||||
@@ -47,11 +47,11 @@ class InsertNamedValuesTests: XCTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MIN(i0) FROM items")!, 0)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MAX(i9) FROM items")!, insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
let dbQueue = try! DatabaseQueue(path: databasePath)
|
||||
try! dbQueue.inDatabase { db in
|
||||
@@ -78,11 +78,11 @@ class InsertNamedValuesTests: XCTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MIN(i0) FROM items")!, 0)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MAX(i9) FROM items")!, insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
let db = try! Connection(databasePath)
|
||||
try! db.run(itemsTable.create { t in
|
||||
|
||||
@@ -17,11 +17,11 @@ class InsertPositionalValuesTests: XCTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MIN(i0) FROM items")!, 0)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MAX(i9) FROM items")!, insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
var connection: OpaquePointer = nil
|
||||
sqlite3_open_v2(databasePath, &connection, 0x00000004 /*SQLITE_OPEN_CREATE*/ | 0x00000002 /*SQLITE_OPEN_READWRITE*/, nil)
|
||||
@@ -63,10 +63,10 @@ class InsertPositionalValuesTests: XCTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MIN(i0) FROM items")!, 0)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MAX(i9) FROM items")!, insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
let dbQueue = FMDatabaseQueue(path: databasePath)
|
||||
dbQueue.inDatabase { db in
|
||||
@@ -92,10 +92,10 @@ class InsertPositionalValuesTests: XCTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MIN(i0) FROM items")!, 0)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MAX(i9) FROM items")!, insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
let dbQueue = try! DatabaseQueue(path: databasePath)
|
||||
try! dbQueue.inDatabase { db in
|
||||
@@ -122,10 +122,10 @@ class InsertPositionalValuesTests: XCTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MIN(i0) FROM items")!, 0)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MAX(i9) FROM items")!, insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
let db = try! Connection(databasePath)
|
||||
try! db.run(itemsTable.create { t in
|
||||
|
||||
@@ -11,7 +11,7 @@ class InsertRecordTests: XCTestCase {
|
||||
func testGRDB() {
|
||||
let databaseFileName = "GRDBPerformanceTests-\(NSProcessInfo.processInfo().globallyUniqueString).sqlite"
|
||||
let databasePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(databaseFileName)
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
defer {
|
||||
let dbQueue = try! DatabaseQueue(path: databasePath)
|
||||
dbQueue.inDatabase { db in
|
||||
@@ -19,11 +19,11 @@ class InsertRecordTests: XCTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MIN(i0) FROM items")!, 0)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT MAX(i9) FROM items")!, insertedRowCount - 1)
|
||||
}
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
|
||||
let dbQueue = try! DatabaseQueue(path: databasePath)
|
||||
try! dbQueue.inDatabase { db in
|
||||
@@ -66,7 +66,7 @@ class InsertRecordTests: XCTestCase {
|
||||
}
|
||||
try! moc.save()
|
||||
try! psc.removePersistentStore(store)
|
||||
try! NSFileManager.default().removeItem(atPath: databasePath)
|
||||
try! FileManager.default().removeItem(atPath: databasePath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class InsertRecordTests: XCTestCase {
|
||||
let databasePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(databaseFileName)
|
||||
|
||||
measureBlock {
|
||||
_ = try? NSFileManager.default().removeItem(atPath: databasePath)
|
||||
_ = try? FileManager.default().removeItem(atPath: databasePath)
|
||||
let realm = try! Realm(path: databasePath)
|
||||
|
||||
try! realm.write {
|
||||
|
||||
@@ -38,14 +38,18 @@ class DataMemoryTests: GRDBTestCase {
|
||||
do {
|
||||
// This data should be copied:
|
||||
let copiedData: Data = row.value(atIndex: 0)
|
||||
XCTAssertNotEqual(copiedData.bytes, sqliteBytes)
|
||||
copiedData.withUnsafeBytes { copiedBytes in
|
||||
XCTAssertNotEqual(copiedBytes, sqliteBytes)
|
||||
}
|
||||
XCTAssertEqual(copiedData, data)
|
||||
}
|
||||
|
||||
do {
|
||||
// This data should not be copied
|
||||
let nonCopiedData = row.dataNoCopy(atIndex: 0)!
|
||||
XCTAssertEqual(nonCopiedData.bytes, sqliteBytes)
|
||||
nonCopiedData.withUnsafeBytes { nonCopiedBytes in
|
||||
XCTAssertEqual(nonCopiedBytes, sqliteBytes)
|
||||
}
|
||||
XCTAssertEqual(nonCopiedData, data)
|
||||
}
|
||||
}
|
||||
@@ -54,18 +58,24 @@ class DataMemoryTests: GRDBTestCase {
|
||||
let databaseValue = row.first!.1
|
||||
switch databaseValue.storage {
|
||||
case .blob(let data):
|
||||
do {
|
||||
// This data should not be copied:
|
||||
let nonCopiedData: Data = row.value(atIndex: 0)
|
||||
XCTAssertEqual(nonCopiedData.bytes, data.bytes)
|
||||
XCTAssertEqual(nonCopiedData, data)
|
||||
}
|
||||
|
||||
do {
|
||||
// This data should not be copied:
|
||||
let nonCopiedData = row.dataNoCopy(atIndex: 0)!
|
||||
XCTAssertEqual(nonCopiedData.bytes, data.bytes)
|
||||
XCTAssertEqual(nonCopiedData, data)
|
||||
data.withUnsafeBytes { (dataBytes: UnsafePointer<Void>) -> Void in
|
||||
do {
|
||||
// This data should not be copied:
|
||||
let nonCopiedData: Data = row.value(atIndex: 0)
|
||||
nonCopiedData.withUnsafeBytes { nonCopiedBytes in
|
||||
XCTAssertEqual(nonCopiedBytes, dataBytes)
|
||||
}
|
||||
XCTAssertEqual(nonCopiedData, data)
|
||||
}
|
||||
|
||||
do {
|
||||
// This data should not be copied:
|
||||
let nonCopiedData = row.dataNoCopy(atIndex: 0)!
|
||||
nonCopiedData.withUnsafeBytes { nonCopiedBytes in
|
||||
XCTAssertEqual(nonCopiedBytes, dataBytes)
|
||||
}
|
||||
XCTAssertEqual(nonCopiedData, data)
|
||||
}
|
||||
}
|
||||
default:
|
||||
XCTFail("Not a blob")
|
||||
|
||||
@@ -11,19 +11,19 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
func testDatabasePoolDeinitClosesAllConnections() {
|
||||
assertNoError {
|
||||
let countQueue = dispatch_queue_create(nil, nil)!
|
||||
let countQueue = DispatchQueue(label: "GRDB")
|
||||
var openConnectionCount = 0
|
||||
var totalOpenConnectionCount = 0
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidOpen = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
totalOpenConnectionCount += 1
|
||||
openConnectionCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidClose = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
openConnectionCount -= 1
|
||||
}
|
||||
}
|
||||
@@ -51,19 +51,19 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
func testDatabasePoolReleaseMemoryClosesReaderConnections() {
|
||||
assertNoError {
|
||||
let countQueue = dispatch_queue_create(nil, nil)!
|
||||
let countQueue = DispatchQueue(label: "GRDB")
|
||||
var openConnectionCount = 0
|
||||
var totalOpenConnectionCount = 0
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidOpen = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
totalOpenConnectionCount += 1
|
||||
openConnectionCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidClose = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
openConnectionCount -= 1
|
||||
}
|
||||
}
|
||||
@@ -80,43 +80,43 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
// SELECT * FROM items
|
||||
// step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// SELECT * FROM items
|
||||
// step
|
||||
// >
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step step
|
||||
// >
|
||||
let s3 = dispatch_semaphore_create(0)!
|
||||
let s3 = DispatchSemaphore(value: 0)
|
||||
// end end releaseMemory
|
||||
|
||||
let block1 = { () in
|
||||
dbPool.read { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s3)
|
||||
s3.signal()
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
dbPool.read { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
}
|
||||
}
|
||||
let block3 = { () in
|
||||
dispatch_semaphore_wait(s3, DISPATCH_TIME_FOREVER)
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
dbPool.releaseMemory()
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(3, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 3) { index in
|
||||
[block1, block2, block3][index]()
|
||||
}
|
||||
|
||||
@@ -130,19 +130,19 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
func testBlocksRetainConnection() {
|
||||
assertNoError {
|
||||
let countQueue = dispatch_queue_create(nil, nil)!
|
||||
let countQueue = DispatchQueue(label: "GRDB")
|
||||
var openConnectionCount = 0
|
||||
var totalOpenConnectionCount = 0
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidOpen = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
totalOpenConnectionCount += 1
|
||||
openConnectionCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidClose = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
openConnectionCount -= 1
|
||||
}
|
||||
}
|
||||
@@ -150,10 +150,10 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
// Block 1 Block 2
|
||||
// read {
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// dbPool = nil
|
||||
// >
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// use database
|
||||
// }
|
||||
|
||||
@@ -164,15 +164,15 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
dbPool = nil
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
}
|
||||
let block2 = { [weak dbPool] () in
|
||||
if let dbPool = dbPool {
|
||||
dbPool.read { db in
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items"), 0)
|
||||
}
|
||||
} else {
|
||||
@@ -181,9 +181,9 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
return (block1, block2)
|
||||
}()
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let blocks = [block1, block2]
|
||||
dispatch_apply(blocks.count, queue) { index in
|
||||
queue.apply(applier: blocks.count) { index in
|
||||
blocks[index]()
|
||||
}
|
||||
|
||||
@@ -202,19 +202,19 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
return
|
||||
}
|
||||
assertNoError {
|
||||
let countQueue = dispatch_queue_create(nil, nil)!
|
||||
let countQueue = DispatchQueue(label: "GRDB")
|
||||
var openConnectionCount = 0
|
||||
var totalOpenConnectionCount = 0
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidOpen = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
totalOpenConnectionCount += 1
|
||||
openConnectionCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidClose = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
openConnectionCount -= 1
|
||||
}
|
||||
}
|
||||
@@ -224,10 +224,10 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
// SELECT
|
||||
// step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// dbPool = nil
|
||||
// >
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step
|
||||
// end
|
||||
// }
|
||||
@@ -241,9 +241,9 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
dbPool = nil
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
}
|
||||
let block2 = { [weak dbPool] () in
|
||||
weak var connection: Database? = nil
|
||||
@@ -254,13 +254,13 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
connection = db
|
||||
iterator = Int.fetch(db, "SELECT id FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator!.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
s1.signal()
|
||||
}
|
||||
} else {
|
||||
XCTFail("expect non nil dbPool")
|
||||
}
|
||||
}
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
do {
|
||||
XCTAssertTrue(dbPool == nil)
|
||||
XCTAssertTrue(iterator!.next() != nil)
|
||||
@@ -271,9 +271,9 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
return (block1, block2)
|
||||
}()
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let blocks = [block1, block2]
|
||||
dispatch_apply(blocks.count, queue) { index in
|
||||
queue.apply(applier: blocks.count) { index in
|
||||
blocks[index]()
|
||||
}
|
||||
|
||||
@@ -295,18 +295,18 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
// Block 1 Block 2
|
||||
// create statement INSERT
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// dbPool = nil
|
||||
// >
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// dbPool is nil
|
||||
|
||||
let (block1, block2) = { () -> (() -> (), () -> ()) in
|
||||
var dbPool: DatabasePool? = try! makeDatabasePool()
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
dbPool = nil
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
}
|
||||
let block2 = { [weak dbPool] () in
|
||||
var statement: UpdateStatement? = nil
|
||||
@@ -315,7 +315,7 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
do {
|
||||
try dbPool.write { db in
|
||||
statement = try db.makeUpdateStatement("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
dispatch_semaphore_signal(s1)
|
||||
s1.signal()
|
||||
}
|
||||
} catch {
|
||||
XCTFail("error: \(error)")
|
||||
@@ -324,15 +324,15 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
|
||||
XCTFail("expect non nil dbPool")
|
||||
}
|
||||
}
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(statement != nil)
|
||||
XCTAssertTrue(dbPool == nil)
|
||||
}
|
||||
return (block1, block2)
|
||||
}()
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let blocks = [block1, block2]
|
||||
dispatch_apply(blocks.count, queue) { index in
|
||||
queue.apply(applier: blocks.count) { index in
|
||||
blocks[index]()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,25 +85,25 @@ class DatabasePoolSchemaCacheTests : GRDBTestCase {
|
||||
// Block 1 Block 2
|
||||
// SELECT 1 FROM items WHERE id = 1
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// SELECT 1 FROM items WHERE id = 1
|
||||
|
||||
let block1 = { () in
|
||||
dbPool.read { db in
|
||||
let stmt = try! db.cachedSelectStatement("SELECT * FROM items")
|
||||
XCTAssertEqual(Int.fetchOne(stmt)!, 1)
|
||||
dispatch_semaphore_signal(s1)
|
||||
s1.signal()
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
dbPool.read { db in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
let stmt = try! db.cachedSelectStatement("SELECT * FROM items")
|
||||
XCTAssertEqual(Int.fetchOne(stmt)!, 1)
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
func testDatabaseQueueuDeinitClosesConnection() {
|
||||
assertNoError {
|
||||
let countQueue = dispatch_queue_create(nil, nil)!
|
||||
let countQueue = DispatchQueue(label: "GRDB")
|
||||
var openConnectionCount = 0
|
||||
var totalOpenConnectionCount = 0
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidOpen = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
totalOpenConnectionCount += 1
|
||||
openConnectionCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidClose = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
openConnectionCount -= 1
|
||||
}
|
||||
}
|
||||
@@ -43,19 +43,19 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
func testBlocksRetainConnection() {
|
||||
assertNoError {
|
||||
let countQueue = dispatch_queue_create(nil, nil)!
|
||||
let countQueue = DispatchQueue(label: "GRDB")
|
||||
var openConnectionCount = 0
|
||||
var totalOpenConnectionCount = 0
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidOpen = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
totalOpenConnectionCount += 1
|
||||
openConnectionCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidClose = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
openConnectionCount -= 1
|
||||
}
|
||||
}
|
||||
@@ -63,10 +63,10 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
// Block 1 Block 2
|
||||
// inDatabase {
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// dbQueue = nil
|
||||
// >
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// use database
|
||||
// }
|
||||
|
||||
@@ -77,15 +77,15 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
dbQueue = nil
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
}
|
||||
let block2 = { [weak dbQueue] () in
|
||||
if let dbQueue = dbQueue {
|
||||
dbQueue.write { db in
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items"), 0)
|
||||
}
|
||||
} else {
|
||||
@@ -94,9 +94,9 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
return (block1, block2)
|
||||
}()
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let blocks = [block1, block2]
|
||||
dispatch_apply(blocks.count, queue) { index in
|
||||
queue.apply(applier: blocks.count) { index in
|
||||
blocks[index]()
|
||||
}
|
||||
|
||||
@@ -115,19 +115,19 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
return
|
||||
}
|
||||
assertNoError {
|
||||
let countQueue = dispatch_queue_create(nil, nil)!
|
||||
let countQueue = DispatchQueue(label: "GRDB")
|
||||
var openConnectionCount = 0
|
||||
var totalOpenConnectionCount = 0
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidOpen = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
totalOpenConnectionCount += 1
|
||||
openConnectionCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
dbConfiguration.SQLiteConnectionDidClose = {
|
||||
dispatch_sync(countQueue) {
|
||||
countQueue.async {
|
||||
openConnectionCount -= 1
|
||||
}
|
||||
}
|
||||
@@ -137,10 +137,10 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
// SELECT
|
||||
// step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// dbQueue = nil
|
||||
// >
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step
|
||||
// end
|
||||
// }
|
||||
@@ -154,9 +154,9 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
dbQueue = nil
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
}
|
||||
let block2 = { [weak dbQueue] () in
|
||||
weak var connection: Database? = nil
|
||||
@@ -167,13 +167,13 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
connection = db
|
||||
iterator = Int.fetch(db, "SELECT id FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator!.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
s1.signal()
|
||||
}
|
||||
} else {
|
||||
XCTFail("expect non nil dbQueue")
|
||||
}
|
||||
}
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
do {
|
||||
XCTAssertTrue(dbQueue == nil)
|
||||
XCTAssertTrue(iterator!.next() != nil)
|
||||
@@ -184,9 +184,9 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
}
|
||||
return (block1, block2)
|
||||
}()
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let blocks = [block1, block2]
|
||||
dispatch_apply(blocks.count, queue) { index in
|
||||
queue.apply(applier: blocks.count) { index in
|
||||
blocks[index]()
|
||||
}
|
||||
|
||||
@@ -208,19 +208,19 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
// Block 1 Block 2
|
||||
// create statement INSERT
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// dbQueue = nil
|
||||
// >
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// dbQueue is nil
|
||||
|
||||
let (block1, block2) = { () -> (() -> (), () -> ()) in
|
||||
var dbQueue: DatabaseQueue? = try! makeDatabaseQueue()
|
||||
|
||||
let block1 = { () in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
dbQueue = nil
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
}
|
||||
let block2 = { [weak dbQueue] () in
|
||||
var statement: UpdateStatement? = nil
|
||||
@@ -229,7 +229,7 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
do {
|
||||
try dbQueue.write { db in
|
||||
statement = try db.makeUpdateStatement("CREATE TABLE items (id INTEGER PRIMARY KEY)")
|
||||
dispatch_semaphore_signal(s1)
|
||||
s1.signal()
|
||||
}
|
||||
} catch {
|
||||
XCTFail("error: \(error)")
|
||||
@@ -238,15 +238,15 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
XCTFail("expect non nil dbQueue")
|
||||
}
|
||||
}
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(statement != nil)
|
||||
XCTAssertTrue(dbQueue == nil)
|
||||
}
|
||||
return (block1, block2)
|
||||
}()
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let blocks = [block1, block2]
|
||||
dispatch_apply(blocks.count, queue) { index in
|
||||
queue.apply(applier: blocks.count) { index in
|
||||
blocks[index]()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,13 +49,13 @@ class DatabasePoolBackupTests: GRDBTestCase {
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
DispatchQueue.global(attributes: [.qosDefault]).async {
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try! source.writeInTransaction(.immediate) { db in
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
@@ -63,8 +63,8 @@ class DatabasePoolBackupTests: GRDBTestCase {
|
||||
try source.backup(
|
||||
to: destination,
|
||||
afterBackupInit: {
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
},
|
||||
afterBackupStep: {
|
||||
try! source.write { db in
|
||||
|
||||
@@ -38,10 +38,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// SELECT * FROM items SELECT * FROM items
|
||||
// step step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// step
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step step
|
||||
// step end
|
||||
// end COMMIT
|
||||
@@ -51,8 +51,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
dbPool.read { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
@@ -62,15 +62,15 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
dbPool.read { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// SELECT * FROM items
|
||||
// step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// DELETE * FROM items
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step
|
||||
// end
|
||||
// COMMIT
|
||||
@@ -103,16 +103,16 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
dbPool.read { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
defer { dispatch_semaphore_signal(s2) }
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.write { db in
|
||||
try db.execute("DELETE FROM items")
|
||||
}
|
||||
@@ -120,8 +120,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTFail("error: \(error)")
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
@@ -142,11 +142,11 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// SELECT * FROM items
|
||||
// step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// DELETE * FROM items
|
||||
// Checkpoint
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step
|
||||
// end
|
||||
// COMMIT
|
||||
@@ -155,16 +155,16 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
dbPool.read { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
defer { dispatch_semaphore_signal(s2) }
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.write { db in
|
||||
try db.execute("DELETE FROM items")
|
||||
}
|
||||
@@ -173,8 +173,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTFail("error: \(error)")
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
@@ -191,26 +191,26 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// BEGIN DEFERRED TRANSACTION
|
||||
// SELECT COUNT(*) FROM items -> 0
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// INSERT INTO items (id) VALUES (NULL)
|
||||
// Checkpoint
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// SELECT COUNT(*) FROM items -> 0
|
||||
// COMMIT
|
||||
|
||||
let block1 = { () in
|
||||
dbPool.read { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
defer { dispatch_semaphore_signal(s2) }
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.write { db in
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
@@ -219,8 +219,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTFail("error: \(error)")
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
@@ -237,20 +237,20 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// BEGIN IMMEDIATE TRANSACTION
|
||||
// INSERT INTO items (id) VALUES (NULL)
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// BEGIN DEFERRED TRANSACTION
|
||||
// SELECT COUNT(*) FROM items -> 0
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// INSERT INTO items (id) VALUES (NULL)
|
||||
// >
|
||||
let s3 = dispatch_semaphore_create(0)!
|
||||
let s3 = DispatchSemaphore(value: 0)
|
||||
// SELECT COUNT(*) FROM items -> 0
|
||||
// <
|
||||
let s4 = dispatch_semaphore_create(0)!
|
||||
let s4 = DispatchSemaphore(value: 0)
|
||||
// COMMIT
|
||||
// >
|
||||
let s5 = dispatch_semaphore_create(0)!
|
||||
let s5 = DispatchSemaphore(value: 0)
|
||||
// SELECT COUNT(*) FROM items -> 0
|
||||
// COMMIT
|
||||
|
||||
@@ -258,32 +258,32 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
do {
|
||||
try dbPool.writeInTransaction(.immediate) { db in
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
dispatch_semaphore_signal(s3)
|
||||
dispatch_semaphore_wait(s4, DISPATCH_TIME_FOREVER)
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
}
|
||||
dispatch_semaphore_signal(s5)
|
||||
s5.signal()
|
||||
} catch {
|
||||
XCTFail("error: \(error)")
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
dbPool.read { db in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0)
|
||||
dispatch_semaphore_signal(s2)
|
||||
dispatch_semaphore_wait(s3, DISPATCH_TIME_FOREVER)
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0)
|
||||
dispatch_semaphore_signal(s4)
|
||||
dispatch_semaphore_wait(s5, DISPATCH_TIME_FOREVER)
|
||||
s4.signal()
|
||||
_ = s5.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0)
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
@@ -303,10 +303,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// SELECT * FROM items
|
||||
// step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// DELETE * FROM items
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step
|
||||
// end
|
||||
// SELECT COUNT(*) FROM items -> 0
|
||||
@@ -315,8 +315,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
dbPool.nonIsolatedRead { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0)
|
||||
@@ -324,8 +324,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
let block2 = { () in
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
defer { dispatch_semaphore_signal(s2) }
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.write { db in
|
||||
try db.execute("DELETE FROM items")
|
||||
}
|
||||
@@ -333,8 +333,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTFail("error: \(error)")
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
@@ -354,11 +354,11 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// SELECT * FROM items
|
||||
// step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// DELETE * FROM items
|
||||
// Checkpoint
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step
|
||||
// end
|
||||
|
||||
@@ -366,16 +366,16 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
dbPool.nonIsolatedRead { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
defer { dispatch_semaphore_signal(s2) }
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.write { db in
|
||||
try db.execute("DELETE FROM items")
|
||||
}
|
||||
@@ -384,8 +384,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTFail("error: \(error)")
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
@@ -401,25 +401,25 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
// Block 1 Block 2
|
||||
// SELECT COUNT(*) FROM items -> 0
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// INSERT INTO items (id) VALUES (NULL)
|
||||
// Checkpoint
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// SELECT COUNT(*) FROM items -> 1
|
||||
|
||||
let block1 = { () in
|
||||
dbPool.nonIsolatedRead { db in
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 0)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertEqual(Int.fetchOne(db, "SELECT COUNT(*) FROM items")!, 1)
|
||||
}
|
||||
}
|
||||
let block2 = { () in
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
defer { dispatch_semaphore_signal(s2) }
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
defer { s2.signal() }
|
||||
try dbPool.write { db in
|
||||
try db.execute("INSERT INTO items (id) VALUES (NULL)")
|
||||
}
|
||||
@@ -428,8 +428,8 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
|
||||
XCTFail("error: \(error)")
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,23 +12,23 @@ class DatabasePoolFileAttributesTests: GRDBTestCase {
|
||||
func testDefaultFileAttributes() {
|
||||
assertNoError {
|
||||
let dbPool = try makeDatabasePool()
|
||||
let fm = NSFileManager.default()
|
||||
let fm = FileManager.default()
|
||||
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
}
|
||||
var attributes = try fm.attributesOfItem(atPath: dbPool.path)
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertFalse((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItem(atPath: dbPool.path + "-wal")
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertFalse((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItem(atPath: dbPool.path + "-shm")
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertFalse((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
}
|
||||
}
|
||||
|
||||
func testExplicitFileAttributesOnExistingFile() {
|
||||
assertNoError {
|
||||
let fm = NSFileManager.default()
|
||||
let fm = FileManager.default()
|
||||
|
||||
do {
|
||||
let dbPool = try makeDatabasePool()
|
||||
@@ -36,47 +36,47 @@ class DatabasePoolFileAttributesTests: GRDBTestCase {
|
||||
try db.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
}
|
||||
var attributes = try fm.attributesOfItem(atPath: dbPool.path)
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertFalse((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItem(atPath: dbPool.path + "-wal")
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertFalse((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItem(atPath: dbPool.path + "-shm")
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertFalse((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.fileAttributes = [NSFileExtensionHidden: true]
|
||||
dbConfiguration.fileAttributes = [FileAttributeKey.extensionHidden.rawValue: true]
|
||||
let dbPool = try makeDatabasePool()
|
||||
// TODO: this test is fragile: we have to wait until the database
|
||||
// store has been notified of file creation.
|
||||
NSThread.sleep(forTimeInterval: 0.1)
|
||||
Thread.sleep(forTimeInterval: 0.1)
|
||||
var attributes = try fm.attributesOfItem(atPath: dbPool.path)
|
||||
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertTrue((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItem(atPath: dbPool.path + "-wal")
|
||||
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertTrue((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItem(atPath: dbPool.path + "-shm")
|
||||
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertTrue((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testExplicitFileAttributesOnNewFile() {
|
||||
assertNoError {
|
||||
let fm = NSFileManager.default()
|
||||
let fm = FileManager.default()
|
||||
|
||||
dbConfiguration.fileAttributes = [NSFileExtensionHidden: true]
|
||||
dbConfiguration.fileAttributes = [FileAttributeKey.extensionHidden.rawValue: true]
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { db in
|
||||
try db.execute("CREATE TABLE foo (bar INTEGER)")
|
||||
}
|
||||
// TODO: this test is fragile: we have to wait until the database
|
||||
// store has been notified of file creation.
|
||||
NSThread.sleep(forTimeInterval: 0.1)
|
||||
Thread.sleep(forTimeInterval: 0.1)
|
||||
var attributes = try fm.attributesOfItem(atPath: dbPool.path)
|
||||
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertTrue((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItem(atPath: dbPool.path + "-wal")
|
||||
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertTrue((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
attributes = try fm.attributesOfItem(atPath: dbPool.path + "-shm")
|
||||
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertTrue((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,10 +38,10 @@ class DatabasePoolReadOnlyTests: GRDBTestCase {
|
||||
// SELECT * FROM items SELECT * FROM items
|
||||
// step step
|
||||
// >
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// step
|
||||
// <
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// step step
|
||||
// step end
|
||||
// end
|
||||
@@ -50,8 +50,8 @@ class DatabasePoolReadOnlyTests: GRDBTestCase {
|
||||
dbPool.read { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
@@ -61,15 +61,15 @@ class DatabasePoolReadOnlyTests: GRDBTestCase {
|
||||
dbPool.read { db in
|
||||
let iterator = Row.fetch(db, "SELECT * FROM items").makeIterator()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
XCTAssertTrue(iterator.next() != nil)
|
||||
XCTAssertTrue(iterator.next() == nil)
|
||||
}
|
||||
}
|
||||
let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
|
||||
dispatch_apply(2, queue) { index in
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
queue.apply(applier: 2) { index in
|
||||
[block1, block2][index]()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,32 +55,32 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
|
||||
// Queue 1 Queue 2
|
||||
// BEGIN DEFERRED TRANSACTION
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// BEGIN DEFERRED TRANSACTION
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// INSERT INTO stuffs (id) VALUES (NULL)
|
||||
let s3 = dispatch_semaphore_create(0)!
|
||||
let s3 = DispatchSemaphore(value: 0)
|
||||
// INSERT INTO stuffs (id) VALUES (NULL) <--- Error
|
||||
// ROLLBACK
|
||||
let s4 = dispatch_semaphore_create(0)!
|
||||
let s4 = DispatchSemaphore(value: 0)
|
||||
// COMMIT
|
||||
|
||||
try! dbQueue1.inDatabase { db in
|
||||
try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let queue = dispatch_queue_create("GRDB", DISPATCH_QUEUE_CONCURRENT)!
|
||||
let group = dispatch_group_create()!
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Queue 1
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
try dbQueue1.inTransaction(.deferred) { db in
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try db.execute("INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
dispatch_semaphore_signal(s3)
|
||||
dispatch_semaphore_wait(s4, DISPATCH_TIME_FOREVER)
|
||||
s3.signal()
|
||||
_ = s4.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
@@ -91,18 +91,18 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
|
||||
// Queue 2
|
||||
var concurrencyError: DatabaseError? = nil
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try dbQueue2.inTransaction(.deferred) { db in
|
||||
dispatch_semaphore_signal(s2)
|
||||
dispatch_semaphore_wait(s3, DISPATCH_TIME_FOREVER)
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
try db.execute("INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
catch let error as DatabaseError {
|
||||
dispatch_semaphore_signal(s4)
|
||||
s4.signal()
|
||||
concurrencyError = error
|
||||
}
|
||||
catch {
|
||||
@@ -110,7 +110,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER)
|
||||
_ = group.wait(timeout: .distantFuture)
|
||||
|
||||
if let concurrencyError = concurrencyError {
|
||||
XCTAssertEqual(concurrencyError.code, 5) // SQLITE_BUSY
|
||||
@@ -128,20 +128,20 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
|
||||
// Queue 1 Queue 2
|
||||
// BEGIN EXCLUSIVE TRANSACTION
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// BEGIN EXCLUSIVE TRANSACTION <--- Error
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// COMMIT
|
||||
|
||||
let queue = dispatch_queue_create("GRDB", DISPATCH_QUEUE_CONCURRENT)!
|
||||
let group = dispatch_group_create()!
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Queue 1
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
try dbQueue1.inTransaction(.exclusive) { db in
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
@@ -152,15 +152,15 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
|
||||
// Queue 2
|
||||
var concurrencyError: DatabaseError? = nil
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try dbQueue2.inTransaction(.exclusive) { db in
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
catch let error as DatabaseError {
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
concurrencyError = error
|
||||
}
|
||||
catch {
|
||||
@@ -168,7 +168,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER)
|
||||
_ = group.wait(timeout: .distantFuture)
|
||||
|
||||
if let concurrencyError = concurrencyError {
|
||||
XCTAssertEqual(concurrencyError.code, 5) // SQLITE_BUSY
|
||||
@@ -186,20 +186,20 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
|
||||
// Queue 1 Queue 2
|
||||
// BEGIN IMMEDIATE TRANSACTION
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// BEGIN IMMEDIATE TRANSACTION <--- Error
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// COMMIT
|
||||
|
||||
let queue = dispatch_queue_create("GRDB", DISPATCH_QUEUE_CONCURRENT)!
|
||||
let group = dispatch_group_create()!
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Queue 1
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
try dbQueue1.inTransaction(.immediate) { db in
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
@@ -210,15 +210,15 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
|
||||
// Queue 2
|
||||
var concurrencyError: DatabaseError? = nil
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try dbQueue2.inTransaction(.immediate) { db in
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
catch let error as DatabaseError {
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
concurrencyError = error
|
||||
}
|
||||
catch {
|
||||
@@ -226,7 +226,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER)
|
||||
_ = group.wait(timeout: .distantFuture)
|
||||
|
||||
if let concurrencyError = concurrencyError {
|
||||
XCTAssertEqual(concurrencyError.code, 5) // SQLITE_BUSY
|
||||
@@ -252,7 +252,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
|
||||
// Queue 1 Queue 2
|
||||
// BEGIN EXCLUSIVE TRANSACTION
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// (Waiting) BEGIN EXCLUSIVE TRANSACTION <--- Busy
|
||||
// (Waiting) BEGIN EXCLUSIVE TRANSACTION <--- Busy
|
||||
// (Waiting) BEGIN EXCLUSIVE TRANSACTION <--- Busy
|
||||
@@ -267,14 +267,14 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
return true
|
||||
}
|
||||
|
||||
let queue = dispatch_queue_create("GRDB", DISPATCH_QUEUE_CONCURRENT)!
|
||||
let group = dispatch_group_create()!
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Queue 1
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
try dbQueue1.inTransaction(.exclusive) { db in
|
||||
dispatch_semaphore_signal(s1)
|
||||
s1.signal()
|
||||
usleep(100_000) // 0.1s
|
||||
return .commit
|
||||
}
|
||||
@@ -285,9 +285,9 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
// Queue 2
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try dbQueue2.inTransaction(.exclusive) { db in
|
||||
return .commit
|
||||
}
|
||||
@@ -297,7 +297,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER)
|
||||
_ = group.wait(timeout: .distantFuture)
|
||||
|
||||
XCTAssertTrue(numberOfTries > 0) // Busy handler has been used.
|
||||
}
|
||||
@@ -321,50 +321,50 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// Queue 1 Queue 2
|
||||
// BEGIN IMMEDIATE TRANSACTION
|
||||
// INSERT INTO stuffs (id) VALUES (NULL)
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// SELECT * FROM stuffs <--- 0 result
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// COMMIT
|
||||
let s3 = dispatch_semaphore_create(0)!
|
||||
let s3 = DispatchSemaphore(value: 0)
|
||||
// SELECT * FROM stuffs <--- 1 result
|
||||
|
||||
try! dbQueue1.inDatabase { db in
|
||||
try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let queue = dispatch_queue_create("GRDB", DISPATCH_QUEUE_CONCURRENT)!
|
||||
let group = dispatch_group_create()!
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Queue 1
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
try dbQueue1.inTransaction { db in
|
||||
try db.execute("INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
catch {
|
||||
XCTFail("\(error)")
|
||||
}
|
||||
dispatch_semaphore_signal(s3)
|
||||
s3.signal()
|
||||
}
|
||||
|
||||
// Queue 2
|
||||
var rows1: [Row]?
|
||||
var rows2: [Row]?
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
dbQueue2.inDatabase { db in
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
rows1 = Row.fetchAll(db, "SELECT * FROM stuffs")
|
||||
dispatch_semaphore_signal(s2)
|
||||
dispatch_semaphore_wait(s3, DISPATCH_TIME_FOREVER)
|
||||
s2.signal()
|
||||
_ = s3.wait(timeout: .distantFuture)
|
||||
rows2 = Row.fetchAll(db, "SELECT * FROM stuffs")
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER)
|
||||
_ = group.wait(timeout: .distantFuture)
|
||||
|
||||
XCTAssertEqual(rows1!.count, 0) // uncommitted changes are not visible
|
||||
XCTAssertEqual(rows2!.count, 1) // committed changes are visible
|
||||
@@ -395,10 +395,10 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
// Queue 1 Queue 2
|
||||
// BEGIN IMMEDIATE TRANSACTION
|
||||
// INSERT INTO stuffs (id) VALUES (NULL)
|
||||
let s1 = dispatch_semaphore_create(0)!
|
||||
let s1 = DispatchSemaphore(value: 0)
|
||||
// BEGIN DEFERRED TRANSACTION
|
||||
// SELECT * FROM stuffs
|
||||
let s2 = dispatch_semaphore_create(0)!
|
||||
let s2 = DispatchSemaphore(value: 0)
|
||||
// COMMIT <--- Busy (Waiting)
|
||||
// COMMIT <--- Busy (Waiting)
|
||||
// COMMIT
|
||||
@@ -415,16 +415,16 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
let queue = dispatch_queue_create("GRDB", DISPATCH_QUEUE_CONCURRENT)!
|
||||
let group = dispatch_group_create()!
|
||||
let queue = DispatchQueue(label: "GRDB", attributes: [.concurrent])
|
||||
let group = DispatchGroup()
|
||||
|
||||
// Queue 1
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
try dbQueue1.inTransaction { db in
|
||||
try db.execute("INSERT INTO stuffs (id) VALUES (NULL)")
|
||||
dispatch_semaphore_signal(s1)
|
||||
dispatch_semaphore_wait(s2, DISPATCH_TIME_FOREVER)
|
||||
s1.signal()
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
return .commit
|
||||
}
|
||||
}
|
||||
@@ -434,12 +434,12 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
// Queue 2
|
||||
dispatch_group_async(group, queue) {
|
||||
queue.async(group: group) {
|
||||
do {
|
||||
dispatch_semaphore_wait(s1, DISPATCH_TIME_FOREVER)
|
||||
_ = s1.wait(timeout: .distantFuture)
|
||||
try dbQueue2.inTransaction(.deferred) { db in
|
||||
_ = Row.fetchAll(db, "SELECT * FROM stuffs")
|
||||
dispatch_semaphore_signal(s2)
|
||||
s2.signal()
|
||||
usleep(100_000) // 0.1s
|
||||
return .commit
|
||||
}
|
||||
@@ -449,7 +449,7 @@ class ConcurrencyTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER)
|
||||
_ = group.wait(timeout: .distantFuture)
|
||||
|
||||
XCTAssertTrue(numberOfTries > 0) // Busy handler has been used.
|
||||
}
|
||||
|
||||
@@ -11,44 +11,44 @@ class DatabaseQueueFileAttributesTests: GRDBTestCase {
|
||||
|
||||
func testDefaultFileAttributes() {
|
||||
assertNoError {
|
||||
let fm = NSFileManager.default()
|
||||
let fm = FileManager.default()
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
var attributes = try fm.attributesOfItem(atPath: dbQueue.path)
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertFalse((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
}
|
||||
}
|
||||
|
||||
func testExplicitFileAttributesOnExistingFile() {
|
||||
assertNoError {
|
||||
let fm = NSFileManager.default()
|
||||
let fm = FileManager.default()
|
||||
|
||||
do {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let attributes = try fm.attributesOfItem(atPath: dbQueue.path)
|
||||
XCTAssertFalse((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertFalse((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
}
|
||||
|
||||
do {
|
||||
dbConfiguration.fileAttributes = [NSFileExtensionHidden: true]
|
||||
dbConfiguration.fileAttributes = [FileAttributeKey.extensionHidden.rawValue: true]
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
let attributes = try fm.attributesOfItem(atPath: dbQueue.path)
|
||||
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertTrue((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testExplicitFileAttributesOnNewFile() {
|
||||
assertNoError {
|
||||
let fm = NSFileManager.default()
|
||||
let fm = FileManager.default()
|
||||
|
||||
dbConfiguration.fileAttributes = [NSFileExtensionHidden: true]
|
||||
dbConfiguration.fileAttributes = [FileAttributeKey.extensionHidden.rawValue: true]
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
// TODO: this test is fragile: we have to wait until the database
|
||||
// store has been notified of file creation.
|
||||
NSThread.sleep(forTimeInterval: 0.1)
|
||||
Thread.sleep(forTimeInterval: 0.1)
|
||||
var attributes = try fm.attributesOfItem(atPath: dbQueue.path)
|
||||
XCTAssertTrue((attributes[NSFileExtensionHidden] as! NSNumber).boolValue)
|
||||
XCTAssertTrue((attributes[FileAttributeKey.extensionHidden.rawValue] as! NSNumber).boolValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,13 @@ class DatabaseQueueTests: GRDBTestCase {
|
||||
func testInvalidFileFormat() {
|
||||
assertNoError {
|
||||
do {
|
||||
let testBundle = NSBundle(for: self.dynamicType)
|
||||
let path = testBundle.pathForResource("Betty", ofType: "jpeg")!
|
||||
guard Data(contentsOfFile: path) != nil else {
|
||||
let testBundle = Bundle(for: self.dynamicType)
|
||||
let url = testBundle.urlForResource("Betty", withExtension: "jpeg")!
|
||||
guard (try? Data(contentsOf: url)) != nil else {
|
||||
XCTFail("Missing file")
|
||||
return
|
||||
}
|
||||
_ = try DatabaseQueue(path: path)
|
||||
_ = try DatabaseQueue(path: url.path!)
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError {
|
||||
XCTAssertEqual(error.code, 26) // SQLITE_NOTADB
|
||||
|
||||
@@ -25,7 +25,7 @@ class DataTests: GRDBTestCase {
|
||||
XCTFail("Failed to convert from DatabaseValue to Data")
|
||||
return false
|
||||
}
|
||||
return back.isEqual(value)
|
||||
return back == value
|
||||
}
|
||||
|
||||
XCTAssertTrue(roundTrip("bar".data(using: .utf8)!))
|
||||
|
||||
@@ -9,18 +9,18 @@ import XCTest
|
||||
|
||||
struct DatabaseTimestamp: DatabaseValueConvertible {
|
||||
|
||||
// NSDate conversion
|
||||
// Date conversion
|
||||
//
|
||||
// We consistently use the Swift nil to represent the database NULL: the
|
||||
// date property is a non-optional NSDate, and the NSDate initializer is
|
||||
// date property is a non-optional Date, and the Date initializer is
|
||||
// failable:
|
||||
|
||||
/// The represented date
|
||||
let date: NSDate
|
||||
let date: Date
|
||||
|
||||
/// Creates a DatabaseTimestamp from an NSDate.
|
||||
/// Creates a DatabaseTimestamp from an Date.
|
||||
/// The result is nil if and only if *date* is nil.
|
||||
init?(_ date: NSDate?) {
|
||||
init?(_ date: Date?) {
|
||||
guard let date = date else {
|
||||
return nil
|
||||
}
|
||||
@@ -40,10 +40,10 @@ struct DatabaseTimestamp: DatabaseValueConvertible {
|
||||
// Double itself adopts DatabaseValueConvertible. So let's avoid
|
||||
// handling the raw DatabaseValue, and use built-in Double conversion:
|
||||
guard let timeInterval = Double.fromDatabaseValue(databaseValue) else {
|
||||
// No Double, no NSDate!
|
||||
// No Double, no Date!
|
||||
return nil
|
||||
}
|
||||
return DatabaseTimestamp(NSDate(timeIntervalSince1970: timeInterval))
|
||||
return DatabaseTimestamp(Date(timeIntervalSince1970: timeInterval))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class DatabaseTimestampTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE dates (date DATETIME)")
|
||||
let storedDate = NSDate()
|
||||
let storedDate = Date()
|
||||
try db.execute("INSERT INTO dates (date) VALUES (?)", arguments: [DatabaseTimestamp(storedDate)])
|
||||
let fetchedDate = DatabaseTimestamp.fetchOne(db, "SELECT date FROM dates")!.date
|
||||
let delta = storedDate.timeIntervalSince(fetchedDate)
|
||||
|
||||
@@ -210,8 +210,8 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
XCTAssertTrue(String.fromDatabaseValue(dbv) == nil)
|
||||
XCTAssertEqual(Data.fromDatabaseValue(dbv), "foo".data(using: .utf8))
|
||||
|
||||
XCTAssertEqual((dbv.value() as Data?), "foo".data(using: .utf8))
|
||||
XCTAssertTrue((dbv.value() as Data).isEqual(to: "foo".data(using: .utf8)!))
|
||||
XCTAssertEqual((dbv.value() as Data?)!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(dbv.value() as Data, "foo".data(using: .utf8))
|
||||
|
||||
return .rollback
|
||||
}
|
||||
@@ -498,8 +498,8 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
XCTAssertTrue(String.fromDatabaseValue(dbv) == nil)
|
||||
XCTAssertEqual(Data.fromDatabaseValue(dbv), "foo".data(using: .utf8))
|
||||
|
||||
XCTAssertEqual((dbv.value() as Data?), "foo".data(using: .utf8))
|
||||
XCTAssertTrue((dbv.value() as Data).isEqual(to: "foo".data(using: .utf8)!))
|
||||
XCTAssertEqual((dbv.value() as Data?)!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(dbv.value() as Data, "foo".data(using: .utf8))
|
||||
|
||||
return .rollback
|
||||
}
|
||||
@@ -674,8 +674,8 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
XCTAssertTrue(String.fromDatabaseValue(dbv) == nil)
|
||||
XCTAssertEqual(Data.fromDatabaseValue(dbv), "foo".data(using: .utf8))
|
||||
|
||||
XCTAssertEqual((dbv.value() as Data?), "foo".data(using: .utf8))
|
||||
XCTAssertTrue((dbv.value() as Data).isEqual(to: "foo".data(using: .utf8)!))
|
||||
XCTAssertEqual((dbv.value() as Data?)!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(dbv.value() as Data, "foo".data(using: .utf8))
|
||||
|
||||
return .rollback
|
||||
}
|
||||
@@ -936,8 +936,8 @@ class DatabaseValueConversionTests : GRDBTestCase {
|
||||
XCTAssertTrue(String.fromDatabaseValue(dbv) == nil)
|
||||
XCTAssertEqual(Data.fromDatabaseValue(dbv), "foo".data(using: .utf8))
|
||||
|
||||
XCTAssertEqual((dbv.value() as Data?), "foo".data(using: .utf8))
|
||||
XCTAssertTrue((dbv.value() as Data).isEqual(to: "foo".data(using: .utf8)!))
|
||||
XCTAssertEqual((dbv.value() as Data?)!, "foo".data(using: .utf8))
|
||||
XCTAssertEqual(dbv.value() as Data, "foo".data(using: .utf8))
|
||||
|
||||
return .rollback
|
||||
}
|
||||
|
||||
+42
-42
@@ -7,7 +7,7 @@ import XCTest
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
class NSDateComponentsTests : GRDBTestCase {
|
||||
class DateComponentsTests : GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
@@ -26,7 +26,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -41,13 +41,13 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
|
||||
let databaseDateComponents = DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")!
|
||||
XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.HM)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.year, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.month, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.day, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.year == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.month == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.day == nil)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.nanosecond, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.second == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.nanosecond == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -72,13 +72,13 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
|
||||
let databaseDateComponents = DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")!
|
||||
XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.HMS)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.year, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.month, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.day, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.year == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.month == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.day == nil)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, dateComponents.second)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.nanosecond, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.nanosecond == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -103,13 +103,13 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
|
||||
let databaseDateComponents = DatabaseDateComponents.fetchOne(db, "SELECT creationDate FROM dates")!
|
||||
XCTAssertEqual(databaseDateComponents.format, DatabaseDateComponents.Format.HMSS)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.year, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.month, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.day, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.year == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.month == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.day == nil)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, dateComponents.second)
|
||||
XCTAssertEqual(round(Double(databaseDateComponents.dateComponents.nanosecond) / 1.0e6), round(Double(dateComponents.nanosecond) / 1.0e6))
|
||||
XCTAssertEqual(round(Double(databaseDateComponents.dateComponents.nanosecond!) / 1.0e6), round(Double(dateComponents.nanosecond!) / 1.0e6))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -137,10 +137,10 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.year, dateComponents.year)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.month, dateComponents.month)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.day, dateComponents.day)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.nanosecond, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.hour == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.minute == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.second == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.nanosecond == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -170,8 +170,8 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.day, dateComponents.day)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.nanosecond, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.second == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.nanosecond == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +181,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -202,7 +202,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, dateComponents.second)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.nanosecond, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.nanosecond == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -233,7 +233,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, dateComponents.second)
|
||||
XCTAssertEqual(round(Double(databaseDateComponents.dateComponents.nanosecond) / 1.0e6), round(Double(dateComponents.nanosecond) / 1.0e6))
|
||||
XCTAssertEqual(round(Double(databaseDateComponents.dateComponents.nanosecond!) / 1.0e6), round(Double(dateComponents.nanosecond!) / 1.0e6))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
let dateComponents = DateComponents()
|
||||
try db.execute("INSERT INTO dates (creationDate) VALUES (?)", arguments: [DatabaseDateComponents(dateComponents, format: .YMD_HMSS)])
|
||||
|
||||
let string = String.fetchOne(db, "SELECT creationDate from dates")!
|
||||
@@ -267,7 +267,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -284,8 +284,8 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.day, dateComponents.day)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, NSDateComponentUndefined)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.nanosecond, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.second == nil)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.nanosecond == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,7 +295,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -313,7 +313,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, dateComponents.second)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.nanosecond, NSDateComponentUndefined)
|
||||
XCTAssertTrue(databaseDateComponents.dateComponents.nanosecond == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -323,7 +323,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let dateComponents = NSDateComponents()
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -341,7 +341,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.hour, dateComponents.hour)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.minute, dateComponents.minute)
|
||||
XCTAssertEqual(databaseDateComponents.dateComponents.second, dateComponents.second)
|
||||
XCTAssertEqual(round(Double(databaseDateComponents.dateComponents.nanosecond) / 1.0e6), round(Double(dateComponents.nanosecond) / 1.0e6))
|
||||
XCTAssertEqual(round(Double(databaseDateComponents.dateComponents.nanosecond!) / 1.0e6), round(Double(dateComponents.nanosecond!) / 1.0e6))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -350,10 +350,10 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
do {
|
||||
let date = NSDate().addingTimeInterval(-1)
|
||||
let date = Date().addingTimeInterval(-1)
|
||||
let dateComponents = calendar.components([.year, .month, .day, .hour, .minute, .second], from: date)
|
||||
try db.execute(
|
||||
"INSERT INTO dates (id, creationDate) VALUES (?,?)",
|
||||
@@ -365,7 +365,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
arguments: [2])
|
||||
}
|
||||
do {
|
||||
let date = NSDate().addingTimeInterval(1)
|
||||
let date = Date().addingTimeInterval(1)
|
||||
let dateComponents = calendar.components([.year, .month, .day, .hour, .minute, .second], from: date)
|
||||
try db.execute(
|
||||
"INSERT INTO dates (id, creationDate) VALUES (?,?)",
|
||||
@@ -383,7 +383,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
XCTAssertTrue(databaseDateComponents == nil)
|
||||
}
|
||||
|
||||
func testDatabaseDateComponentsFailureFromNilNSDateComponents() {
|
||||
func testDatabaseDateComponentsFailureFromNilDateComponents() {
|
||||
XCTAssertNil(DatabaseDateComponents(nil, format: .YMD))
|
||||
}
|
||||
}
|
||||
+51
-51
@@ -7,7 +7,7 @@ import XCTest
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
class NSDateTests : GRDBTestCase {
|
||||
class DateTests : GRDBTestCase {
|
||||
|
||||
override func setup(_ dbWriter: DatabaseWriter) throws {
|
||||
var migrator = DatabaseMigrator()
|
||||
@@ -21,13 +21,13 @@ class NSDateTests : GRDBTestCase {
|
||||
try migrator.migrate(dbWriter)
|
||||
}
|
||||
|
||||
func testNSDate() {
|
||||
func testDate() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
let dateComponents = NSDateComponents()
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.year = 1973
|
||||
dateComponents.month = 9
|
||||
dateComponents.day = 18
|
||||
@@ -42,7 +42,7 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
|
||||
do {
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate FROM dates")!
|
||||
let date = Date.fetchOne(db, "SELECT creationDate FROM dates")!
|
||||
// All components must be preserved, but nanosecond since ISO-8601 stores milliseconds.
|
||||
XCTAssertEqual(calendar.component(.year, from: date), dateComponents.year)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), dateComponents.month)
|
||||
@@ -50,19 +50,19 @@ class NSDateTests : GRDBTestCase {
|
||||
XCTAssertEqual(calendar.component(.hour, from: date), dateComponents.hour)
|
||||
XCTAssertEqual(calendar.component(.minute, from: date), dateComponents.minute)
|
||||
XCTAssertEqual(calendar.component(.second, from: date), dateComponents.second)
|
||||
XCTAssertEqual(round(Double(calendar.component(.nanosecond, from: date)) / 1.0e6), round(Double(dateComponents.nanosecond) / 1.0e6))
|
||||
XCTAssertEqual(round(Double(calendar.component(.nanosecond, from: date)) / 1.0e6), round(Double(dateComponents.nanosecond!) / 1.0e6))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateIsLexicallyComparableToCURRENT_TIMESTAMP() {
|
||||
func testDateIsLexicallyComparableToCURRENT_TIMESTAMP() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (id, creationDate) VALUES (?,?)",
|
||||
arguments: [1, NSDate().addingTimeInterval(-1)])
|
||||
arguments: [1, Date().addingTimeInterval(-1)])
|
||||
|
||||
try db.execute(
|
||||
"INSERT INTO dates (id) VALUES (?)",
|
||||
@@ -70,7 +70,7 @@ class NSDateTests : GRDBTestCase {
|
||||
|
||||
try db.execute(
|
||||
"INSERT INTO dates (id, creationDate) VALUES (?,?)",
|
||||
arguments: [3, NSDate().addingTimeInterval(1)])
|
||||
arguments: [3, Date().addingTimeInterval(1)])
|
||||
|
||||
let ids = Int.fetchAll(db, "SELECT id FROM dates ORDER BY creationDate")
|
||||
XCTAssertEqual(ids, [1,2,3])
|
||||
@@ -78,60 +78,60 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateFromUnparsableString() {
|
||||
let date = NSDate.fromDatabaseValue("foo".databaseValue)
|
||||
func testDateFromUnparsableString() {
|
||||
let date = Date.fromDatabaseValue("foo".databaseValue)
|
||||
XCTAssertTrue(date == nil)
|
||||
}
|
||||
|
||||
func testNSDateDoesNotAcceptFormatHM() {
|
||||
func testDateDoesNotAcceptFormatHM() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["01:02"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")
|
||||
XCTAssertTrue(date == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateDoesNotAcceptFormatHMS() {
|
||||
func testDateDoesNotAcceptFormatHMS() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["01:02:03"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")
|
||||
XCTAssertTrue(date == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateDoesNotAcceptFormatHMSS() {
|
||||
func testDateDoesNotAcceptFormatHMSS() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["01:02:03.00456"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")
|
||||
XCTAssertTrue(date == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateAcceptsFormatYMD() {
|
||||
func testDateAcceptsFormatYMD() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["2015-07-22"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
XCTAssertEqual(calendar.component(.year, from: date), 2015)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), 7)
|
||||
XCTAssertEqual(calendar.component(.day, from: date), 22)
|
||||
@@ -143,16 +143,16 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateAcceptsFormatYMD_HM() {
|
||||
func testDateAcceptsFormatYMD_HM() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["2015-07-22 01:02"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
XCTAssertEqual(calendar.component(.year, from: date), 2015)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), 7)
|
||||
XCTAssertEqual(calendar.component(.day, from: date), 22)
|
||||
@@ -164,16 +164,16 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateAcceptsFormatYMD_HMS() {
|
||||
func testDateAcceptsFormatYMD_HMS() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["2015-07-22 01:02:03"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
XCTAssertEqual(calendar.component(.year, from: date), 2015)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), 7)
|
||||
XCTAssertEqual(calendar.component(.day, from: date), 22)
|
||||
@@ -185,28 +185,28 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateAcceptsFormatYMD_HMSS() {
|
||||
func testDateAcceptsFormatYMD_HMSS() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["2015-07-22 01:02:03.00456"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
XCTAssertEqual(calendar.component(.year, from: date), 2015)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), 7)
|
||||
XCTAssertEqual(calendar.component(.day, from: date), 22)
|
||||
XCTAssertEqual(calendar.component(.hour, from: date), 1)
|
||||
XCTAssertEqual(calendar.component(.minute, from: date), 2)
|
||||
XCTAssertEqual(calendar.component(.second, from: date), 3)
|
||||
XCTAssertTrue(abs(calendar.component(.nanosecond, from: date) - 4_000_000) < 10) // We actually get 4_000_008. Some precision is lost during the NSDateComponents -> NSDate conversion. Not a big deal.
|
||||
XCTAssertTrue(abs(calendar.component(.nanosecond, from: date) - 4_000_000) < 10) // We actually get 4_000_008. Some precision is lost during the DateComponents -> Date conversion. Not a big deal.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateAcceptsJulianDayNumber() {
|
||||
func testDateAcceptsJulianDayNumber() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -218,9 +218,9 @@ class NSDateTests : GRDBTestCase {
|
||||
let string = String.fetchOne(db, "SELECT datetime(creationDate) from dates")!
|
||||
XCTAssertEqual(string, "2013-01-01 00:29:59")
|
||||
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
XCTAssertEqual(calendar.component(.year, from: date), 2013)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), 1)
|
||||
XCTAssertEqual(calendar.component(.day, from: date), 1)
|
||||
@@ -231,16 +231,16 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateAcceptsFormatIso8601YMD_HM() {
|
||||
func testDateAcceptsFormatIso8601YMD_HM() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["2015-07-22T01:02"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
XCTAssertEqual(calendar.component(.year, from: date), 2015)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), 7)
|
||||
XCTAssertEqual(calendar.component(.day, from: date), 22)
|
||||
@@ -252,16 +252,16 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateAcceptsFormatIso8601YMD_HMS() {
|
||||
func testDateAcceptsFormatIso8601YMD_HMS() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["2015-07-22T01:02:03"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
XCTAssertEqual(calendar.component(.year, from: date), 2015)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), 7)
|
||||
XCTAssertEqual(calendar.component(.day, from: date), 22)
|
||||
@@ -273,23 +273,23 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testNSDateAcceptsFormatIso8601YMD_HMSS() {
|
||||
func testDateAcceptsFormatIso8601YMD_HMSS() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute(
|
||||
"INSERT INTO dates (creationDate) VALUES (?)",
|
||||
arguments: ["2015-07-22T01:02:03.00456"])
|
||||
let date = NSDate.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
|
||||
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
let date = Date.fetchOne(db, "SELECT creationDate from dates")!
|
||||
let calendar = Calendar(calendarIdentifier: .gregorian)!
|
||||
calendar.timeZone = TimeZone(forSecondsFromGMT: 0)
|
||||
XCTAssertEqual(calendar.component(.year, from: date), 2015)
|
||||
XCTAssertEqual(calendar.component(.month, from: date), 7)
|
||||
XCTAssertEqual(calendar.component(.day, from: date), 22)
|
||||
XCTAssertEqual(calendar.component(.hour, from: date), 1)
|
||||
XCTAssertEqual(calendar.component(.minute, from: date), 2)
|
||||
XCTAssertEqual(calendar.component(.second, from: date), 3)
|
||||
XCTAssertTrue(abs(calendar.component(.nanosecond, from: date) - 4_000_000) < 10) // We actually get 4_000_008. Some precision is lost during the NSDateComponents -> NSDate conversion. Not a big deal.
|
||||
XCTAssertTrue(abs(calendar.component(.nanosecond, from: date) - 4_000_000) < 10) // We actually get 4_000_008. Some precision is lost during the DateComponents -> Date conversion. Not a big deal.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class RowFoundationTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testRowToNSDictionary() {
|
||||
let row = Row(["a": "foo", "b": 1, "c": nil, "d": NSDate(timeIntervalSince1970: 1443642439)])
|
||||
let row = Row(["a": "foo", "b": 1, "c": nil, "d": Date(timeIntervalSince1970: 1443642439)])
|
||||
let dictionary = row.toNSDictionary()
|
||||
XCTAssertEqual(dictionary.count, 4)
|
||||
XCTAssertTrue((dictionary["a"] as! NSString).isEqual(to: "foo"))
|
||||
|
||||
@@ -12,9 +12,9 @@ private class Person : Record {
|
||||
var id: Int64!
|
||||
var name: String!
|
||||
var age: Int?
|
||||
var creationDate: NSDate!
|
||||
var creationDate: Date!
|
||||
|
||||
init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: NSDate? = nil) {
|
||||
init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: Date? = nil) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.age = age
|
||||
@@ -58,7 +58,7 @@ private class Person : Record {
|
||||
override func insert(_ db: Database) throws {
|
||||
// This is implicitely tested with the NOT NULL constraint on creationDate
|
||||
if creationDate == nil {
|
||||
creationDate = NSDate()
|
||||
creationDate = Date()
|
||||
}
|
||||
|
||||
try super.insert(db)
|
||||
|
||||
@@ -11,9 +11,9 @@ private class Person : Record {
|
||||
var id: Int64!
|
||||
var name: String!
|
||||
var age: Int?
|
||||
var creationDate: NSDate
|
||||
var creationDate: Date
|
||||
|
||||
init(id: Int64?, name: String?, age: Int?, creationDate: NSDate) {
|
||||
init(id: Int64?, name: String?, age: Int?, creationDate: Date) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.age = age
|
||||
@@ -44,7 +44,7 @@ private class Person : Record {
|
||||
class RecordCopyTests: GRDBTestCase {
|
||||
|
||||
func testRecordCopy() {
|
||||
let person1 = Person(id: 123, name: "Arthur", age: 41, creationDate: NSDate())
|
||||
let person1 = Person(id: 123, name: "Arthur", age: 41, creationDate: Date())
|
||||
let person2 = person1.copy()
|
||||
XCTAssertTrue(person2.id == person1.id)
|
||||
XCTAssertTrue(person2.name == person1.name)
|
||||
|
||||
@@ -11,9 +11,9 @@ private class Person : Record {
|
||||
var id: Int64!
|
||||
var name: String!
|
||||
var age: Int?
|
||||
var creationDate: NSDate!
|
||||
var creationDate: Date!
|
||||
|
||||
init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: NSDate? = nil) {
|
||||
init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: Date? = nil) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.age = age
|
||||
@@ -57,7 +57,7 @@ private class Person : Record {
|
||||
override func insert(_ db: Database) throws {
|
||||
// This is implicitely tested with the NOT NULL constraint on creationDate
|
||||
if creationDate == nil {
|
||||
creationDate = NSDate()
|
||||
creationDate = Date()
|
||||
}
|
||||
|
||||
try super.insert(db)
|
||||
@@ -92,9 +92,9 @@ private class PersonWithModifiedCaseColumns: Record {
|
||||
var id: Int64!
|
||||
var name: String!
|
||||
var age: Int?
|
||||
var creationDate: NSDate!
|
||||
var creationDate: Date!
|
||||
|
||||
init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: NSDate? = nil) {
|
||||
init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: Date? = nil) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.age = age
|
||||
@@ -128,7 +128,7 @@ private class PersonWithModifiedCaseColumns: Record {
|
||||
override func insert(_ db: Database) throws {
|
||||
// This is implicitely tested with the NOT NULL constraint on creationDate
|
||||
if creationDate == nil {
|
||||
creationDate = NSDate()
|
||||
creationDate = Date()
|
||||
}
|
||||
|
||||
try super.insert(db)
|
||||
@@ -620,7 +620,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
case "age":
|
||||
XCTAssertEqual(old, DatabaseValue.null)
|
||||
case "creationDate":
|
||||
XCTAssertTrue((old?.value() as NSDate?) != nil)
|
||||
XCTAssertTrue((old?.value() as Date?) != nil)
|
||||
default:
|
||||
XCTFail("Unexpected column: \(column)")
|
||||
}
|
||||
@@ -642,7 +642,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
case "AGE":
|
||||
XCTAssertEqual(old, DatabaseValue.null)
|
||||
case "CREATIONDATE":
|
||||
XCTAssertTrue((old?.value() as NSDate?) != nil)
|
||||
XCTAssertTrue((old?.value() as Date?) != nil)
|
||||
default:
|
||||
XCTFail("Unexpected column: \(column)")
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ private class Person : Record {
|
||||
var id: Int64!
|
||||
var name: String!
|
||||
var age: Int?
|
||||
var creationDate: NSDate!
|
||||
var creationDate: Date!
|
||||
|
||||
init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: NSDate? = nil) {
|
||||
init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: Date? = nil) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.age = age
|
||||
@@ -57,7 +57,7 @@ private class Person : Record {
|
||||
override func insert(_ db: Database) throws {
|
||||
// This is implicitely tested with the NOT NULL constraint on creationDate
|
||||
if creationDate == nil {
|
||||
creationDate = NSDate()
|
||||
creationDate = Date()
|
||||
}
|
||||
|
||||
try super.insert(db)
|
||||
@@ -88,7 +88,7 @@ private class PersonWithOverrides : Person {
|
||||
var extra: Int!
|
||||
var lastSavingMethod: SavingMethod?
|
||||
|
||||
override init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: NSDate? = nil) {
|
||||
override init(id: Int64? = nil, name: String? = nil, age: Int? = nil, creationDate: Date? = nil) {
|
||||
super.init(id: id, name: name, age: age, creationDate: creationDate)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user