motion-yapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (348) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +5 -0
  5. data/Gemfile.lock +63 -0
  6. data/README.md +16 -0
  7. data/Rakefile +20 -0
  8. data/app/app_delegate.rb +5 -0
  9. data/lib/yapper.rb +30 -0
  10. data/lib/yapper/attachment.rb +48 -0
  11. data/lib/yapper/bson.rb +20 -0
  12. data/lib/yapper/config.rb +18 -0
  13. data/lib/yapper/db.rb +151 -0
  14. data/lib/yapper/document.rb +54 -0
  15. data/lib/yapper/document/attachment.rb +26 -0
  16. data/lib/yapper/document/callbacks.rb +86 -0
  17. data/lib/yapper/document/persistance.rb +171 -0
  18. data/lib/yapper/document/relation.rb +84 -0
  19. data/lib/yapper/document/selection.rb +100 -0
  20. data/lib/yapper/extensions.rb +80 -0
  21. data/lib/yapper/log.rb +5 -0
  22. data/lib/yapper/sync.rb +134 -0
  23. data/lib/yapper/sync/data.rb +12 -0
  24. data/lib/yapper/sync/event.rb +194 -0
  25. data/lib/yapper/sync/queue.rb +164 -0
  26. data/lib/yapper/timestamps.rb +16 -0
  27. data/lib/yapper/version.rb +3 -0
  28. data/lib/yapper/yapper.rb +2 -0
  29. data/spec/helpers/time_helper.rb +3 -0
  30. data/spec/integration/all_spec.rb +40 -0
  31. data/spec/integration/callback_spec.rb +87 -0
  32. data/spec/integration/db_spec.rb +40 -0
  33. data/spec/integration/find_spec.rb +51 -0
  34. data/spec/integration/persistance_spec.rb +118 -0
  35. data/spec/integration/relation_spec.rb +174 -0
  36. data/spec/integration/sync_spec.rb +42 -0
  37. data/spec/integration/timestamps_spec.rb +34 -0
  38. data/spec/integration/types_spec.rb +23 -0
  39. data/spec/integration/when_spec.rb +29 -0
  40. data/spec/integration/where_spec.rb +132 -0
  41. data/vendor/Podfile.lock +24 -0
  42. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +641 -0
  43. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1396 -0
  44. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
  45. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +327 -0
  46. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +113 -0
  47. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +321 -0
  48. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
  49. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +150 -0
  50. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  51. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +157 -0
  52. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +43 -0
  53. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  54. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +143 -0
  55. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +370 -0
  56. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +848 -0
  57. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
  58. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +167 -0
  59. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
  60. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +191 -0
  61. data/vendor/Pods/AFNetworking/LICENSE +19 -0
  62. data/vendor/Pods/AFNetworking/README.md +208 -0
  63. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +641 -0
  64. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
  65. data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +113 -0
  66. data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
  67. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  68. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +43 -0
  69. data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  70. data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +370 -0
  71. data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
  72. data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
  73. data/vendor/Pods/BuildHeaders/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
  74. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +41 -0
  75. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
  76. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +334 -0
  77. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +601 -0
  78. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +167 -0
  79. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
  80. data/vendor/Pods/BuildHeaders/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  81. data/vendor/Pods/BuildHeaders/Reachability/Reachability.h +109 -0
  82. data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +90 -0
  83. data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +20 -0
  84. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +547 -0
  85. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +447 -0
  86. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnectionState.h +29 -0
  87. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +37 -0
  88. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtension.h +15 -0
  89. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
  90. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
  91. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
  92. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +108 -0
  93. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
  94. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
  95. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
  96. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
  97. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
  98. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
  99. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  100. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
  101. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseLogging.h +158 -0
  102. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseManager.h +17 -0
  103. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +424 -0
  104. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseQuery.h +42 -0
  105. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
  106. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
  107. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
  108. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
  109. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
  110. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseStatement.h +13 -0
  111. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseString.h +121 -0
  112. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +541 -0
  113. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +186 -0
  114. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +272 -0
  115. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
  116. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +115 -0
  117. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +825 -0
  118. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
  119. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +56 -0
  120. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPage.h +36 -0
  121. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
  122. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +153 -0
  123. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
  124. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  125. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +447 -0
  126. data/vendor/Pods/BuildHeaders/YapDatabase/YapMemoryTable.h +74 -0
  127. data/vendor/Pods/BuildHeaders/YapDatabase/YapNull.h +17 -0
  128. data/vendor/Pods/BuildHeaders/YapDatabase/YapSet.h +41 -0
  129. data/vendor/Pods/BuildHeaders/YapDatabase/YapTouch.h +15 -0
  130. data/vendor/Pods/CocoaLumberjack/LICENSE.txt +18 -0
  131. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +41 -0
  132. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +99 -0
  133. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
  134. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
  135. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +334 -0
  136. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1353 -0
  137. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +601 -0
  138. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +1083 -0
  139. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +167 -0
  140. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +1479 -0
  141. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
  142. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
  143. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
  144. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
  145. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +7 -0
  146. data/vendor/Pods/CocoaLumberjack/README.markdown +37 -0
  147. data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +641 -0
  148. data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
  149. data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +113 -0
  150. data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
  151. data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  152. data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +43 -0
  153. data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  154. data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +370 -0
  155. data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
  156. data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
  157. data/vendor/Pods/Headers/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
  158. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +41 -0
  159. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
  160. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +334 -0
  161. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +601 -0
  162. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +167 -0
  163. data/vendor/Pods/Headers/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
  164. data/vendor/Pods/Headers/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  165. data/vendor/Pods/Headers/Reachability/Reachability.h +109 -0
  166. data/vendor/Pods/Headers/YapDatabase/YapCache.h +90 -0
  167. data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +20 -0
  168. data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +547 -0
  169. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +447 -0
  170. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnectionState.h +29 -0
  171. data/vendor/Pods/Headers/YapDatabase/YapDatabaseDefaults.h +37 -0
  172. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtension.h +15 -0
  173. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
  174. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
  175. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
  176. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +108 -0
  177. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
  178. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
  179. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
  180. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
  181. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
  182. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
  183. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  184. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
  185. data/vendor/Pods/Headers/YapDatabase/YapDatabaseLogging.h +158 -0
  186. data/vendor/Pods/Headers/YapDatabase/YapDatabaseManager.h +17 -0
  187. data/vendor/Pods/Headers/YapDatabase/YapDatabasePrivate.h +424 -0
  188. data/vendor/Pods/Headers/YapDatabase/YapDatabaseQuery.h +42 -0
  189. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
  190. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
  191. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
  192. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
  193. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
  194. data/vendor/Pods/Headers/YapDatabase/YapDatabaseStatement.h +13 -0
  195. data/vendor/Pods/Headers/YapDatabase/YapDatabaseString.h +121 -0
  196. data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +541 -0
  197. data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +186 -0
  198. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +272 -0
  199. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
  200. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +115 -0
  201. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +825 -0
  202. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
  203. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +56 -0
  204. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPage.h +36 -0
  205. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
  206. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPrivate.h +153 -0
  207. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
  208. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  209. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +447 -0
  210. data/vendor/Pods/Headers/YapDatabase/YapMemoryTable.h +74 -0
  211. data/vendor/Pods/Headers/YapDatabase/YapNull.h +17 -0
  212. data/vendor/Pods/Headers/YapDatabase/YapSet.h +41 -0
  213. data/vendor/Pods/Headers/YapDatabase/YapTouch.h +15 -0
  214. data/vendor/Pods/Headers/____Pods-AFNetworking-prefix.h +17 -0
  215. data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +5 -0
  216. data/vendor/Pods/Headers/____Pods-NSData+MD5Digest-prefix.h +5 -0
  217. data/vendor/Pods/Headers/____Pods-Reachability-prefix.h +5 -0
  218. data/vendor/Pods/Headers/____Pods-YapDatabase-prefix.h +5 -0
  219. data/vendor/Pods/Headers/____Pods-environment.h +38 -0
  220. data/vendor/Pods/Manifest.lock +24 -0
  221. data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  222. data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.m +39 -0
  223. data/vendor/Pods/NSData+MD5Digest/README.md +11 -0
  224. data/vendor/Pods/Pods-AFNetworking-Private.xcconfig +5 -0
  225. data/vendor/Pods/Pods-AFNetworking-dummy.m +5 -0
  226. data/vendor/Pods/Pods-AFNetworking-prefix.pch +17 -0
  227. data/vendor/Pods/Pods-AFNetworking.xcconfig +1 -0
  228. data/vendor/Pods/Pods-Acknowledgements.markdown +96 -0
  229. data/vendor/Pods/Pods-Acknowledgements.plist +142 -0
  230. data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +5 -0
  231. data/vendor/Pods/Pods-CocoaLumberjack-dummy.m +5 -0
  232. data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +5 -0
  233. data/vendor/Pods/Pods-CocoaLumberjack.xcconfig +0 -0
  234. data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +5 -0
  235. data/vendor/Pods/Pods-NSData+MD5Digest-dummy.m +5 -0
  236. data/vendor/Pods/Pods-NSData+MD5Digest-prefix.pch +5 -0
  237. data/vendor/Pods/Pods-NSData+MD5Digest.xcconfig +0 -0
  238. data/vendor/Pods/Pods-Reachability-Private.xcconfig +5 -0
  239. data/vendor/Pods/Pods-Reachability-dummy.m +5 -0
  240. data/vendor/Pods/Pods-Reachability-prefix.pch +5 -0
  241. data/vendor/Pods/Pods-Reachability.xcconfig +1 -0
  242. data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +5 -0
  243. data/vendor/Pods/Pods-YapDatabase-dummy.m +5 -0
  244. data/vendor/Pods/Pods-YapDatabase-prefix.pch +5 -0
  245. data/vendor/Pods/Pods-YapDatabase.xcconfig +1 -0
  246. data/vendor/Pods/Pods-dummy.m +5 -0
  247. data/vendor/Pods/Pods-environment.h +38 -0
  248. data/vendor/Pods/Pods-resources.sh +68 -0
  249. data/vendor/Pods/Pods.bridgesupport +5096 -0
  250. data/vendor/Pods/Pods.xcconfig +5 -0
  251. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +5536 -0
  252. data/vendor/Pods/Reachability/LICENCE.txt +24 -0
  253. data/vendor/Pods/Reachability/README.md +65 -0
  254. data/vendor/Pods/Reachability/Reachability.h +109 -0
  255. data/vendor/Pods/Reachability/Reachability.m +527 -0
  256. data/vendor/Pods/YapDatabase/LICENSE.txt +18 -0
  257. data/vendor/Pods/YapDatabase/README.md +30 -0
  258. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +19 -0
  259. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +108 -0
  260. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +175 -0
  261. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.h +12 -0
  262. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.m +41 -0
  263. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +39 -0
  264. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +966 -0
  265. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +69 -0
  266. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.h +89 -0
  267. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.m +146 -0
  268. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.h +32 -0
  269. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +298 -0
  270. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  271. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.m +95 -0
  272. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.h +68 -0
  273. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +1352 -0
  274. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +440 -0
  275. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.h +15 -0
  276. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +58 -0
  277. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.h +11 -0
  278. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +46 -0
  279. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.h +11 -0
  280. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +180 -0
  281. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +73 -0
  282. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +100 -0
  283. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +149 -0
  284. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.h +33 -0
  285. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +330 -0
  286. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.h +33 -0
  287. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +184 -0
  288. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.h +58 -0
  289. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +1166 -0
  290. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewChangePrivate.h +94 -0
  291. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewMappingsPrivate.h +72 -0
  292. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.h +36 -0
  293. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.mm +296 -0
  294. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.h +27 -0
  295. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.m +28 -0
  296. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +153 -0
  297. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  298. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +272 -0
  299. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +2494 -0
  300. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +825 -0
  301. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +1567 -0
  302. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.h +330 -0
  303. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.m +141 -0
  304. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +186 -0
  305. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +191 -0
  306. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +115 -0
  307. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +897 -0
  308. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +56 -0
  309. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.m +27 -0
  310. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +447 -0
  311. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +4505 -0
  312. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +90 -0
  313. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +453 -0
  314. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.h +29 -0
  315. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.m +48 -0
  316. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +37 -0
  317. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +83 -0
  318. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.h +158 -0
  319. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.m +73 -0
  320. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.h +17 -0
  321. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.m +56 -0
  322. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +424 -0
  323. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.h +13 -0
  324. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.m +26 -0
  325. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseString.h +121 -0
  326. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.h +74 -0
  327. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.m +603 -0
  328. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.h +17 -0
  329. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +31 -0
  330. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.h +15 -0
  331. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.m +31 -0
  332. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +20 -0
  333. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +194 -0
  334. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.h +42 -0
  335. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.m +96 -0
  336. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.h +41 -0
  337. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.m +82 -0
  338. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +547 -0
  339. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +2022 -0
  340. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +447 -0
  341. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +3874 -0
  342. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +541 -0
  343. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +5282 -0
  344. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +16 -0
  345. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +13 -0
  346. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +20 -0
  347. data/yapper.gemspec +24 -0
  348. metadata +458 -0
@@ -0,0 +1,897 @@
1
+ #import "YapDatabaseViewConnection.h"
2
+ #import "YapDatabaseViewPrivate.h"
3
+ #import "YapDatabaseExtensionPrivate.h"
4
+ #import "YapDatabasePrivate.h"
5
+ #import "YapDatabaseViewPage.h"
6
+ #import "YapDatabaseViewChange.h"
7
+ #import "YapDatabaseViewChangePrivate.h"
8
+ #import "YapCollectionKey.h"
9
+ #import "YapCache.h"
10
+ #import "YapDatabaseString.h"
11
+ #import "YapDatabaseLogging.h"
12
+
13
+ #if ! __has_feature(objc_arc)
14
+ #warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
15
+ #endif
16
+
17
+ /**
18
+ * Define log level for this file: OFF, ERROR, WARN, INFO, VERBOSE
19
+ * See YapDatabaseLogging.h for more information.
20
+ **/
21
+ #if DEBUG
22
+ static const int ydbLogLevel = YDB_LOG_LEVEL_WARN;
23
+ #else
24
+ static const int ydbLogLevel = YDB_LOG_LEVEL_WARN;
25
+ #endif
26
+
27
+ static NSString *const key_dirtyMaps = @"dirtyMaps";
28
+ static NSString *const key_dirtyPages = @"dirtyPages";
29
+ static NSString *const key_reset = @"reset";
30
+ static NSString *const key_group_pagesMetadata_dict = @"group_pagesMetadata_dict";
31
+ static NSString *const key_pageKey_group_dict = @"pageKey_group_dict";
32
+ static NSString *const key_changes = @"changes";
33
+
34
+ @implementation YapDatabaseViewConnection
35
+ {
36
+ id sharedKeySetForInternalChangeset;
37
+ id sharedKeySetForExternalChangeset;
38
+
39
+ sqlite3_stmt *mapTable_getPageKeyForRowidStatement;
40
+ sqlite3_stmt *mapTable_setPageKeyForRowidStatement;
41
+ sqlite3_stmt *mapTable_removeForRowidStatement;
42
+ sqlite3_stmt *mapTable_removeAllStatement;
43
+
44
+ sqlite3_stmt *pageTable_getDataForPageKeyStatement;
45
+ sqlite3_stmt *pageTable_insertForPageKeyStatement;
46
+ sqlite3_stmt *pageTable_updateAllForPageKeyStatement;
47
+ sqlite3_stmt *pageTable_updatePageForPageKeyStatement;
48
+ sqlite3_stmt *pageTable_updateLinkForPageKeyStatement;
49
+ sqlite3_stmt *pageTable_removeForPageKeyStatement;
50
+ sqlite3_stmt *pageTable_removeAllStatement;
51
+ }
52
+
53
+ @synthesize view = view;
54
+
55
+ - (id)initWithView:(YapDatabaseView *)inView databaseConnection:(YapDatabaseConnection *)inDbC
56
+ {
57
+ if ((self = [super init]))
58
+ {
59
+ view = inView;
60
+ databaseConnection = inDbC;
61
+
62
+ mapCache = [[YapCache alloc] initWithKeyClass:[NSNumber class]];
63
+ pageCache = [[YapCache alloc] initWithKeyClass:[NSString class]];
64
+
65
+ sharedKeySetForInternalChangeset = [NSDictionary sharedKeySetForKeys:[self internalChangesetKeys]];
66
+ sharedKeySetForExternalChangeset = [NSDictionary sharedKeySetForKeys:[self externalChangesetKeys]];
67
+ }
68
+ return self;
69
+ }
70
+
71
+ - (void)dealloc
72
+ {
73
+ sqlite_finalize_null(&mapTable_getPageKeyForRowidStatement);
74
+ sqlite_finalize_null(&mapTable_setPageKeyForRowidStatement);
75
+ sqlite_finalize_null(&mapTable_removeForRowidStatement);
76
+ sqlite_finalize_null(&mapTable_removeAllStatement);
77
+
78
+ sqlite_finalize_null(&pageTable_getDataForPageKeyStatement);
79
+ sqlite_finalize_null(&pageTable_insertForPageKeyStatement);
80
+ sqlite_finalize_null(&pageTable_updateAllForPageKeyStatement);
81
+ sqlite_finalize_null(&pageTable_updatePageForPageKeyStatement);
82
+ sqlite_finalize_null(&pageTable_updateLinkForPageKeyStatement);
83
+ sqlite_finalize_null(&pageTable_removeForPageKeyStatement);
84
+ sqlite_finalize_null(&pageTable_removeAllStatement);
85
+ }
86
+
87
+ /**
88
+ * Required override method from YapDatabaseExtensionConnection
89
+ **/
90
+ - (void)_flushMemoryWithLevel:(int)level
91
+ {
92
+ if (level >= YapDatabaseConnectionFlushMemoryLevelMild)
93
+ {
94
+ [mapCache removeAllObjects];
95
+ [pageCache removeAllObjects];
96
+ }
97
+
98
+ if (level >= YapDatabaseConnectionFlushMemoryLevelModerate)
99
+ {
100
+ sqlite_finalize_null(&mapTable_setPageKeyForRowidStatement);
101
+ sqlite_finalize_null(&mapTable_removeForRowidStatement);
102
+ sqlite_finalize_null(&mapTable_removeAllStatement);
103
+
104
+ sqlite_finalize_null(&pageTable_insertForPageKeyStatement);
105
+ sqlite_finalize_null(&pageTable_updateAllForPageKeyStatement);
106
+ sqlite_finalize_null(&pageTable_updatePageForPageKeyStatement);
107
+ sqlite_finalize_null(&pageTable_updateLinkForPageKeyStatement);
108
+ sqlite_finalize_null(&pageTable_removeForPageKeyStatement);
109
+ sqlite_finalize_null(&pageTable_removeAllStatement);
110
+ }
111
+
112
+ if (level >= YapDatabaseConnectionFlushMemoryLevelFull)
113
+ {
114
+ sqlite_finalize_null(&mapTable_getPageKeyForRowidStatement);
115
+
116
+ sqlite_finalize_null(&pageTable_getDataForPageKeyStatement);
117
+ }
118
+ }
119
+
120
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121
+ #pragma mark Accessors
122
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123
+
124
+ /**
125
+ * Required override method from YapDatabaseExtensionConnection.
126
+ **/
127
+ - (YapDatabaseExtension *)extension
128
+ {
129
+ return view;
130
+ }
131
+
132
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133
+ #pragma mark Transactions
134
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
135
+
136
+ /**
137
+ * Required override method from YapDatabaseExtensionConnection.
138
+ **/
139
+ - (id)newReadTransaction:(YapDatabaseReadTransaction *)databaseTransaction
140
+ {
141
+ YapDatabaseViewTransaction *transaction =
142
+ [[YapDatabaseViewTransaction alloc] initWithViewConnection:self
143
+ databaseTransaction:databaseTransaction];
144
+
145
+ return transaction;
146
+ }
147
+
148
+ /**
149
+ * Required override method from YapDatabaseExtensionConnection.
150
+ **/
151
+ - (id)newReadWriteTransaction:(YapDatabaseReadWriteTransaction *)databaseTransaction
152
+ {
153
+ YapDatabaseViewTransaction *transaction =
154
+ [[YapDatabaseViewTransaction alloc] initWithViewConnection:self
155
+ databaseTransaction:databaseTransaction];
156
+
157
+ [self prepareForReadWriteTransaction];
158
+ return transaction;
159
+ }
160
+
161
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
162
+ #pragma mark Utilities
163
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
164
+
165
+ - (NSMutableDictionary *)group_pagesMetadata_dict_deepCopy:(NSDictionary *)in_group_pagesMetadata_dict
166
+ {
167
+ NSMutableDictionary *deepCopy = [NSMutableDictionary dictionaryWithCapacity:[in_group_pagesMetadata_dict count]];
168
+
169
+ [in_group_pagesMetadata_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
170
+
171
+ __unsafe_unretained NSString *group = (NSString *)key;
172
+ __unsafe_unretained NSMutableArray *pagesMetadata = (NSMutableArray *)obj;
173
+
174
+ // We need a mutable copy of the pages array,
175
+ // and we need a copy of each YapDatabaseViewPageMetadata object within the pages array.
176
+
177
+ NSMutableArray *pagesMetadataDeepCopy = [[NSMutableArray alloc] initWithArray:pagesMetadata copyItems:YES];
178
+
179
+ [deepCopy setObject:pagesMetadataDeepCopy forKey:group];
180
+ }];
181
+
182
+ return deepCopy;
183
+ }
184
+
185
+ - (void)sanitizeDirtyPages
186
+ {
187
+ NSNull *nsnull = [NSNull null];
188
+
189
+ for (NSString *pageKey in [dirtyPages allKeys])
190
+ {
191
+ YapDatabaseViewPage *page = [dirtyPages objectForKey:pageKey];
192
+
193
+ if ((id)page != nsnull)
194
+ {
195
+ [dirtyPages setObject:[page copy] forKey:pageKey];
196
+ }
197
+ }
198
+ }
199
+
200
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
201
+ #pragma mark Changeset Architecture
202
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
203
+
204
+ /**
205
+ * Initializes any ivars that a read-write transaction may need.
206
+ **/
207
+ - (void)prepareForReadWriteTransaction
208
+ {
209
+ if (dirtyMaps == nil)
210
+ dirtyMaps = [[NSMutableDictionary alloc] init];
211
+ if (dirtyPages == nil)
212
+ dirtyPages = [[NSMutableDictionary alloc] init];
213
+ if (dirtyLinks == nil)
214
+ dirtyLinks = [[NSMutableDictionary alloc] init];
215
+ if (changes == nil)
216
+ changes = [[NSMutableArray alloc] init];
217
+ if (mutatedGroups == nil)
218
+ mutatedGroups = [[NSMutableSet alloc] init];
219
+ }
220
+
221
+ /**
222
+ * Invoked by our YapDatabaseViewTransaction at the completion of the rollbackTransaction method.
223
+ **/
224
+ - (void)postRollbackCleanup
225
+ {
226
+ YDBLogAutoTrace();
227
+
228
+ group_pagesMetadata_dict = nil;
229
+ pageKey_group_dict = nil;
230
+
231
+ [mapCache removeAllObjects];
232
+ [pageCache removeAllObjects];
233
+
234
+ [dirtyMaps removeAllObjects];
235
+ [dirtyPages removeAllObjects];
236
+ [dirtyLinks removeAllObjects];
237
+ reset = NO;
238
+
239
+ [changes removeAllObjects];
240
+ }
241
+
242
+ /**
243
+ * Invoked by our YapDatabaseViewTransaction at the completion of the commitTransaction method.
244
+ **/
245
+ - (void)postCommitCleanup
246
+ {
247
+ // This code is best understood alongside the getExternalChangeset:internalChangeset: method (below).
248
+
249
+ // Both dirtyKeys & dirtyPages are sent in the internalChangeset.
250
+ // So we need completely new versions of them.
251
+
252
+ if ([dirtyMaps count] > 0)
253
+ dirtyMaps = nil;
254
+
255
+ if ([dirtyPages count] > 0)
256
+ dirtyPages = nil;
257
+
258
+ // dirtyLinks isn't part of the changeset.
259
+ // So it's safe to simply reset.
260
+
261
+ [dirtyLinks removeAllObjects];
262
+
263
+ // The changes log is copied into the external changeset.
264
+ // So it's safe to simply reset.
265
+
266
+ [changes removeAllObjects];
267
+ [mutatedGroups removeAllObjects];
268
+
269
+ reset = NO;
270
+ }
271
+
272
+ - (NSArray *)internalChangesetKeys
273
+ {
274
+ return @[ key_dirtyMaps,
275
+ key_dirtyPages,
276
+ key_reset,
277
+ key_group_pagesMetadata_dict,
278
+ key_pageKey_group_dict ];
279
+ }
280
+
281
+ - (NSArray *)externalChangesetKeys
282
+ {
283
+ return @[ key_changes ];
284
+ }
285
+
286
+ - (void)getInternalChangeset:(NSMutableDictionary **)internalChangesetPtr
287
+ externalChangeset:(NSMutableDictionary **)externalChangesetPtr
288
+ hasDiskChanges:(BOOL *)hasDiskChangesPtr
289
+ {
290
+ YDBLogAutoTrace();
291
+
292
+ NSMutableDictionary *internalChangeset = nil;
293
+ NSMutableDictionary *externalChangeset = nil;
294
+ BOOL hasDiskChanges = NO;
295
+
296
+ if ([dirtyMaps count] || [dirtyPages count] || [dirtyLinks count] || reset)
297
+ {
298
+ hasDiskChanges = view->options.isPersistent;
299
+ internalChangeset = [NSMutableDictionary dictionaryWithSharedKeySet:sharedKeySetForInternalChangeset];
300
+
301
+ if ([dirtyMaps count] > 0)
302
+ {
303
+ [internalChangeset setObject:dirtyMaps forKey:key_dirtyMaps];
304
+ }
305
+ if ([dirtyPages count] > 0)
306
+ {
307
+ [self sanitizeDirtyPages];
308
+ [internalChangeset setObject:dirtyPages forKey:key_dirtyPages];
309
+ }
310
+
311
+ if (reset)
312
+ {
313
+ [internalChangeset setObject:@(reset) forKey:key_reset];
314
+ }
315
+
316
+ NSMutableDictionary *group_pagesMetadata_dict_copy;
317
+ NSMutableDictionary *pageKey_group_dict_copy;
318
+
319
+ group_pagesMetadata_dict_copy = [self group_pagesMetadata_dict_deepCopy:group_pagesMetadata_dict];
320
+ pageKey_group_dict_copy = [pageKey_group_dict mutableCopy];
321
+
322
+ [internalChangeset setObject:group_pagesMetadata_dict_copy forKey:key_group_pagesMetadata_dict];
323
+ [internalChangeset setObject:pageKey_group_dict_copy forKey:key_pageKey_group_dict];
324
+ }
325
+
326
+ if ([changes count])
327
+ {
328
+ externalChangeset = [NSMutableDictionary dictionaryWithSharedKeySet:sharedKeySetForExternalChangeset];
329
+
330
+ [externalChangeset setObject:[changes copy] forKey:key_changes];
331
+ }
332
+
333
+ *internalChangesetPtr = internalChangeset;
334
+ *externalChangesetPtr = externalChangeset;
335
+ *hasDiskChangesPtr = hasDiskChanges;
336
+ }
337
+
338
+ - (void)processChangeset:(NSDictionary *)changeset
339
+ {
340
+ YDBLogAutoTrace();
341
+
342
+ NSMutableDictionary *changeset_group_pagesMetadata_dict = [changeset objectForKey:key_group_pagesMetadata_dict];
343
+ NSMutableDictionary *changeset_pageKey_group_dict = [changeset objectForKey:key_pageKey_group_dict];
344
+
345
+ NSDictionary *changeset_dirtyMaps = [changeset objectForKey:key_dirtyMaps];
346
+ NSDictionary *changeset_dirtyPages = [changeset objectForKey:key_dirtyPages];
347
+
348
+ BOOL changeset_reset = [[changeset objectForKey:key_reset] boolValue];
349
+
350
+ // Perform proper deep copies
351
+ //
352
+ // Note: we make copies from changeset_dirtyPages on demand below via:
353
+ // - [pageCache setObject:[page copy] forKey:pageKey];
354
+
355
+ changeset_group_pagesMetadata_dict = [self group_pagesMetadata_dict_deepCopy:changeset_group_pagesMetadata_dict];
356
+ changeset_pageKey_group_dict = [changeset_pageKey_group_dict mutableCopy];
357
+
358
+ // Store new top level objects
359
+
360
+ group_pagesMetadata_dict = changeset_group_pagesMetadata_dict;
361
+ pageKey_group_dict = changeset_pageKey_group_dict;
362
+
363
+ // Update mapCache
364
+
365
+ if (changeset_reset && ([changeset_dirtyMaps count] == 0))
366
+ {
367
+ [mapCache removeAllObjects];
368
+ }
369
+ else if ([changeset_dirtyMaps count] > 0)
370
+ {
371
+ NSUInteger removeCapacity = [mapCache count];
372
+ NSUInteger updateCapacity = MIN([mapCache count], [changeset_dirtyMaps count]);
373
+
374
+ NSMutableArray *keysToRemove = [NSMutableArray arrayWithCapacity:removeCapacity];
375
+ NSMutableArray *keysToUpdate = [NSMutableArray arrayWithCapacity:updateCapacity];
376
+
377
+ [mapCache enumerateKeysWithBlock:^(id key, BOOL *stop) {
378
+
379
+ // Order matters.
380
+ // Consider the following database change:
381
+ //
382
+ // [transaction removeAllObjects];
383
+ // [transaction setObject:obj forKey:key];
384
+
385
+ if ([changeset_dirtyMaps objectForKey:key])
386
+ [keysToUpdate addObject:key];
387
+ else if (changeset_reset)
388
+ [keysToRemove addObject:key];
389
+ }];
390
+
391
+ [mapCache removeObjectsForKeys:keysToRemove];
392
+
393
+ NSNull *nsnull = [NSNull null];
394
+
395
+ for (NSString *key in keysToUpdate)
396
+ {
397
+ NSString *pageKey = [changeset_dirtyMaps objectForKey:key];
398
+
399
+ if ((id)pageKey == nsnull)
400
+ [mapCache removeObjectForKey:key];
401
+ else
402
+ [mapCache setObject:pageKey forKey:key];
403
+ }
404
+ }
405
+
406
+ // Update pageCache
407
+
408
+ if (changeset_reset && ([changeset_dirtyPages count] == 0))
409
+ {
410
+ [pageCache removeAllObjects];
411
+ }
412
+ else if ([changeset_dirtyPages count])
413
+ {
414
+ NSUInteger removeCapacity = [pageCache count];
415
+ NSUInteger updateCapacity = MIN([pageCache count], [changeset_dirtyPages count]);
416
+
417
+ NSMutableArray *keysToRemove = [NSMutableArray arrayWithCapacity:removeCapacity];
418
+ NSMutableArray *keysToUpdate = [NSMutableArray arrayWithCapacity:updateCapacity];
419
+
420
+ [pageCache enumerateKeysWithBlock:^(id key, BOOL *stop) {
421
+
422
+ // Order matters.
423
+ // Consider the following database change:
424
+ //
425
+ // [transaction removeAllObjects];
426
+ // [transaction setObject:obj forKey:key];
427
+
428
+ if ([changeset_dirtyPages objectForKey:key])
429
+ [keysToUpdate addObject:key];
430
+ else if (changeset_reset)
431
+ [keysToRemove addObject:key];
432
+ }];
433
+
434
+ [pageCache removeObjectsForKeys:keysToRemove];
435
+
436
+ NSNull *nsnull = [NSNull null];
437
+
438
+ for (NSString *pageKey in keysToUpdate)
439
+ {
440
+ YapDatabaseViewPage *page = [changeset_dirtyPages objectForKey:pageKey];
441
+
442
+ // Each viewConnection needs its own independent mutable copy of the page.
443
+ // Mutable pages cannot be shared between multiple view connections.
444
+
445
+ if ((id)page == nsnull)
446
+ [pageCache removeObjectForKey:pageKey];
447
+ else
448
+ [pageCache setObject:[page copy] forKey:pageKey];
449
+ }
450
+ }
451
+ }
452
+
453
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
454
+ #pragma mark Changeset Inspection
455
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
456
+
457
+ /**
458
+ * Gets an exact list of changes that happend to the view, translating groups to sections as requested.
459
+ * See the header file for more information.
460
+ **/
461
+ - (void)getSectionChanges:(NSArray **)sectionChangesPtr
462
+ rowChanges:(NSArray **)rowChangesPtr
463
+ forNotifications:(NSArray *)notifications
464
+ withMappings:(YapDatabaseViewMappings *)mappings
465
+ {
466
+ if (mappings == nil)
467
+ {
468
+ YDBLogWarn(@"%@ - mappings parameter is nil", THIS_METHOD);
469
+
470
+ if (sectionChangesPtr) *sectionChangesPtr = nil;
471
+ if (rowChangesPtr) *rowChangesPtr = nil;
472
+
473
+ return;
474
+ }
475
+ if (mappings.snapshotOfLastUpdate == UINT64_MAX)
476
+ {
477
+ NSString *reason = [NSString stringWithFormat:
478
+ @"ViewConnection[%p, RegisteredName=%@] was asked for changes, but given bad mappings.",
479
+ self, view.registeredName];
480
+
481
+ NSDictionary *userInfo = @{ NSLocalizedRecoverySuggestionErrorKey:
482
+ @"The given mappings have not been properly initialized."
483
+ @" You need to invoke [mappings updateWithTransaction:transaction] once in order to initialize"
484
+ @" the mappings object. You should do this after invoking"
485
+ @" [databaseConnection beginLongLivedReadTransaction]. For example code, please see"
486
+ @" YapDatabaseViewMappings.h, or see the wiki: https://github.com/yaptv/YapDatabase/wiki/Views"};
487
+
488
+ @throw [NSException exceptionWithName:@"YapDatabaseException" reason:reason userInfo:userInfo];
489
+ }
490
+
491
+ NSString *registeredName = self.view.registeredName;
492
+ NSMutableArray *all_changes = [NSMutableArray array];
493
+
494
+ for (NSNotification *notification in notifications)
495
+ {
496
+ NSDictionary *changeset =
497
+ [[notification.userInfo objectForKey:YapDatabaseExtensionsKey] objectForKey:registeredName];
498
+
499
+ NSArray *changeset_changes = [changeset objectForKey:key_changes];
500
+
501
+ [all_changes addObjectsFromArray:changeset_changes];
502
+ }
503
+
504
+ YapDatabaseViewMappings *originalMappings = [mappings copy];
505
+ __block BOOL isLongLivedReadTransaction = NO;
506
+
507
+ [databaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
508
+
509
+ isLongLivedReadTransaction = transaction.connection.isInLongLivedReadTransaction;
510
+ [mappings updateWithTransaction:transaction];
511
+ }];
512
+
513
+ if ([notifications count] > 0)
514
+ {
515
+ NSDictionary *firstChangeset = [[notifications objectAtIndex:0] userInfo];
516
+ NSDictionary *lastChangeset = [[notifications lastObject] userInfo];
517
+
518
+ uint64_t firstSnapshot = [[firstChangeset objectForKey:YapDatabaseSnapshotKey] unsignedLongLongValue];
519
+ uint64_t lastSnapshot = [[lastChangeset objectForKey:YapDatabaseSnapshotKey] unsignedLongLongValue];
520
+
521
+ if ((originalMappings.snapshotOfLastUpdate != (firstSnapshot - 1)) ||
522
+ (mappings.snapshotOfLastUpdate != lastSnapshot))
523
+ {
524
+ NSString *reason = [NSString stringWithFormat:
525
+ @"ViewConnection[%p, RegisteredName=%@] was asked for changes,"
526
+ @" but given mismatched mappings & notifications.", self, view.registeredName];
527
+
528
+ NSString *failureReason = [NSString stringWithFormat:
529
+ @"preMappings.snapshotOfLastUpdate: expected(%llu) != found(%llu), "
530
+ @"postMappings.snapshotOfLastUpdate: expected(%llu) != found(%llu), "
531
+ @"isLongLivedReadTransaction = %@",
532
+ originalMappings.snapshotOfLastUpdate, (firstSnapshot - 1),
533
+ mappings.snapshotOfLastUpdate, lastSnapshot,
534
+ (isLongLivedReadTransaction ? @"YES" : @"NO")];
535
+
536
+ NSString *suggestion = [NSString stringWithFormat:
537
+ @"When you initialize the database, the snapshot (uint64) is set to zero."
538
+ @" Every read-write transaction (that makes modifications) increments the snapshot."
539
+ @" Now, when you ask the viewConnection for a changeset, "
540
+ @" you need to pass matching mappings & notifications. That is, the mappings need to represent the"
541
+ @" database at snapshot X, and the notifications need to represent the database at snapshots"
542
+ @" @[ X+1, X+2, ...]. This does not appear to be the case. This most often happens when the"
543
+ @" databaseConnection isn't using a longLivedReadTransaction. And this happens by accident"
544
+ @" most often when you use a databaseConnection, which is in a longLivedReadTransaction, to perform"
545
+ @" a read-write transaction. Doing so implicitly forces the connection out of the"
546
+ @" longLivedReadTransaction, and moves it to the most recent snapshot. If this is the case,"
547
+ @" be sure to use a separate connection for your read-write transaction."];
548
+
549
+ NSDictionary *userInfo = @{
550
+ NSLocalizedFailureReasonErrorKey: failureReason,
551
+ NSLocalizedRecoverySuggestionErrorKey: suggestion };
552
+
553
+ // If we don't throw the exception here,
554
+ // then you'll just get an exception later from the tableView or collectionView.
555
+ // It will look something like this:
556
+ //
557
+ // > Invalid update: invalid number of rows in section X. The number of rows contained in an
558
+ // > existing section after the update (Y) must be equal to the number of rows contained in that section
559
+ // > before the update (Z), plus or minus the number of rows inserted or deleted from that
560
+ // > section (# inserted, # deleted).
561
+ //
562
+ // In order to guarantee you DON'T get an exception (either from YapDatabase or from Apple),
563
+ // then you need to follow the instructions for setting up your connection, mappings, & notifications.
564
+ //
565
+ // For complete code samples, check out the wiki:
566
+ // https://github.com/yaptv/YapDatabase/wiki/Views
567
+ //
568
+ // You may be tempted to simply comment out the exception below.
569
+ // If you do, you're not fixing the root cause of your problem.
570
+ // Furthermore, you're simply trading this exception, which comes with documented steps on how
571
+ // to fix the problem, for an exception from Apple which will be even harder to diagnose.
572
+
573
+ @throw [NSException exceptionWithName:@"YapDatabaseException" reason:reason userInfo:userInfo];
574
+ }
575
+
576
+ if (!isLongLivedReadTransaction)
577
+ {
578
+ YDBLogWarn(@"%@ - The databaseConnection is NOT in a longLivedReadTransaction."
579
+ @" It needs to be in order to guarantee"
580
+ @" (A) you can provide a stable data-source for your UI thread and"
581
+ @" (B) you can get changesets which match the movement from one"
582
+ @" stable data-source state to another. If you think your databaseConnection IS"
583
+ @" in a longLivedReadTransaction, then perhaps you aborted it by accident."
584
+ @" This generally happens when you use a databaseConnection,"
585
+ @" which is in a longLivedReadTransaction, to perform a read-write transaction."
586
+ @" Doing so implicitly forces the connection out of the longLivedReadTransaction,"
587
+ @" and moves it to the most recent snapshot. If this is the case,"
588
+ @" be sure to use a separate connection for your read-write transaction.", THIS_METHOD);
589
+ }
590
+ }
591
+
592
+ [YapDatabaseViewChange getSectionChanges:sectionChangesPtr
593
+ rowChanges:rowChangesPtr
594
+ withOriginalMappings:originalMappings
595
+ finalMappings:mappings
596
+ fromChanges:all_changes];
597
+ }
598
+
599
+ /**
600
+ * A simple YES/NO query to see if the view changed at all, inclusive of all groups.
601
+ **/
602
+ - (BOOL)hasChangesForNotifications:(NSArray *)notifications
603
+ {
604
+ NSString *registeredName = self.view.registeredName;
605
+
606
+ for (NSNotification *notification in notifications)
607
+ {
608
+ NSDictionary *changeset =
609
+ [[notification.userInfo objectForKey:YapDatabaseExtensionsKey] objectForKey:registeredName];
610
+
611
+ NSArray *changeset_changes = [changeset objectForKey:key_changes];
612
+
613
+ if ([changeset_changes count] > 0)
614
+ {
615
+ return YES;
616
+ }
617
+ }
618
+
619
+ return NO;
620
+ }
621
+
622
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
623
+ #pragma mark Statements - KeyTable
624
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
625
+
626
+ - (sqlite3_stmt *)mapTable_getPageKeyForRowidStatement
627
+ {
628
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
629
+
630
+ if (mapTable_getPageKeyForRowidStatement == NULL)
631
+ {
632
+ NSString *string = [NSString stringWithFormat:
633
+ @"SELECT \"pageKey\" FROM \"%@\" WHERE \"rowid\" = ?;", [view mapTableName]];
634
+
635
+ sqlite3 *db = databaseConnection->db;
636
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
637
+
638
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &mapTable_getPageKeyForRowidStatement, NULL);
639
+ if (status != SQLITE_OK)
640
+ {
641
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
642
+ }
643
+
644
+ FreeYapDatabaseString(&stmt);
645
+ }
646
+
647
+ return mapTable_getPageKeyForRowidStatement;
648
+ }
649
+
650
+ - (sqlite3_stmt *)mapTable_setPageKeyForRowidStatement
651
+ {
652
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
653
+
654
+ if (mapTable_setPageKeyForRowidStatement == NULL)
655
+ {
656
+ NSString *string = [NSString stringWithFormat:
657
+ @"INSERT OR REPLACE INTO \"%@\" (\"rowid\", \"pageKey\") VALUES (?, ?);", [view mapTableName]];
658
+
659
+ sqlite3 *db = databaseConnection->db;
660
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
661
+
662
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &mapTable_setPageKeyForRowidStatement, NULL);
663
+ if (status != SQLITE_OK)
664
+ {
665
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
666
+ }
667
+
668
+ FreeYapDatabaseString(&stmt);
669
+ }
670
+
671
+ return mapTable_setPageKeyForRowidStatement;
672
+ }
673
+
674
+ - (sqlite3_stmt *)mapTable_removeForRowidStatement
675
+ {
676
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
677
+
678
+ if (mapTable_removeForRowidStatement == NULL)
679
+ {
680
+ NSString *string = [NSString stringWithFormat:
681
+ @"DELETE FROM \"%@\" WHERE \"rowid\" = ?;", [view mapTableName]];
682
+
683
+ sqlite3 *db = databaseConnection->db;
684
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
685
+
686
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &mapTable_removeForRowidStatement, NULL);
687
+ if (status != SQLITE_OK)
688
+ {
689
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
690
+ }
691
+
692
+ FreeYapDatabaseString(&stmt);
693
+ }
694
+
695
+ return mapTable_removeForRowidStatement;
696
+ }
697
+
698
+ - (sqlite3_stmt *)mapTable_removeAllStatement
699
+ {
700
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
701
+
702
+ if (mapTable_removeAllStatement == NULL)
703
+ {
704
+ NSString *string = [NSString stringWithFormat:
705
+ @"DELETE FROM \"%@\";", [view mapTableName]];
706
+
707
+ sqlite3 *db = databaseConnection->db;
708
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
709
+
710
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &mapTable_removeAllStatement, NULL);
711
+ if (status != SQLITE_OK)
712
+ {
713
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
714
+ }
715
+
716
+ FreeYapDatabaseString(&stmt);
717
+ }
718
+
719
+ return mapTable_removeAllStatement;
720
+ }
721
+
722
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
723
+ #pragma mark Statements - PageTable
724
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
725
+
726
+ - (sqlite3_stmt *)pageTable_getDataForPageKeyStatement
727
+ {
728
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
729
+
730
+ if (pageTable_getDataForPageKeyStatement == NULL)
731
+ {
732
+ NSString *string = [NSString stringWithFormat:
733
+ @"SELECT \"data\" FROM \"%@\" WHERE \"pageKey\" = ?;", [view pageTableName]];
734
+
735
+ sqlite3 *db = databaseConnection->db;
736
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
737
+
738
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &pageTable_getDataForPageKeyStatement, NULL);
739
+ if (status != SQLITE_OK)
740
+ {
741
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
742
+ }
743
+
744
+ FreeYapDatabaseString(&stmt);
745
+ }
746
+
747
+ return pageTable_getDataForPageKeyStatement;
748
+ }
749
+
750
+ - (sqlite3_stmt *)pageTable_insertForPageKeyStatement
751
+ {
752
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
753
+
754
+ if (pageTable_insertForPageKeyStatement == NULL)
755
+ {
756
+ NSString *string = [NSString stringWithFormat:
757
+ @"INSERT INTO \"%@\""
758
+ @" (\"pageKey\", \"group\", \"prevPageKey\", \"count\", \"data\") VALUES (?, ?, ?, ?, ?);",
759
+ [view pageTableName]];
760
+
761
+ sqlite3 *db = databaseConnection->db;
762
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
763
+
764
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &pageTable_insertForPageKeyStatement, NULL);
765
+ if (status != SQLITE_OK)
766
+ {
767
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
768
+ }
769
+
770
+ FreeYapDatabaseString(&stmt);
771
+ }
772
+
773
+ return pageTable_insertForPageKeyStatement;
774
+ }
775
+
776
+ - (sqlite3_stmt *)pageTable_updateAllForPageKeyStatement
777
+ {
778
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
779
+
780
+ if (pageTable_updateAllForPageKeyStatement == NULL)
781
+ {
782
+ NSString *string = [NSString stringWithFormat:
783
+ @"UPDATE \"%@\" SET \"prevPageKey\" = ?, \"count\" = ?, \"data\" = ? WHERE \"pageKey\" = ?;",
784
+ [view pageTableName]];
785
+
786
+ sqlite3 *db = databaseConnection->db;
787
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
788
+
789
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &pageTable_updateAllForPageKeyStatement, NULL);
790
+ if (status != SQLITE_OK)
791
+ {
792
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
793
+ }
794
+
795
+ FreeYapDatabaseString(&stmt);
796
+ }
797
+
798
+ return pageTable_updateAllForPageKeyStatement;
799
+ }
800
+
801
+ - (sqlite3_stmt *)pageTable_updatePageForPageKeyStatement
802
+ {
803
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
804
+
805
+ if (pageTable_updatePageForPageKeyStatement == NULL)
806
+ {
807
+ NSString *string = [NSString stringWithFormat:
808
+ @"UPDATE \"%@\" SET \"count\" = ?, \"data\" = ? WHERE \"pageKey\" = ?;", [view pageTableName]];
809
+
810
+ sqlite3 *db = databaseConnection->db;
811
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
812
+
813
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &pageTable_updatePageForPageKeyStatement, NULL);
814
+ if (status != SQLITE_OK)
815
+ {
816
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
817
+ }
818
+
819
+ FreeYapDatabaseString(&stmt);
820
+ }
821
+
822
+ return pageTable_updatePageForPageKeyStatement;
823
+ }
824
+
825
+ - (sqlite3_stmt *)pageTable_updateLinkForPageKeyStatement
826
+ {
827
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
828
+
829
+ if (pageTable_updateLinkForPageKeyStatement == NULL)
830
+ {
831
+ NSString *string = [NSString stringWithFormat:
832
+ @"UPDATE \"%@\" SET \"prevPageKey\" = ? WHERE \"pageKey\" = ?;", [view pageTableName]];
833
+
834
+ sqlite3 *db = databaseConnection->db;
835
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
836
+
837
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &pageTable_updateLinkForPageKeyStatement, NULL);
838
+ if (status != SQLITE_OK)
839
+ {
840
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
841
+ }
842
+
843
+ FreeYapDatabaseString(&stmt);
844
+ }
845
+
846
+ return pageTable_updateLinkForPageKeyStatement;
847
+ }
848
+
849
+ - (sqlite3_stmt *)pageTable_removeForPageKeyStatement
850
+ {
851
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
852
+
853
+ if (pageTable_removeForPageKeyStatement == NULL)
854
+ {
855
+ NSString *string = [NSString stringWithFormat:
856
+ @"DELETE FROM \"%@\" WHERE \"pageKey\" = ?;", [view pageTableName]];
857
+
858
+ sqlite3 *db = databaseConnection->db;
859
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
860
+
861
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &pageTable_removeForPageKeyStatement, NULL);
862
+ if (status != SQLITE_OK)
863
+ {
864
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
865
+ }
866
+
867
+ FreeYapDatabaseString(&stmt);
868
+ }
869
+
870
+ return pageTable_removeForPageKeyStatement;
871
+ }
872
+
873
+ - (sqlite3_stmt *)pageTable_removeAllStatement
874
+ {
875
+ NSAssert(view->options.isPersistent, @"In-memory view accessing sqlite");
876
+
877
+ if (pageTable_removeAllStatement == NULL)
878
+ {
879
+ NSString *string = [NSString stringWithFormat:
880
+ @"DELETE FROM \"%@\";", [view pageTableName]];
881
+
882
+ sqlite3 *db = databaseConnection->db;
883
+ YapDatabaseString stmt; MakeYapDatabaseString(&stmt, string);
884
+
885
+ int status = sqlite3_prepare_v2(db, stmt.str, stmt.length+1, &pageTable_removeAllStatement, NULL);
886
+ if (status != SQLITE_OK)
887
+ {
888
+ YDBLogError(@"%@: Error creating prepared statement: %d %s", THIS_METHOD, status, sqlite3_errmsg(db));
889
+ }
890
+
891
+ FreeYapDatabaseString(&stmt);
892
+ }
893
+
894
+ return pageTable_removeAllStatement;
895
+ }
896
+
897
+ @end