TemplateInfo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. data/.DS_Store +0 -0
  2. data/.gitignore +2 -0
  3. data/TemplateInfo.gemspec +1 -1
  4. data/bin/tif_create.rb +157 -0
  5. data/lib/TemplateInfo/version.rb +1 -1
  6. data/test.xctemplate/.DS_Store +0 -0
  7. data/test.xctemplate/TemplateInfo.plist +2830 -0
  8. data/test.xctemplate/TemplateInfo.xml +2842 -0
  9. data/test.xctemplate/libs/BeeFramework/Bee.h +35 -0
  10. data/test.xctemplate/libs/BeeFramework/Bee_Precompile.h +143 -0
  11. data/test.xctemplate/libs/BeeFramework/Core/Bee_Core.h +36 -0
  12. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Foundation.h +54 -0
  13. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Foundation.mm +33 -0
  14. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Log.h +64 -0
  15. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Log.mm +164 -0
  16. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Performance.h +111 -0
  17. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Performance.mm +122 -0
  18. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Runtime.h +98 -0
  19. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Runtime.mm +437 -0
  20. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Sandbox.h +45 -0
  21. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Sandbox.mm +81 -0
  22. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Singleton.h +47 -0
  23. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Singleton.mm +34 -0
  24. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_SystemInfo.h +62 -0
  25. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_SystemInfo.m +147 -0
  26. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Thread.h +64 -0
  27. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Thread.mm +91 -0
  28. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSArray+BeeExtension.h +76 -0
  29. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSArray+BeeExtension.m +300 -0
  30. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSData+BeeExtension.h +44 -0
  31. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSData+BeeExtension.m +92 -0
  32. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSDate+BeeExtension.h +44 -0
  33. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSDate+BeeExtension.m +85 -0
  34. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSDictionary+BeeExtension.h +90 -0
  35. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSDictionary+BeeExtension.m +509 -0
  36. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSNumber+BeeExtension.h +50 -0
  37. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSNumber+BeeExtension.m +64 -0
  38. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeJSON.h +43 -0
  39. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeJSON.m +116 -0
  40. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeNotification.h +66 -0
  41. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeNotification.m +150 -0
  42. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeProperty.h +210 -0
  43. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeProperty.m +34 -0
  44. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeTicker.h +41 -0
  45. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeTicker.m +156 -0
  46. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeTypeConversion.h +49 -0
  47. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeTypeConversion.m +109 -0
  48. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSString+BeeExtension.h +86 -0
  49. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSString+BeeExtension.m +464 -0
  50. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_Network.h +36 -0
  51. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_Network.m +33 -0
  52. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_Request.h +144 -0
  53. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_Request.m +560 -0
  54. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_RequestQueue.h +99 -0
  55. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_RequestQueue.m +742 -0
  56. data/test.xctemplate/libs/BeeFramework/Core/Network/Extension/NSObject+BeeRequest.h +62 -0
  57. data/test.xctemplate/libs/BeeFramework/Core/Network/Extension/NSObject+BeeRequest.m +175 -0
  58. data/test.xctemplate/libs/BeeFramework/Core/Storage/0.2.4.zip +0 -0
  59. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_ActiveBase.h +133 -0
  60. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_ActiveBase.m +641 -0
  61. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_ActiveRecord.h +106 -0
  62. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_ActiveRecord.m +1956 -0
  63. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Cache.h +91 -0
  64. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Cache.m +318 -0
  65. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Database.h +223 -0
  66. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Database.m +3007 -0
  67. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Keychain.h +55 -0
  68. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Keychain.m +173 -0
  69. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Storage.h +39 -0
  70. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Storage.m +33 -0
  71. data/test.xctemplate/libs/BeeFramework/Core/Storage/Extension/NSObject+BeeDatabase.h +47 -0
  72. data/test.xctemplate/libs/BeeFramework/Core/Storage/Extension/NSObject+BeeDatabase.m +81 -0
  73. data/test.xctemplate/libs/BeeFramework/Core/Storage/Extension/NSObject+BeeKeychain.h +44 -0
  74. data/test.xctemplate/libs/BeeFramework/Core/Storage/Extension/NSObject+BeeKeychain.m +57 -0
  75. data/test.xctemplate/libs/BeeFramework/MVC/Bee_MVC.h +49 -0
  76. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_Controller.h +66 -0
  77. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_Controller.mm +228 -0
  78. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_Message.h +209 -0
  79. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_Message.mm +873 -0
  80. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_MessageQueue.h +75 -0
  81. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_MessageQueue.mm +389 -0
  82. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+ActiveRecord.h +52 -0
  83. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+ActiveRecord.m +150 -0
  84. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+HTTP.h +49 -0
  85. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+HTTP.mm +201 -0
  86. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+JSON.h +52 -0
  87. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+JSON.mm +118 -0
  88. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+XML.h +49 -0
  89. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+XML.mm +78 -0
  90. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/NSObject+BeeMessage.h +57 -0
  91. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/NSObject+BeeMessage.mm +138 -0
  92. data/test.xctemplate/libs/BeeFramework/MVC/Model/Bee_Model.h +64 -0
  93. data/test.xctemplate/libs/BeeFramework/MVC/Model/Bee_Model.m +190 -0
  94. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIActionSheet.h +71 -0
  95. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIActionSheet.m +307 -0
  96. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIActivityIndicatorView.h +52 -0
  97. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIActivityIndicatorView.m +152 -0
  98. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIAlertView.h +73 -0
  99. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIAlertView.m +234 -0
  100. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIButton.h +97 -0
  101. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIButton.m +424 -0
  102. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIDatePicker.h +78 -0
  103. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIDatePicker.m +362 -0
  104. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIGridCell.h +82 -0
  105. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIGridCell.m +298 -0
  106. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIImageView.h +110 -0
  107. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIImageView.m +541 -0
  108. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIKeyboard.h +74 -0
  109. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIKeyboard.m +243 -0
  110. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UILabel.h +46 -0
  111. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UILabel.m +99 -0
  112. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIMatrixView.h +124 -0
  113. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIMatrixView.m +821 -0
  114. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UINavigationBar.h +57 -0
  115. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UINavigationBar.m +161 -0
  116. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIOrientation.h +60 -0
  117. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIOrientation.m +146 -0
  118. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIPageControl.h +61 -0
  119. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIPageControl.m +190 -0
  120. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIProgressView.h +47 -0
  121. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIProgressView.m +113 -0
  122. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIPullLoader.h +71 -0
  123. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIPullLoader.m +236 -0
  124. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIScrollView.h +146 -0
  125. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIScrollView.m +1487 -0
  126. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UISegmentedControl.h +60 -0
  127. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UISegmentedControl.m +192 -0
  128. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UISignal.h +126 -0
  129. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UISignal.m +453 -0
  130. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITabBar.h +70 -0
  131. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITabBar.m +249 -0
  132. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITextField.h +67 -0
  133. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITextField.m +242 -0
  134. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITextView.h +75 -0
  135. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITextView.m +311 -0
  136. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITipsView.h +184 -0
  137. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITipsView.m +911 -0
  138. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIWebView.h +65 -0
  139. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIWebView.m +242 -0
  140. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIZoomView.h +91 -0
  141. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIZoomView.m +444 -0
  142. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_View.h +72 -0
  143. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_View.m +38 -0
  144. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/CGRect+BeeExtension.h +79 -0
  145. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/CGRect+BeeExtension.m +288 -0
  146. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIColor+BeeExtension.h +65 -0
  147. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIColor+BeeExtension.m +161 -0
  148. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIFont+BeeExtension.h +45 -0
  149. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIFont+BeeExtension.m +137 -0
  150. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIImage+BeeExtension.h +56 -0
  151. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIImage+BeeExtension.m +218 -0
  152. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+BeeExtension.h +105 -0
  153. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+BeeExtension.m +556 -0
  154. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+BeeUISignal.h +53 -0
  155. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+BeeUISignal.m +104 -0
  156. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+HoldGesture.h +52 -0
  157. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+HoldGesture.m +170 -0
  158. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+PanGesture.h +54 -0
  159. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+PanGesture.m +166 -0
  160. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+SwipeGesture.h +54 -0
  161. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+SwipeGesture.m +184 -0
  162. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+TapGesture.h +57 -0
  163. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+TapGesture.m +275 -0
  164. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIBoard.h +212 -0
  165. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIBoard.m +1219 -0
  166. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIStack.h +111 -0
  167. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIStack.m +694 -0
  168. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIStackGroup.h +71 -0
  169. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIStackGroup.m +258 -0
  170. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_ViewController.h +45 -0
  171. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_ViewController.m +36 -0
  172. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+BeeExtension.h +57 -0
  173. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+BeeExtension.m +151 -0
  174. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+BeeUISignal.h +53 -0
  175. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+BeeUISignal.m +92 -0
  176. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+UINavigationBar.h +72 -0
  177. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+UINavigationBar.m +175 -0
  178. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UICollection.h +59 -0
  179. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UICollection.m +249 -0
  180. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UILayout.h +199 -0
  181. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UILayout.m +1170 -0
  182. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UIQuery.h +113 -0
  183. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UIQuery.m +710 -0
  184. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UIStyle.h +66 -0
  185. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UIStyle.m +189 -0
  186. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplate.h +69 -0
  187. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplate.m +210 -0
  188. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateAndroid.h +45 -0
  189. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateAndroid.m +59 -0
  190. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateHTML.h +45 -0
  191. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateHTML.m +55 -0
  192. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateJSON.h +45 -0
  193. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateJSON.m +54 -0
  194. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateOmniGraffle.h +45 -0
  195. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateOmniGraffle.m +54 -0
  196. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateXML.h +45 -0
  197. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateXML.m +438 -0
  198. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_ViewLayout.h +60 -0
  199. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_ViewLayout.m +37 -0
  200. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/BeeUIQuery+BeeUIStyle.h +45 -0
  201. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/BeeUIQuery+BeeUIStyle.m +55 -0
  202. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/BeeUIStyle+BeeUIQuery.h +45 -0
  203. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/BeeUIStyle+BeeUIQuery.m +55 -0
  204. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIButton+BeeUIStyle.h +41 -0
  205. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIButton+BeeUIStyle.m +100 -0
  206. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIImageView+BeeUIStyle.h +41 -0
  207. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIImageView+BeeUIStyle.m +101 -0
  208. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UILabel+BeeUIStyle.h +41 -0
  209. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UILabel+BeeUIStyle.m +48 -0
  210. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UITextField+BeeUIStyle.h +41 -0
  211. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UITextField+BeeUIStyle.m +77 -0
  212. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UITextView+BeeUIStyle.h +41 -0
  213. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UITextView+BeeUIStyle.m +47 -0
  214. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUILayout.h +52 -0
  215. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUILayout.m +177 -0
  216. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUIQuery.h +44 -0
  217. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUIQuery.m +57 -0
  218. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUIStyle.h +50 -0
  219. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUIStyle.m +283 -0
  220. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUILayout.h +52 -0
  221. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUILayout.m +178 -0
  222. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUIQuery.h +44 -0
  223. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUIQuery.m +58 -0
  224. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUIStyle.h +44 -0
  225. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUIStyle.m +57 -0
  226. metadata +226 -3
@@ -0,0 +1,3007 @@
1
+ //
2
+ // ______ ______ ______
3
+ // /\ __ \ /\ ___\ /\ ___\
4
+ // \ \ __< \ \ __\_ \ \ __\_
5
+ // \ \_____\ \ \_____\ \ \_____\
6
+ // \/_____/ \/_____/ \/_____/
7
+ //
8
+ // Copyright (c) 2012 BEE creators
9
+ // http://www.whatsbug.com
10
+ //
11
+ // Permission is hereby granted, free of charge, to any person obtaining a
12
+ // copy of this software and associated documentation files (the "Software"),
13
+ // to deal in the Software without restriction, including without limitation
14
+ // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
+ // and/or sell copies of the Software, and to permit persons to whom the
16
+ // Software is furnished to do so, subject to the following conditions:
17
+ //
18
+ // The above copyright notice and this permission notice shall be included in
19
+ // all copies or substantial portions of the Software.
20
+ //
21
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27
+ // IN THE SOFTWARE.
28
+ //
29
+ //
30
+ // Bee_Database.h
31
+ //
32
+
33
+ #import "Bee_Precompile.h"
34
+ #import "Bee_Database.h"
35
+ #import "Bee_Log.h"
36
+ #import "Bee_Sandbox.h"
37
+ #import "Bee_ActiveRecord.h"
38
+ #import "Bee_ActiveBase.h"
39
+
40
+ #import "NSArray+BeeExtension.h"
41
+ #import "NSString+BeeExtension.h"
42
+ #import "NSNumber+BeeExtension.h"
43
+ #import "NSDictionary+BeeExtension.h"
44
+ #import "NSObject+BeeDatabase.h"
45
+
46
+ #import "FMDatabase.h"
47
+
48
+ #pragma mark -
49
+
50
+ @interface BeeDatabase(Private)
51
+
52
+ + (NSString *)fieldNameForIdentifier:(NSString *)identifier;
53
+ + (BOOL)isFullPath:(NSString *)path;
54
+
55
+ - (void)initSelf;
56
+ - (NSString *)internalCreateAliasFromTable:(NSString *)name;
57
+ - (void)internalSelect:(NSString *)select alias:(NSString *)alias type:(NSString *)type;
58
+ - (void)internalWhere:(NSString *)key value:(NSObject *)value type:(NSString *)type;
59
+ - (void)internalLike:(NSString *)field match:(NSObject *)match type:(NSString *)type side:(NSString *)side not:(BOOL)not;
60
+ - (void)internalHaving:(NSString *)key value:(NSObject *)value type:(NSString *)type;
61
+
62
+ - (NSString *)internalCompileSelect:(NSString *)override;
63
+ - (NSString *)internalCompileCreate:(NSString *)table;
64
+ - (NSString *)internalCompileIndex:(NSString *)table;
65
+
66
+ // create
67
+
68
+ - (BeeDatabase *)table:(NSString *)name;
69
+ - (BeeDatabase *)field:(NSString *)name type:(NSString *)type size:(NSUInteger)size;
70
+ - (BeeDatabase *)unsignedType;
71
+ - (BeeDatabase *)notNull;
72
+ - (BeeDatabase *)primaryKey;
73
+ - (BeeDatabase *)autoIncrement;
74
+ - (BeeDatabase *)defaultZero;
75
+ - (BeeDatabase *)defaultNull;
76
+ - (BeeDatabase *)defaultValue:(id)value;
77
+ - (BeeDatabase *)unique;
78
+ - (BOOL)createTableIfNotExists;
79
+ - (BOOL)createTableIfNotExists:(NSString *)table;
80
+ - (BOOL)indexTableOn:(NSArray *)fields;
81
+ - (BOOL)indexTable:(NSString *)table on:(NSArray *)fields;
82
+ - (BOOL)existsTable:(NSString *)table;
83
+
84
+ // select
85
+
86
+ - (BeeDatabase *)select:(NSString *)select;
87
+ - (BeeDatabase *)selectMax:(NSString *)select;
88
+ - (BeeDatabase *)selectMax:(NSString *)select alias:(NSString *)alias;
89
+ - (BeeDatabase *)selectMin:(NSString *)select;
90
+ - (BeeDatabase *)selectMin:(NSString *)select alias:(NSString *)alias;
91
+ - (BeeDatabase *)selectAvg:(NSString *)select;
92
+ - (BeeDatabase *)selectAvg:(NSString *)select alias:(NSString *)alias;
93
+ - (BeeDatabase *)selectSum:(NSString *)select;
94
+ - (BeeDatabase *)selectSum:(NSString *)select alias:(NSString *)alias;
95
+
96
+ - (BeeDatabase *)distinct:(BOOL)flag;
97
+ - (BeeDatabase *)from:(NSString *)from;
98
+
99
+ - (BeeDatabase *)where:(NSString *)key value:(id)value;
100
+ - (BeeDatabase *)orWhere:(NSString *)key value:(id)value;
101
+
102
+ - (BeeDatabase *)whereIn:(NSString *)key values:(NSArray *)values;
103
+ - (BeeDatabase *)orWhereIn:(NSString *)key values:(NSArray *)values;
104
+ - (BeeDatabase *)whereNotIn:(NSString *)key values:(NSArray *)values;
105
+ - (BeeDatabase *)orWhereNotIn:(NSString *)key values:(NSArray *)values;
106
+
107
+ - (BeeDatabase *)like:(NSString *)field match:(id)value;
108
+ - (BeeDatabase *)notLike:(NSString *)field match:(id)value;
109
+ - (BeeDatabase *)orLike:(NSString *)field match:(id)value;
110
+ - (BeeDatabase *)orNotLike:(NSString *)field match:(id)value;
111
+
112
+ - (BeeDatabase *)groupBy:(NSString *)by;
113
+
114
+ - (BeeDatabase *)having:(NSString *)key value:(id)value;
115
+ - (BeeDatabase *)orHaving:(NSString *)key value:(id)value;
116
+
117
+ - (BeeDatabase *)orderAscendBy:(NSString *)by;
118
+ - (BeeDatabase *)orderDescendBy:(NSString *)by;
119
+ - (BeeDatabase *)orderRandomBy:(NSString *)by;
120
+ - (BeeDatabase *)orderBy:(NSString *)by direction:(NSString *)direction;
121
+
122
+ - (BeeDatabase *)limit:(NSUInteger)limit;
123
+ - (BeeDatabase *)offset:(NSUInteger)offset;
124
+
125
+ - (BeeDatabase *)classInfo:(id)obj;
126
+
127
+ // write
128
+
129
+ - (BeeDatabase *)set:(NSString *)key;
130
+ - (BeeDatabase *)set:(NSString *)key value:(id)value;
131
+
132
+ - (NSArray *)get;
133
+ - (NSArray *)get:(NSString *)table;
134
+ - (NSArray *)get:(NSString *)table limit:(NSUInteger)limit;
135
+ - (NSArray *)get:(NSString *)table limit:(NSUInteger)limit offset:(NSUInteger)offset;
136
+
137
+ - (NSUInteger)count;
138
+ - (NSUInteger)count:(NSString *)table;
139
+
140
+ - (NSInteger)insert;
141
+ - (NSInteger)insert:(NSString *)table;
142
+
143
+ - (BOOL)update;
144
+ - (BOOL)update:(NSString *)table;
145
+
146
+ - (BOOL)empty;
147
+ - (BOOL)empty:(NSString *)table;
148
+
149
+ - (BOOL)truncate;
150
+ - (BOOL)truncate:(NSString *)table;
151
+
152
+ - (BOOL)delete;
153
+ - (BOOL)delete:(NSString *)table;
154
+
155
+ // active record
156
+
157
+ - (void)classType:(Class)clazz;
158
+ - (void)associate:(NSObject *)obj;
159
+ - (void)has:(NSObject *)obj;
160
+
161
+ @end
162
+
163
+ #pragma mark -
164
+
165
+ @implementation BeeDatabase
166
+
167
+ @dynamic autoOptimize;
168
+ @dynamic ready;
169
+ @dynamic total;
170
+ @synthesize shadow = _shadow;
171
+ @synthesize database = _database;
172
+ @synthesize filePath = _filePath;
173
+ @synthesize identifier = _identifier;
174
+
175
+ @dynamic TABLE;
176
+ @dynamic FIELD;
177
+ @dynamic FIELD_WITH_SIZE;
178
+ @dynamic UNSIGNED;
179
+ @dynamic NOT_NULL;
180
+ @dynamic PRIMARY_KEY;
181
+ @dynamic AUTO_INREMENT;
182
+ @dynamic DEFAULT_ZERO;
183
+ @dynamic DEFAULT_NULL;
184
+ @dynamic DEFAULT;
185
+ @dynamic UNIQUE;
186
+ @dynamic CREATE_IF_NOT_EXISTS;
187
+ @dynamic INDEX_ON;
188
+
189
+ @dynamic SELECT;
190
+ @dynamic SELECT_MAX;
191
+ @dynamic SELECT_MAX_ALIAS;
192
+ @dynamic SELECT_MIN;
193
+ @dynamic SELECT_MIN_ALIAS;
194
+ @dynamic SELECT_AVG;
195
+ @dynamic SELECT_AVG_ALIAS;
196
+ @dynamic SELECT_SUM;
197
+ @dynamic SELECT_SUM_ALIAS;
198
+
199
+ @dynamic DISTINCT;
200
+ @dynamic FROM;
201
+
202
+ @dynamic WHERE;
203
+ @dynamic OR_WHERE;
204
+
205
+ @dynamic WHERE_IN;
206
+ @dynamic OR_WHERE_IN;
207
+ @dynamic WHERE_NOT_IN;
208
+ @dynamic OR_WHERE_NOT_IN;
209
+
210
+ @dynamic LIKE;
211
+ @dynamic NOT_LIKE;
212
+ @dynamic OR_LIKE;
213
+ @dynamic OR_NOT_LIKE;
214
+
215
+ @dynamic GROUP_BY;
216
+
217
+ @dynamic HAVING;
218
+ @dynamic OR_HAVING;
219
+
220
+ @dynamic ORDER_ASC_BY;
221
+ @dynamic ORDER_DESC_BY;
222
+ @dynamic ORDER_RAND_BY;
223
+ @dynamic ORDER_BY;
224
+
225
+ @dynamic LIMIT;
226
+ @dynamic OFFSET;
227
+
228
+ @dynamic SET;
229
+ @dynamic SET_NULL;
230
+
231
+ @dynamic GET;
232
+ @dynamic COUNT;
233
+
234
+ @dynamic INSERT;
235
+ @dynamic UPDATE;
236
+ @dynamic EMPTY;
237
+ @dynamic TRUNCATE;
238
+ @dynamic DELETE;
239
+
240
+ @dynamic BATCH_BEGIN;
241
+ @dynamic BATCH_END;
242
+
243
+ @dynamic CLASS_TYPE;
244
+ @dynamic ASSOCIATE;
245
+ @dynamic HAS;
246
+
247
+ @dynamic resultArray;
248
+ @dynamic resultCount;
249
+ @dynamic insertID;
250
+ @dynamic succeed;
251
+
252
+ @synthesize lastQuery = _lastQuery;
253
+ @synthesize lastUpdate = _lastUpdate;
254
+
255
+ static NSMutableArray * __shadowDBs = nil;
256
+ static BeeDatabase * __sharedDB = nil;
257
+ static NSUInteger __identSeed = 1;
258
+
259
+ - (NSArray *)resultArray
260
+ {
261
+ [self __internalResetSelect];
262
+ [self __internalResetWrite];
263
+ [self __internalResetCreate];
264
+
265
+ // [self __internalResetResult];
266
+
267
+ return [[[NSMutableArray alloc] initWithArray:_resultArray] autorelease];
268
+ }
269
+
270
+ - (NSUInteger)resultCount
271
+ {
272
+ [self __internalResetSelect];
273
+ [self __internalResetWrite];
274
+ [self __internalResetCreate];
275
+
276
+ return _resultCount;
277
+ }
278
+
279
+ - (NSInteger)insertID
280
+ {
281
+ [self __internalResetSelect];
282
+ [self __internalResetWrite];
283
+ [self __internalResetCreate];
284
+
285
+ return _lastInsertID;
286
+ }
287
+
288
+ - (BOOL)succeed
289
+ {
290
+ [self __internalResetSelect];
291
+ [self __internalResetWrite];
292
+ [self __internalResetCreate];
293
+
294
+ return _lastSucceed;
295
+ }
296
+
297
+ - (NSUInteger)total
298
+ {
299
+ NSUInteger count = [self count];
300
+
301
+ [self __internalResetSelect];
302
+ [self __internalResetWrite];
303
+ [self __internalResetCreate];
304
+
305
+ return count;
306
+ }
307
+
308
+ - (void)initSelf
309
+ {
310
+ _select = [[NSMutableArray alloc] init];
311
+ _distinct = NO;
312
+ _from = [[NSMutableArray alloc] init];
313
+ _where = [[NSMutableArray alloc] init];
314
+ _like = [[NSMutableArray alloc] init];
315
+ _groupby = [[NSMutableArray alloc] init];
316
+ _having = [[NSMutableArray alloc] init];
317
+ _keys = [[NSMutableArray alloc] init];
318
+ _limit = 0;
319
+ _offset = 0;
320
+ _orderby = [[NSMutableArray alloc] init];
321
+ _set = [[NSMutableDictionary alloc] init];
322
+ _classType = [[NSMutableArray alloc] init];
323
+ _associate = [[NSMutableArray nonRetainingArray] retain];
324
+ _has = [[NSMutableArray nonRetainingArray] retain];
325
+
326
+ _table = [[NSMutableArray alloc] init];
327
+ _field = [[NSMutableArray alloc] init];
328
+ _index = [[NSMutableArray alloc] init];
329
+
330
+ _resultArray = [[NSMutableArray alloc] init];
331
+ _resultCount = 0;
332
+
333
+ _identifier = __identSeed++;
334
+
335
+ _lastQuery = [NSDate timeIntervalSinceReferenceDate];
336
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
337
+ }
338
+
339
+ + (BOOL)openSharedDatabase:(NSString *)path
340
+ {
341
+ if ( __sharedDB.ready && [__sharedDB.filePath isEqualToString:path] )
342
+ return YES;
343
+
344
+ [self closeSharedDatabase];
345
+
346
+ __sharedDB = [[[self class] alloc] initWithPath:path];
347
+ if ( __sharedDB )
348
+ {
349
+ if ( NO == __sharedDB.ready )
350
+ {
351
+ [__sharedDB release];
352
+ __sharedDB = nil;
353
+ }
354
+ }
355
+
356
+ return (__sharedDB && __sharedDB.ready) ? YES : NO;
357
+ }
358
+
359
+ + (BOOL)existsSharedDatabase:(NSString *)path
360
+ {
361
+ return [BeeDatabase exists:path];
362
+ }
363
+
364
+ + (void)closeSharedDatabase
365
+ {
366
+ if ( __shadowDBs )
367
+ {
368
+ for ( BeeDatabase * db in __shadowDBs )
369
+ {
370
+ [db close];
371
+ }
372
+
373
+ [__shadowDBs removeAllObjects];
374
+ [__shadowDBs release];
375
+ __shadowDBs = nil;
376
+ }
377
+
378
+ [__sharedDB close];
379
+ [__sharedDB release];
380
+ __sharedDB = nil;
381
+
382
+ [self resetPrepareFlags];
383
+ }
384
+
385
+ + (void)setSharedDatabase:(BeeDatabase *)db
386
+ {
387
+ if ( db != __sharedDB )
388
+ {
389
+ [db retain];
390
+
391
+ if ( __shadowDBs )
392
+ {
393
+ for ( BeeDatabase * db in __shadowDBs )
394
+ {
395
+ [db close];
396
+ }
397
+
398
+ [__shadowDBs removeAllObjects];
399
+ [__shadowDBs release];
400
+ __shadowDBs = nil;
401
+ }
402
+
403
+ [__sharedDB close];
404
+ [__sharedDB release];
405
+ __sharedDB = db;
406
+ }
407
+
408
+ [self resetPrepareFlags];
409
+ }
410
+
411
+ + (BeeDatabase *)sharedDatabase
412
+ {
413
+ if ( __shadowDBs.count )
414
+ {
415
+ return (BeeDatabase *)__shadowDBs.lastObject;
416
+ }
417
+
418
+ return __sharedDB;
419
+ }
420
+
421
+ + (void)scopeEnter
422
+ {
423
+ if ( __sharedDB )
424
+ {
425
+ BeeDatabase * db = [[BeeDatabase alloc] initWithDatabase:__sharedDB.database];
426
+ if ( db )
427
+ {
428
+ db.shadow = YES;
429
+
430
+ if ( nil == __shadowDBs )
431
+ {
432
+ __shadowDBs = [[NSMutableArray alloc] init];
433
+ }
434
+
435
+ [__shadowDBs addObject:db];
436
+
437
+ [db release];
438
+ }
439
+ }
440
+ }
441
+
442
+ + (void)scopeLeave
443
+ {
444
+ if ( __shadowDBs && __shadowDBs.count )
445
+ {
446
+ [__shadowDBs removeObject:__shadowDBs.lastObject];
447
+ }
448
+ }
449
+
450
+ - (id)init
451
+ {
452
+ self = [super init];
453
+ if ( self )
454
+ {
455
+ [self initSelf];
456
+ }
457
+ return self;
458
+ }
459
+
460
+ - (id)initWithDatabase:(FMDatabase *)db
461
+ {
462
+ self = [super init];
463
+ if ( self )
464
+ {
465
+ [self initSelf];
466
+
467
+ CC( @"[DB] open shadow '%p'", db );
468
+
469
+ self.database = db;
470
+ self.filePath = db.databasePath;
471
+ }
472
+ return self;
473
+ }
474
+
475
+ - (id)initWithPath:(NSString *)path
476
+ {
477
+ self = [super init];
478
+ if ( self )
479
+ {
480
+ [self initSelf];
481
+ [self open:path];
482
+ }
483
+ return self;
484
+ }
485
+
486
+ - (BOOL)ready
487
+ {
488
+ if ( nil == _database )
489
+ return NO;
490
+
491
+ return _database.open;
492
+ }
493
+
494
+ + (BOOL)isFullPath:(NSString *)path
495
+ {
496
+ if ( [[path componentsSeparatedByString:@"/"] count] > 1 )
497
+ {
498
+ return YES;
499
+ }
500
+
501
+ return NO;
502
+ }
503
+
504
+ + (NSString *)storePath:(NSString *)path
505
+ {
506
+ if ( [BeeDatabase isFullPath:path] )
507
+ {
508
+ return path;
509
+ }
510
+
511
+ NSString * fullPath = [NSString stringWithFormat:@"%@/BeeDatabase/", [BeeSandbox docPath]];
512
+ NSString * fullName = [fullPath stringByAppendingString:path];
513
+ return fullName;
514
+ }
515
+
516
+ + (BOOL)exists:(NSString *)path;
517
+ {
518
+ NSFileManager * manager = [NSFileManager defaultManager];
519
+ NSString * fullName = [BeeDatabase storePath:path];
520
+ BOOL isDirectory = NO;
521
+ BOOL returnValue = [manager fileExistsAtPath:fullName isDirectory:&isDirectory];
522
+ if ( NO == returnValue || YES == isDirectory )
523
+ return NO;
524
+
525
+ return YES;
526
+ }
527
+
528
+ - (BOOL)open:(NSString *)path
529
+ {
530
+ if ( _filePath && [_filePath isEqualToString:path] )
531
+ return YES;
532
+
533
+ [self close];
534
+
535
+ CC( @"[DB] open at '%@'", path );
536
+
537
+ NSFileManager * manager = [NSFileManager defaultManager];
538
+
539
+ if ( NO == [BeeDatabase isFullPath:path] )
540
+ {
541
+ NSString * fullPath = [NSString stringWithFormat:@"%@/BeeDatabase/", [BeeSandbox docPath]];
542
+ if ( NO == [manager fileExistsAtPath:fullPath isDirectory:NULL] )
543
+ {
544
+ BOOL ret = [manager createDirectoryAtPath:fullPath
545
+ withIntermediateDirectories:YES
546
+ attributes:nil
547
+ error:nil];
548
+ if ( NO == ret )
549
+ return NO;
550
+ }
551
+ }
552
+
553
+ _database = [[FMDatabase alloc] initWithPath:[BeeDatabase storePath:path]];
554
+ if ( nil == _database )
555
+ return NO;
556
+
557
+ BOOL ret = [_database open];
558
+ if ( NO == ret )
559
+ {
560
+ [_database release];
561
+ _database = nil;
562
+ return NO;
563
+ }
564
+
565
+ #if defined(__BEE_DEVELOPMENT__) && __BEE_DEVELOPMENT__
566
+ _database.traceExecution = YES;
567
+ _database.logsErrors = YES;
568
+ #endif // #if defined(__BEE_DEVELOPMENT__) && __BEE_DEVELOPMENT__
569
+
570
+ self.filePath = path;
571
+ return YES;
572
+ }
573
+
574
+ - (void)close
575
+ {
576
+ if ( _database )
577
+ {
578
+ if ( NO == _shadow )
579
+ {
580
+ CC( @"[DB] close '%p'", _database );
581
+
582
+ [_database close];
583
+ }
584
+ else
585
+ {
586
+ CC( @"[DB] close shadow '%p'", _database );
587
+ }
588
+
589
+ [_database release];
590
+ _database = nil;
591
+ }
592
+
593
+ _lastQuery = [NSDate timeIntervalSinceReferenceDate];
594
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
595
+ }
596
+
597
+ - (void)clearState
598
+ {
599
+ [self __internalResetCreate];
600
+ [self __internalResetWrite];
601
+ [self __internalResetSelect];
602
+ }
603
+
604
+ - (void)dealloc
605
+ {
606
+ [self close];
607
+
608
+ [_database release];
609
+ _database = nil;
610
+
611
+ [_filePath release];
612
+
613
+ [_select removeAllObjects];
614
+ [_select release];
615
+
616
+ [_from removeAllObjects];
617
+ [_from release];
618
+
619
+ [_where removeAllObjects];
620
+ [_where release];
621
+
622
+ [_like removeAllObjects];
623
+ [_like release];
624
+
625
+ [_groupby removeAllObjects];
626
+ [_groupby release];
627
+
628
+ [_having removeAllObjects];
629
+ [_having release];
630
+
631
+ [_keys removeAllObjects];
632
+ [_keys release];
633
+
634
+ [_orderby removeAllObjects];
635
+ [_orderby release];
636
+
637
+ [_set removeAllObjects];
638
+ [_set release];
639
+
640
+ [_field removeAllObjects];
641
+ [_field release];
642
+
643
+ [_table removeAllObjects];
644
+ [_table release];
645
+
646
+ [_index removeAllObjects];
647
+ [_index release];
648
+
649
+ [_resultArray removeAllObjects];
650
+ [_resultArray release];
651
+
652
+ [_classType removeAllObjects];
653
+ [_classType release];
654
+
655
+ [_associate removeAllObjects];
656
+ [_associate release];
657
+
658
+ [_has removeAllObjects];
659
+ [_has release];
660
+
661
+ [super dealloc];
662
+ }
663
+
664
+ - (void)__internalResetCreate
665
+ {
666
+ [_field removeAllObjects];
667
+ [_table removeAllObjects];
668
+ [_index removeAllObjects];
669
+
670
+ if ( NO == _batch )
671
+ {
672
+ [_classType removeAllObjects];
673
+ [_associate removeAllObjects];
674
+ [_has removeAllObjects];
675
+ }
676
+ }
677
+
678
+ - (BeeDatabase *)table:(NSString *)name
679
+ {
680
+ if ( nil == _database )
681
+ return self;
682
+
683
+ if ( nil == name )
684
+ return self;
685
+
686
+ for ( NSString * table in _table )
687
+ {
688
+ if ( NSOrderedSame == [table compare:name options:NSCaseInsensitiveSearch] )
689
+ return self;
690
+ }
691
+
692
+ [_table addObject:name];
693
+ return self;
694
+ }
695
+
696
+ - (BeeDatabase *)field:(NSString *)name type:(NSString *)type size:(NSUInteger)size
697
+ {
698
+ if ( nil == _database )
699
+ return self;
700
+
701
+ name = [[self class] fieldNameForIdentifier:name];
702
+
703
+ for ( NSMutableDictionary * dict in _field )
704
+ {
705
+ NSString * name2 = [dict objectForKey:@"name"];
706
+ if ( NSOrderedSame == [name2 compare:name options:NSCaseInsensitiveSearch] )
707
+ {
708
+ if ( type )
709
+ {
710
+ [dict setObject:type forKey:@"type"];
711
+ }
712
+ if ( size )
713
+ {
714
+ [dict setObject:__INT(size) forKey:@"size"];
715
+ }
716
+ return self;
717
+ }
718
+ }
719
+
720
+ [_field addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
721
+ name ? name : @"", @"name",
722
+ type ? type : @"int", @"type",
723
+ __INT(size), @"size",
724
+ nil]];
725
+
726
+ return self;
727
+ }
728
+
729
+ - (BeeDatabase *)unsignedType
730
+ {
731
+ if ( nil == _database )
732
+ return self;
733
+
734
+ NSMutableDictionary * dict = (NSMutableDictionary *)_field.lastObject;
735
+ if ( nil == dict )
736
+ return self;
737
+
738
+ [dict setObject:__INT(1) forKey:@"unsigned"];
739
+ return self;
740
+ }
741
+
742
+ - (BeeDatabase *)notNull
743
+ {
744
+ if ( nil == _database )
745
+ return self;
746
+
747
+ NSMutableDictionary * dict = (NSMutableDictionary *)_field.lastObject;
748
+ if ( nil == dict )
749
+ return self;
750
+
751
+ [dict setObject:__INT(1) forKey:@"notNull"];
752
+ return self;
753
+ }
754
+
755
+ - (BeeDatabase *)primaryKey
756
+ {
757
+ if ( nil == _database )
758
+ return self;
759
+
760
+ NSMutableDictionary * dict = (NSMutableDictionary *)_field.lastObject;
761
+ if ( nil == dict )
762
+ return self;
763
+
764
+ [dict setObject:__INT(1) forKey:@"primaryKey"];
765
+ return self;
766
+ }
767
+
768
+ - (BeeDatabase *)autoIncrement
769
+ {
770
+ if ( nil == _database )
771
+ return self;
772
+
773
+ NSMutableDictionary * dict = (NSMutableDictionary *)_field.lastObject;
774
+ if ( nil == dict )
775
+ return self;
776
+
777
+ [dict setObject:__INT(1) forKey:@"autoIncrement"];
778
+ return self;
779
+ }
780
+
781
+ - (BeeDatabase *)defaultZero
782
+ {
783
+ return [self defaultValue:__INT(0)];
784
+ }
785
+
786
+ - (BeeDatabase *)defaultNull
787
+ {
788
+ return [self defaultValue:[NSNull null]];
789
+ }
790
+
791
+ - (BeeDatabase *)defaultValue:(id)value
792
+ {
793
+ if ( nil == _database )
794
+ return self;
795
+
796
+ NSMutableDictionary * dict = (NSMutableDictionary *)_field.lastObject;
797
+ if ( nil == dict )
798
+ return self;
799
+
800
+ [dict setObject:value forKey:@"default"];
801
+ return self;
802
+ }
803
+
804
+ - (BeeDatabase *)unique
805
+ {
806
+ if ( nil == _database )
807
+ return self;
808
+
809
+ NSMutableDictionary * dict = (NSMutableDictionary *)_field.lastObject;
810
+ if ( nil == dict )
811
+ return self;
812
+
813
+ [dict setObject:__INT(1) forKey:@"unique"];
814
+ return self;
815
+ }
816
+
817
+ - (BOOL)createTableIfNotExists
818
+ {
819
+ return [self createTableIfNotExists:nil];
820
+ }
821
+
822
+ - (BOOL)createTableIfNotExists:(NSString *)table
823
+ {
824
+ [self __internalResetResult];
825
+
826
+ if ( nil == _database )
827
+ return NO;
828
+
829
+ if ( 0 == _table.count )
830
+ return NO;
831
+
832
+ if ( nil == table )
833
+ {
834
+ table = (NSString *)_table.lastObject;
835
+ }
836
+
837
+ if ( nil == table || 0 == table.length )
838
+ return NO;
839
+
840
+ if ( 0 == _field.count )
841
+ return NO;
842
+
843
+ NSString * sql = [self internalCompileCreate:table];
844
+ [self __internalResetCreate];
845
+
846
+ BOOL ret = [_database executeUpdate:sql];
847
+ if ( ret )
848
+ {
849
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
850
+ _lastSucceed = YES;
851
+ }
852
+
853
+ return ret;
854
+ }
855
+
856
+ - (NSString *)internalCompileCreate:(NSString *)table
857
+ {
858
+ NSMutableString * sql = [NSMutableString string];
859
+
860
+ [sql appendFormat:@"CREATE TABLE IF NOT EXISTS %@ ( ", table];
861
+
862
+ for ( NSInteger i = 0; i < _field.count; ++i )
863
+ {
864
+ NSDictionary * dict = [_field objectAtIndex:i];
865
+
866
+ NSString * name = (NSString *)[dict objectForKey:@"name"];
867
+ NSString * type = (NSString *)[dict objectForKey:@"type"];
868
+ NSNumber * size = (NSNumber *)[dict objectForKey:@"size"];
869
+ NSNumber * PK = (NSNumber *)[dict objectForKey:@"primaryKey"];
870
+ NSNumber * AI = (NSNumber *)[dict objectForKey:@"autoIncrement"];
871
+ NSNumber * UN = (NSNumber *)[dict objectForKey:@"unique"];
872
+ NSNumber * NN = (NSNumber *)[dict objectForKey:@"notNull"];
873
+
874
+ NSObject * defaultValue = [dict objectForKey:@"default"];
875
+
876
+ if ( 0 == i )
877
+ {
878
+ [sql appendFormat:@"%@", name];
879
+ }
880
+ else
881
+ {
882
+ [sql appendFormat:@", %@", name];
883
+ }
884
+
885
+ if ( type )
886
+ {
887
+ [sql appendFormat:@" %@", type];
888
+ }
889
+
890
+ if ( size && size.intValue )
891
+ {
892
+ [sql appendFormat:@"(%@)", size];
893
+ }
894
+
895
+ if ( PK && PK.intValue )
896
+ {
897
+ [sql appendString:@" PRIMARY KEY"];
898
+ }
899
+
900
+ if ( AI && AI.intValue )
901
+ {
902
+ [sql appendString:@" AUTOINCREMENT"];
903
+ }
904
+
905
+ if ( UN && UN.intValue )
906
+ {
907
+ [sql appendString:@" UNIQUE"];
908
+ }
909
+
910
+ if ( NN && NN.intValue )
911
+ {
912
+ [sql appendString:@" NOT NULL"];
913
+ }
914
+
915
+ if ( defaultValue )
916
+ {
917
+ if ( [defaultValue isKindOfClass:[NSNull class]] )
918
+ {
919
+ [sql appendString:@" DEFAULT NULL"];
920
+ }
921
+ else
922
+ {
923
+ [sql appendFormat:@" DEFAULT '%@'", defaultValue];
924
+ }
925
+ }
926
+ }
927
+
928
+ [sql appendString:@" )"];
929
+
930
+ return sql;
931
+ }
932
+
933
+ - (BOOL)indexTableOn:(NSArray *)fields
934
+ {
935
+ [self __internalResetResult];
936
+
937
+ if ( nil == _database )
938
+ return NO;
939
+
940
+ if ( nil == fields || 0 == fields.count )
941
+ return NO;
942
+
943
+ if ( 0 == _table.count )
944
+ return NO;
945
+
946
+ NSString * table = (NSString *)_table.lastObject;
947
+ if ( nil == table || 0 == table.length )
948
+ return NO;
949
+
950
+ for ( NSString * field in fields )
951
+ {
952
+ field = [[self class] fieldNameForIdentifier:field];
953
+ [_index addObject:field];
954
+ }
955
+
956
+ if ( 0 == _index.count )
957
+ return NO;
958
+
959
+ NSString * sql = [self internalCompileIndex:table];
960
+ [self __internalResetCreate];
961
+
962
+ BOOL ret = [_database executeUpdate:sql];
963
+ if ( ret )
964
+ {
965
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
966
+ _lastSucceed = YES;
967
+ }
968
+
969
+ return ret;
970
+ }
971
+
972
+ - (BOOL)indexTable:(NSString *)table on:(NSArray *)fields
973
+ {
974
+ [self __internalResetResult];
975
+
976
+ if ( nil == _database )
977
+ return NO;
978
+
979
+ if ( nil == fields || 0 == fields.count )
980
+ return NO;
981
+
982
+ if ( 0 == _table.count )
983
+ return NO;
984
+
985
+ if ( nil == table )
986
+ {
987
+ table = (NSString *)_table.lastObject;
988
+ }
989
+ if ( nil == table || 0 == table.length )
990
+ return NO;
991
+
992
+ for ( NSString * field in fields )
993
+ {
994
+ field = [[self class] fieldNameForIdentifier:field];
995
+ [_index addObject:field];
996
+ }
997
+
998
+ if ( 0 == _index.count )
999
+ return NO;
1000
+
1001
+ NSString * sql = [self internalCompileIndex:table];
1002
+ [self __internalResetCreate];
1003
+
1004
+ BOOL ret = [_database executeUpdate:sql];
1005
+ if ( ret )
1006
+ {
1007
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
1008
+ _lastSucceed = YES;
1009
+ }
1010
+
1011
+ return ret;
1012
+ }
1013
+
1014
+ - (NSString *)internalCompileIndex:(NSString *)table
1015
+ {
1016
+ NSMutableString * sql = [NSMutableString string];
1017
+
1018
+ [sql appendFormat:@"CREATE INDEX IF NOT EXISTS index_%@ ON %@ ( ", table, table];
1019
+
1020
+ for ( NSInteger i = 0; i < _index.count; ++i )
1021
+ {
1022
+ NSString * field = [_index objectAtIndex:i];
1023
+
1024
+ if ( 0 == i )
1025
+ {
1026
+ [sql appendFormat:@"%@", field];
1027
+ }
1028
+ else
1029
+ {
1030
+ [sql appendFormat:@", %@", field];
1031
+ }
1032
+ }
1033
+
1034
+ [sql appendString:@" )"];
1035
+
1036
+ return sql;
1037
+ }
1038
+
1039
+ - (BOOL)existsTable:(NSString *)table
1040
+ {
1041
+ FMResultSet * result = [_database executeQuery:@"SELECT COUNT(*) as 'numrows' FROM sqlite_master WHERE type ='table' AND name = ?", table];
1042
+ if ( nil == result )
1043
+ return NO;
1044
+
1045
+ _lastQuery = [NSDate timeIntervalSinceReferenceDate];
1046
+
1047
+ BOOL succed = [result next];
1048
+ if ( NO == succed )
1049
+ return NO;
1050
+
1051
+ NSDictionary * dict = [result resultDictionary];
1052
+ if ( nil == dict )
1053
+ return NO;
1054
+
1055
+ NSNumber * numrows = [dict objectForKey:@"numrows"];
1056
+ if ( nil == numrows )
1057
+ return NO;
1058
+
1059
+ return numrows.intValue ? YES : NO;
1060
+ }
1061
+
1062
+ - (void)__internalResetSelect
1063
+ {
1064
+ [_select removeAllObjects];
1065
+ [_from removeAllObjects];
1066
+ [_where removeAllObjects];
1067
+ [_like removeAllObjects];
1068
+ [_groupby removeAllObjects];
1069
+ [_having removeAllObjects];
1070
+ [_orderby removeAllObjects];
1071
+
1072
+ if ( NO == _batch )
1073
+ {
1074
+ [_classType removeAllObjects];
1075
+ [_associate removeAllObjects];
1076
+ [_has removeAllObjects];
1077
+ }
1078
+
1079
+ _distinct = NO;
1080
+ _limit = 0;
1081
+ _offset = 0;
1082
+ }
1083
+
1084
+ - (void)__internalResetWrite
1085
+ {
1086
+ [_set removeAllObjects];
1087
+ [_from removeAllObjects];
1088
+ [_where removeAllObjects];
1089
+ [_like removeAllObjects];
1090
+ [_orderby removeAllObjects];
1091
+ [_keys removeAllObjects];
1092
+
1093
+ if ( NO == _batch )
1094
+ {
1095
+ [_classType removeAllObjects];
1096
+ [_associate removeAllObjects];
1097
+ [_has removeAllObjects];
1098
+ }
1099
+
1100
+ _limit = 0;
1101
+ }
1102
+
1103
+ - (BeeDatabase *)select:(NSString *)select
1104
+ {
1105
+ if ( nil == _database )
1106
+ return self;
1107
+
1108
+ if ( nil == select )
1109
+ return self;
1110
+
1111
+ NSArray * components = [select componentsSeparatedByString:@","];
1112
+ for ( NSString * component in components )
1113
+ {
1114
+ component = [component trim];
1115
+ if ( component && component.length )
1116
+ {
1117
+ [_select addObject:component];
1118
+ }
1119
+ }
1120
+
1121
+ return self;
1122
+ }
1123
+
1124
+ - (BeeDatabase *)selectMax:(NSString *)select
1125
+ {
1126
+ return [self selectMax:select alias:nil];
1127
+ }
1128
+
1129
+ - (BeeDatabase *)selectMax:(NSString *)select alias:(NSString *)alias
1130
+ {
1131
+ if ( nil == _database )
1132
+ return self;
1133
+
1134
+ [self internalSelect:select alias:alias type:@"MAX"];
1135
+ return self;
1136
+ }
1137
+
1138
+ - (BeeDatabase *)selectMin:(NSString *)select
1139
+ {
1140
+ return [self selectMin:select alias:nil];
1141
+ }
1142
+
1143
+ - (BeeDatabase *)selectMin:(NSString *)select alias:(NSString *)alias
1144
+ {
1145
+ if ( nil == _database )
1146
+ return self;
1147
+
1148
+ [self internalSelect:select alias:alias type:@"MIN"];
1149
+ return self;
1150
+ }
1151
+
1152
+ - (BeeDatabase *)selectAvg:(NSString *)select
1153
+ {
1154
+ return [self selectAvg:select alias:nil];
1155
+ }
1156
+
1157
+ - (BeeDatabase *)selectAvg:(NSString *)select alias:(NSString *)alias
1158
+ {
1159
+ if ( nil == _database )
1160
+ return self;
1161
+
1162
+ [self internalSelect:select alias:alias type:@"AVG"];
1163
+ return self;
1164
+ }
1165
+
1166
+ - (BeeDatabase *)selectSum:(NSString *)select
1167
+ {
1168
+ return [self selectSum:select alias:nil];
1169
+ }
1170
+
1171
+ - (BeeDatabase *)selectSum:(NSString *)select alias:(NSString *)alias
1172
+ {
1173
+ if ( nil == _database )
1174
+ return self;
1175
+
1176
+ [self internalSelect:select alias:alias type:@"SUM"];
1177
+ return self;
1178
+ }
1179
+
1180
+ - (void)internalSelect:(NSString *)select alias:(NSString *)alias type:(NSString *)type
1181
+ {
1182
+ if ( nil == select )
1183
+ return;
1184
+
1185
+ if ( nil == alias || 0 == alias.length )
1186
+ {
1187
+ alias = [self internalCreateAliasFromTable:alias];
1188
+ }
1189
+
1190
+ NSString * sql = [NSString stringWithFormat:@"%@(%@) AS %@", type, [select trim], alias];
1191
+
1192
+ [_select addObject:sql];
1193
+ }
1194
+
1195
+ - (NSString *)internalCreateAliasFromTable:(NSString *)name
1196
+ {
1197
+ NSRange range = [name rangeOfString:@"."];
1198
+ if ( range.length )
1199
+ {
1200
+ NSArray * array = [name componentsSeparatedByString:@"."];
1201
+ if ( array && array.count )
1202
+ {
1203
+ return array.lastObject;
1204
+ }
1205
+ }
1206
+
1207
+ return name;
1208
+ }
1209
+
1210
+ - (BeeDatabase *)distinct:(BOOL)flag
1211
+ {
1212
+ if ( nil == _database )
1213
+ return self;
1214
+
1215
+ _distinct = flag;
1216
+ return self;
1217
+ }
1218
+
1219
+ - (BeeDatabase *)from:(NSString *)from
1220
+ {
1221
+ if ( nil == _database )
1222
+ return self;
1223
+
1224
+ if ( nil == from )
1225
+ return self;
1226
+
1227
+ for ( NSString * table in _from )
1228
+ {
1229
+ if ( NSOrderedSame == [table compare:from options:NSCaseInsensitiveSearch] )
1230
+ return self;
1231
+ }
1232
+
1233
+ [_from addObject:from.trim];
1234
+ return self;
1235
+ }
1236
+
1237
+ - (void)internalWhere:(NSString *)key value:(NSObject *)value type:(NSString *)type
1238
+ {
1239
+ NSString * prefix = (0 == _where.count) ? @"" : type;
1240
+ NSString * sql = nil;
1241
+
1242
+ key = [[self class] fieldNameForIdentifier:key];
1243
+
1244
+ if ( nil == value )
1245
+ {
1246
+ sql = [NSString stringWithFormat:@"%@ %@ IS NULL", prefix, key];
1247
+ }
1248
+ else
1249
+ {
1250
+ if ( [value isKindOfClass:[NSNumber class]] )
1251
+ {
1252
+ sql = [NSString stringWithFormat:@"%@ %@ = %@", prefix, key, value];
1253
+ }
1254
+ else
1255
+ {
1256
+ sql = [NSString stringWithFormat:@"%@ %@ = '%@'", prefix, key, value];
1257
+ }
1258
+ }
1259
+
1260
+ [_where addObject:sql];
1261
+ }
1262
+
1263
+ - (BeeDatabase *)where:(NSString *)key value:(id)value
1264
+ {
1265
+ if ( nil == _database )
1266
+ return self;
1267
+
1268
+ [self internalWhere:key value:value type:@"AND"];
1269
+ return self;
1270
+ }
1271
+
1272
+ - (BeeDatabase *)orWhere:(NSString *)key value:(id)value
1273
+ {
1274
+ if ( nil == _database )
1275
+ return self;
1276
+
1277
+ [self internalWhere:key value:value type:@"OR"];
1278
+ return self;
1279
+ }
1280
+
1281
+ - (BeeDatabase *)whereIn:(NSString *)key values:(NSArray *)values
1282
+ {
1283
+ if ( nil == _database )
1284
+ return self;
1285
+
1286
+ [self internalWhereIn:key values:values not:NO type:@"AND"];
1287
+ return self;
1288
+ }
1289
+
1290
+ - (BeeDatabase *)orWhereIn:(NSString *)key values:(NSArray *)values
1291
+ {
1292
+ if ( nil == _database )
1293
+ return self;
1294
+
1295
+ [self internalWhereIn:key values:values not:NO type:@"OR"];
1296
+ return self;
1297
+ }
1298
+
1299
+ - (BeeDatabase *)whereNotIn:(NSString *)key values:(NSArray *)values
1300
+ {
1301
+ if ( nil == _database )
1302
+ return self;
1303
+
1304
+ [self internalWhereIn:key values:values not:YES type:@"AND"];
1305
+ return self;
1306
+ }
1307
+
1308
+ - (BeeDatabase *)orWhereNotIn:(NSString *)key values:(NSArray *)values
1309
+ {
1310
+ if ( nil == _database )
1311
+ return self;
1312
+
1313
+ [self internalWhereIn:key values:values not:YES type:@"OR"];
1314
+ return self;
1315
+ }
1316
+
1317
+ - (void)internalWhereIn:(NSString *)key values:(NSArray *)values not:(BOOL)not type:(NSString *)type
1318
+ {
1319
+ if ( nil == key || nil == values || 0 == values.count )
1320
+ return;
1321
+
1322
+ key = [[self class] fieldNameForIdentifier:key];
1323
+
1324
+ NSMutableString * sql = [NSMutableString string];
1325
+
1326
+ if ( _where.count )
1327
+ {
1328
+ [sql appendFormat:@"%@ ", type];
1329
+ }
1330
+
1331
+ [sql appendString:key];
1332
+
1333
+ if ( not )
1334
+ {
1335
+ [sql appendString:@" NOT"];
1336
+ }
1337
+
1338
+ [sql appendString:@" IN ("];
1339
+
1340
+ for ( NSInteger i = 0; i < values.count; ++i )
1341
+ {
1342
+ NSObject * value = [values objectAtIndex:i];
1343
+
1344
+ if ( i > 0 )
1345
+ {
1346
+ [sql appendFormat:@", "];
1347
+ }
1348
+
1349
+ if ( [value isKindOfClass:[NSNumber class]] )
1350
+ {
1351
+ [sql appendFormat:@"%@", value];
1352
+ }
1353
+ else
1354
+ {
1355
+ [sql appendFormat:@"'%@'", value];
1356
+ }
1357
+ }
1358
+
1359
+ [sql appendString:@")"];
1360
+
1361
+ [_where addObject:sql];
1362
+ }
1363
+
1364
+ - (BeeDatabase *)like:(NSString *)field match:(id)value
1365
+ {
1366
+ if ( nil == _database )
1367
+ return self;
1368
+
1369
+ [self internalLike:field match:value type:@"AND" side:@"both" not:NO];
1370
+ return self;
1371
+ }
1372
+
1373
+ - (BeeDatabase *)notLike:(NSString *)field match:(id)value
1374
+ {
1375
+ if ( nil == _database )
1376
+ return self;
1377
+
1378
+ [self internalLike:field match:value type:@"AND" side:@"both" not:YES];
1379
+ return self;
1380
+ }
1381
+
1382
+ - (BeeDatabase *)orLike:(NSString *)field match:(id)value
1383
+ {
1384
+ if ( nil == _database )
1385
+ return self;
1386
+
1387
+ [self internalLike:field match:value type:@"OR" side:@"both" not:NO];
1388
+ return self;
1389
+ }
1390
+
1391
+ - (BeeDatabase *)orNotLike:(NSString *)field match:(id)value
1392
+ {
1393
+ if ( nil == _database )
1394
+ return self;
1395
+
1396
+ [self internalLike:field match:value type:@"OR" side:@"both" not:YES];
1397
+ return self;
1398
+ }
1399
+
1400
+ - (void)internalLike:(NSString *)field match:(NSObject *)match type:(NSString *)type side:(NSString *)side not:(BOOL)not
1401
+ {
1402
+ if ( nil == field || nil == match )
1403
+ return;
1404
+
1405
+ field = [[self class] fieldNameForIdentifier:field];
1406
+
1407
+ NSString * value = nil;
1408
+
1409
+ if ( [side isEqualToString:@"before"] )
1410
+ {
1411
+ value = [NSString stringWithFormat:@"%%%@", match];
1412
+ }
1413
+ else if ( [side isEqualToString:@"after"] )
1414
+ {
1415
+ value = [NSString stringWithFormat:@"%@%%", match];
1416
+ }
1417
+ else
1418
+ {
1419
+ value = [NSString stringWithFormat:@"%%%@%%", match];
1420
+ }
1421
+
1422
+ NSMutableString * sql = [NSMutableString string];
1423
+
1424
+ if ( _like.count )
1425
+ {
1426
+ [sql appendString:type];
1427
+ }
1428
+
1429
+ [sql appendFormat:@" %@", field];
1430
+
1431
+ if ( not )
1432
+ {
1433
+ [sql appendString:@" NOT"];
1434
+ }
1435
+
1436
+ [sql appendFormat:@" LIKE '%@'", value];
1437
+
1438
+ [_like addObject:sql];
1439
+ }
1440
+
1441
+ - (BeeDatabase *)groupBy:(NSString *)by
1442
+ {
1443
+ if ( nil == _database )
1444
+ return self;
1445
+
1446
+ by = [[self class] fieldNameForIdentifier:by];
1447
+
1448
+ [_groupby addObject:by];
1449
+
1450
+ return self;
1451
+ }
1452
+
1453
+ - (BeeDatabase *)having:(NSString *)key value:(id)value
1454
+ {
1455
+ if ( nil == _database )
1456
+ return self;
1457
+
1458
+ [self internalHaving:key value:value type:@"AND"];
1459
+ return self;
1460
+ }
1461
+
1462
+ - (BeeDatabase *)orHaving:(NSString *)key value:(id)value
1463
+ {
1464
+ if ( nil == _database )
1465
+ return self;
1466
+
1467
+ [self internalHaving:key value:value type:@"OR"];
1468
+ return self;
1469
+ }
1470
+
1471
+ - (void)internalHaving:(NSString *)key value:(NSObject *)value type:(NSString *)type
1472
+ {
1473
+ if ( nil == key || nil == value )
1474
+ return;
1475
+
1476
+ key = [[self class] fieldNameForIdentifier:key];
1477
+
1478
+ NSString * sql = nil;
1479
+
1480
+ if ( _having.count )
1481
+ {
1482
+ sql = [NSString stringWithFormat:@"%@ %@ = '%@'", type, key, value];
1483
+ }
1484
+ else
1485
+ {
1486
+ sql = [NSString stringWithFormat:@"%@ = '%@'", key, value];
1487
+ }
1488
+
1489
+ [_having addObject:sql];
1490
+ }
1491
+
1492
+ - (BeeDatabase *)orderAscendBy:(NSString *)by
1493
+ {
1494
+ return [self orderBy:by direction:@"ASC"];
1495
+ }
1496
+
1497
+ - (BeeDatabase *)orderDescendBy:(NSString *)by
1498
+ {
1499
+ return [self orderBy:by direction:@"DESC"];
1500
+ }
1501
+
1502
+ - (BeeDatabase *)orderRandomBy:(NSString *)by
1503
+ {
1504
+ return [self orderBy:by direction:@"RAND()"];
1505
+ }
1506
+
1507
+ - (BeeDatabase *)orderBy:(NSString *)by direction:(NSString *)direction
1508
+ {
1509
+ if ( nil == _database )
1510
+ return self;
1511
+
1512
+ if ( nil == by )
1513
+ return self;
1514
+
1515
+ by = [[self class] fieldNameForIdentifier:by];
1516
+
1517
+ NSString * sql = [NSString stringWithFormat:@"%@ %@", by, direction];
1518
+ [_orderby addObject:sql];
1519
+
1520
+ return self;
1521
+ }
1522
+
1523
+ - (BeeDatabase *)limit:(NSUInteger)limit
1524
+ {
1525
+ if ( nil == _database )
1526
+ return self;
1527
+
1528
+ _limit = limit;
1529
+ return self;
1530
+ }
1531
+
1532
+ - (BeeDatabase *)offset:(NSUInteger)offset
1533
+ {
1534
+ if ( nil == _database )
1535
+ return self;
1536
+
1537
+ _offset = offset;
1538
+ return self;
1539
+ }
1540
+
1541
+ - (BeeDatabase *)classInfo:(id)obj
1542
+ {
1543
+ if ( nil == obj )
1544
+ return self;
1545
+
1546
+ [_classType addObject:obj];
1547
+ return self;
1548
+ }
1549
+
1550
+ - (BeeDatabase *)set:(NSString *)key
1551
+ {
1552
+ return [self set:key value:nil];
1553
+ }
1554
+
1555
+ - (BeeDatabase *)set:(NSString *)key value:(id)value
1556
+ {
1557
+ if ( nil == _database )
1558
+ return self;
1559
+
1560
+ if ( nil == key )
1561
+ return self;
1562
+
1563
+ key = [[self class] fieldNameForIdentifier:key];
1564
+ value = (value ? value : [NSNull null]);
1565
+
1566
+ [_set setObject:value forKey:key];
1567
+ return self;
1568
+ }
1569
+
1570
+ - (void)__internalResetResult
1571
+ {
1572
+ [_resultArray removeAllObjects];
1573
+
1574
+ _resultCount = 0;
1575
+ _lastInsertID = -1;
1576
+ _lastSucceed = NO;
1577
+ }
1578
+
1579
+ - (NSArray *)get
1580
+ {
1581
+ return [self get:nil limit:0 offset:0];
1582
+ }
1583
+
1584
+ - (NSArray *)get:(NSString *)table
1585
+ {
1586
+ return [self get:table limit:0 offset:0];
1587
+ }
1588
+
1589
+ - (NSArray *)get:(NSString *)table limit:(NSUInteger)limit
1590
+ {
1591
+ return [self get:table limit:limit offset:0];
1592
+ }
1593
+
1594
+ - (NSArray *)get:(NSString *)table limit:(NSUInteger)limit offset:(NSUInteger)offset
1595
+ {
1596
+ [self __internalResetResult];
1597
+
1598
+ if ( nil == _database )
1599
+ return nil;
1600
+
1601
+ if ( table )
1602
+ {
1603
+ [self from:table];
1604
+ }
1605
+
1606
+ if ( limit )
1607
+ {
1608
+ [self limit:limit];
1609
+ }
1610
+
1611
+ if ( offset )
1612
+ {
1613
+ [self offset:offset];
1614
+ }
1615
+
1616
+ NSString * sql = [self internalCompileSelect:nil];
1617
+ [self __internalResetSelect];
1618
+
1619
+ FMResultSet * result = [_database executeQuery:sql];
1620
+ if ( result )
1621
+ {
1622
+ while ( [result next] )
1623
+ {
1624
+ [_resultArray addObject:[result resultDictionary]];
1625
+ }
1626
+
1627
+ _resultCount = _resultArray.count;
1628
+
1629
+ _lastQuery = [NSDate timeIntervalSinceReferenceDate];
1630
+ _lastSucceed = YES;
1631
+ }
1632
+
1633
+ return _resultArray;
1634
+ }
1635
+
1636
+ - (NSString *)internalCompileSelect:(NSString *)override
1637
+ {
1638
+ NSMutableString * sql = [NSMutableString string];
1639
+
1640
+ if ( override )
1641
+ {
1642
+ [sql appendString:override];
1643
+ }
1644
+ else
1645
+ {
1646
+ if ( _distinct )
1647
+ {
1648
+ [sql appendString:@"SELECT DISTINCT "];
1649
+ }
1650
+ else
1651
+ {
1652
+ [sql appendString:@"SELECT "];
1653
+ }
1654
+
1655
+ if ( _select.count )
1656
+ {
1657
+ for ( NSInteger i = 0; i < _select.count; ++i )
1658
+ {
1659
+ NSString * select = [_select objectAtIndex:i];
1660
+
1661
+ if ( 0 == i )
1662
+ {
1663
+ [sql appendString:select];
1664
+ }
1665
+ else
1666
+ {
1667
+ [sql appendFormat:@", %@", select];
1668
+ }
1669
+ }
1670
+ }
1671
+ else
1672
+ {
1673
+ [sql appendString:@"*"];
1674
+ }
1675
+ }
1676
+
1677
+ if ( _from.count )
1678
+ {
1679
+ [sql appendString:@" FROM "];
1680
+
1681
+ for ( NSInteger i = 0; i < _from.count; ++i )
1682
+ {
1683
+ NSString * from = [_from objectAtIndex:i];
1684
+
1685
+ if ( 0 == i )
1686
+ {
1687
+ [sql appendString:from];
1688
+ }
1689
+ else
1690
+ {
1691
+ [sql appendFormat:@", %@", from];
1692
+ }
1693
+ }
1694
+ }
1695
+
1696
+ if ( _where.count || _like.count )
1697
+ {
1698
+ [sql appendString:@" WHERE"];
1699
+ }
1700
+
1701
+ if ( _where.count )
1702
+ {
1703
+ for ( NSString * where in _where )
1704
+ {
1705
+ [sql appendFormat:@" %@ ", where];
1706
+ }
1707
+ }
1708
+
1709
+ if ( _like.count )
1710
+ {
1711
+ if ( _where.count )
1712
+ {
1713
+ [sql appendString:@" AND "];
1714
+ }
1715
+
1716
+ for ( NSString * like in _like )
1717
+ {
1718
+ [sql appendFormat:@" %@ ", like];
1719
+ }
1720
+ }
1721
+
1722
+ if ( _groupby.count )
1723
+ {
1724
+ [sql appendString:@" GROUP BY "];
1725
+
1726
+ for ( NSInteger i = 0; i < _groupby.count; ++i )
1727
+ {
1728
+ NSString * by = [_groupby objectAtIndex:i];
1729
+
1730
+ if ( 0 == i )
1731
+ {
1732
+ [sql appendString:by];
1733
+ }
1734
+ else
1735
+ {
1736
+ [sql appendFormat:@", %@", by];
1737
+ }
1738
+ }
1739
+ }
1740
+
1741
+ if ( _having.count )
1742
+ {
1743
+ [sql appendString:@" HAVING "];
1744
+
1745
+ for ( NSString * have in _having )
1746
+ {
1747
+ [sql appendFormat:@" %@ ", have];
1748
+ }
1749
+ }
1750
+
1751
+ if ( _orderby.count )
1752
+ {
1753
+ [sql appendString:@" ORDER BY "];
1754
+
1755
+ for ( NSInteger i = 0; i < _orderby.count; ++i )
1756
+ {
1757
+ NSString * by = [_orderby objectAtIndex:i];
1758
+
1759
+ if ( 0 == i )
1760
+ {
1761
+ [sql appendString:by];
1762
+ }
1763
+ else
1764
+ {
1765
+ [sql appendFormat:@", %@", by];
1766
+ }
1767
+ }
1768
+ }
1769
+
1770
+ if ( _limit )
1771
+ {
1772
+ if ( _offset )
1773
+ {
1774
+ [sql appendFormat:@" LIMIT %u, %u", _offset, _limit];
1775
+ }
1776
+ else
1777
+ {
1778
+ [sql appendFormat:@" LIMIT %u", _limit];
1779
+ }
1780
+ }
1781
+
1782
+ return sql;
1783
+ }
1784
+
1785
+ - (NSUInteger)count
1786
+ {
1787
+ return [self count:nil];
1788
+ }
1789
+
1790
+ - (NSUInteger)count:(NSString *)table
1791
+ {
1792
+ [self __internalResetResult];
1793
+
1794
+ if ( nil == _database )
1795
+ return 0;
1796
+
1797
+ if ( table )
1798
+ {
1799
+ [self from:table];
1800
+ }
1801
+
1802
+ NSString * sql = [self internalCompileSelect:@"SELECT COUNT(*) AS numrows"];
1803
+ [self __internalResetSelect];
1804
+
1805
+ FMResultSet * result = [_database executeQuery:sql];
1806
+ if ( result )
1807
+ {
1808
+ BOOL ret = [result next];
1809
+ if ( NO == ret )
1810
+ return 0;
1811
+
1812
+ _resultCount = (NSUInteger)[result unsignedLongLongIntForColumn:@"numrows"];
1813
+
1814
+ _lastQuery = [NSDate timeIntervalSinceReferenceDate];
1815
+ _lastSucceed = YES;
1816
+ }
1817
+
1818
+ return _resultCount;
1819
+ }
1820
+
1821
+ - (NSInteger)insert
1822
+ {
1823
+ return [self insert:nil];
1824
+ }
1825
+
1826
+ - (NSInteger)insert:(NSString *)table
1827
+ {
1828
+ [self __internalResetResult];
1829
+
1830
+ if ( nil == _database )
1831
+ return -1;
1832
+
1833
+ if ( 0 == _set.count )
1834
+ return -1;
1835
+
1836
+ if ( nil == table )
1837
+ {
1838
+ if ( 0 == _from.count )
1839
+ return -1;
1840
+
1841
+ table = [_from objectAtIndex:0];
1842
+ }
1843
+
1844
+ NSMutableString * sql = [NSMutableString string];
1845
+ NSArray * allKeys = _set.allKeys;
1846
+ NSMutableArray * allValues = [NSMutableArray array];
1847
+
1848
+ NSString * field = nil;
1849
+ NSObject * value = nil;
1850
+
1851
+ [sql appendFormat:@"INSERT INTO %@ (", table];
1852
+
1853
+ for ( NSInteger i = 0; i < allKeys.count; ++i )
1854
+ {
1855
+ NSString * key = [allKeys objectAtIndex:i];
1856
+
1857
+ field = [[self class] fieldNameForIdentifier:key];
1858
+ value = [_set objectForKey:key];
1859
+
1860
+ if ( 0 == i )
1861
+ {
1862
+ [sql appendString:field];
1863
+ }
1864
+ else
1865
+ {
1866
+ [sql appendFormat:@", %@", field];
1867
+ }
1868
+
1869
+ [allValues addObject:value];
1870
+ }
1871
+
1872
+ [sql appendString:@") VALUES ("];
1873
+
1874
+ for ( NSInteger i = 0; i < allValues.count; ++i )
1875
+ {
1876
+ if ( 0 == i )
1877
+ {
1878
+ [sql appendString:@"?"];
1879
+ }
1880
+ else
1881
+ {
1882
+ [sql appendString:@", ?"];
1883
+ }
1884
+ }
1885
+
1886
+ [sql appendString:@")"];
1887
+
1888
+ [self __internalResetWrite];
1889
+
1890
+ BOOL ret = [_database executeUpdate:sql withArgumentsInArray:allValues];
1891
+ if ( ret )
1892
+ {
1893
+ _lastInsertID = (NSInteger)_database.lastInsertRowId;
1894
+
1895
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
1896
+ _lastSucceed = YES;
1897
+ }
1898
+
1899
+ return _lastInsertID;
1900
+ }
1901
+
1902
+ - (BOOL)update
1903
+ {
1904
+ return [self update:nil];
1905
+ }
1906
+
1907
+ - (BOOL)update:(NSString *)table
1908
+ {
1909
+ [self __internalResetResult];
1910
+
1911
+ if ( nil == _database )
1912
+ return NO;
1913
+
1914
+ if ( 0 == _set.count )
1915
+ return NO;
1916
+
1917
+ if ( nil == table )
1918
+ {
1919
+ if ( 0 == _from.count )
1920
+ return NO;
1921
+
1922
+ table = [_from objectAtIndex:0];
1923
+ }
1924
+
1925
+ NSMutableString * sql = [NSMutableString string];
1926
+ NSArray * allKeys = _set.allKeys;
1927
+ NSMutableArray * allValues = [NSMutableArray array];
1928
+
1929
+ NSString * field = nil;
1930
+ NSObject * value = nil;
1931
+
1932
+ [sql appendFormat:@"UPDATE %@ SET ", table];
1933
+
1934
+ for ( NSInteger i = 0; i < allKeys.count; ++i )
1935
+ {
1936
+ NSString * key = [allKeys objectAtIndex:i];
1937
+
1938
+ field = [[self class] fieldNameForIdentifier:key];
1939
+ value = [_set objectForKey:key];
1940
+
1941
+ if ( value )
1942
+ {
1943
+ [allValues addObject:value];
1944
+
1945
+ if ( 0 == i )
1946
+ {
1947
+ [sql appendFormat:@"%@ = ?", field];
1948
+ }
1949
+ else
1950
+ {
1951
+ [sql appendFormat:@", %@ = ?", field];
1952
+ }
1953
+ }
1954
+ }
1955
+
1956
+ if ( _where.count )
1957
+ {
1958
+ [sql appendString:@" WHERE"];
1959
+
1960
+ for ( NSString * where in _where )
1961
+ {
1962
+ [sql appendFormat:@" %@", where];
1963
+ }
1964
+ }
1965
+
1966
+ if ( _orderby.count )
1967
+ {
1968
+ [sql appendString:@" ORDER BY "];
1969
+
1970
+ for ( NSInteger i = 0; i < _orderby.count; ++i )
1971
+ {
1972
+ NSString * by = [_orderby objectAtIndex:i];
1973
+
1974
+ if ( 0 == i )
1975
+ {
1976
+ [sql appendString:by];
1977
+ }
1978
+ else
1979
+ {
1980
+ [sql appendFormat:@", %@", by];
1981
+ }
1982
+ }
1983
+ }
1984
+
1985
+ if ( _limit )
1986
+ {
1987
+ [sql appendFormat:@" LIMIT %u", _limit];
1988
+ }
1989
+
1990
+ [self __internalResetWrite];
1991
+
1992
+ BOOL ret = [_database executeUpdate:sql withArgumentsInArray:allValues];
1993
+ if ( ret )
1994
+ {
1995
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
1996
+ _lastSucceed = YES;
1997
+
1998
+ // TODO: ...
1999
+ }
2000
+ return ret;
2001
+ }
2002
+
2003
+ - (BOOL)empty
2004
+ {
2005
+ return [self empty:nil];
2006
+ }
2007
+
2008
+ - (BOOL)empty:(NSString *)table
2009
+ {
2010
+ [self __internalResetResult];
2011
+
2012
+ if ( nil == _database )
2013
+ return NO;
2014
+
2015
+ if ( nil == table )
2016
+ {
2017
+ if ( 0 == _from.count )
2018
+ return NO;
2019
+
2020
+ table = [_from objectAtIndex:0];
2021
+ }
2022
+
2023
+ NSString * sql = [NSString stringWithFormat:@"DELETE FROM %@", table];
2024
+
2025
+ [self __internalResetWrite];
2026
+
2027
+ BOOL ret = [_database executeUpdate:sql];
2028
+ if ( ret )
2029
+ {
2030
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
2031
+ _lastSucceed = YES;
2032
+
2033
+ // TODO: ...
2034
+ }
2035
+ return ret;
2036
+ }
2037
+
2038
+ - (BOOL)truncate
2039
+ {
2040
+ return [self truncate:nil];
2041
+ }
2042
+
2043
+ - (BOOL)truncate:(NSString *)table
2044
+ {
2045
+ [self __internalResetResult];
2046
+
2047
+ if ( nil == _database )
2048
+ return NO;
2049
+
2050
+ if ( nil == table )
2051
+ {
2052
+ if ( 0 == _from.count )
2053
+ return NO;
2054
+
2055
+ table = [_from objectAtIndex:0];
2056
+ }
2057
+
2058
+ NSString * sql = [NSString stringWithFormat:@"TRUNCATE %@", table];
2059
+
2060
+ [self __internalResetWrite];
2061
+
2062
+ BOOL ret = [_database executeUpdate:sql];
2063
+ if ( ret )
2064
+ {
2065
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
2066
+ _lastSucceed = YES;
2067
+
2068
+ // TODO: ...
2069
+ }
2070
+ return ret;
2071
+ }
2072
+
2073
+ - (BOOL)delete
2074
+ {
2075
+ return [self delete:nil];
2076
+ }
2077
+
2078
+ - (BOOL)delete:(NSString *)table
2079
+ {
2080
+ [self __internalResetResult];
2081
+
2082
+ if ( nil == _database )
2083
+ return NO;
2084
+
2085
+ if ( nil == table )
2086
+ {
2087
+ if ( 0 == _from.count )
2088
+ return NO;
2089
+
2090
+ table = [_from objectAtIndex:0];
2091
+ }
2092
+
2093
+ if ( 0 == _where.count && 0 == _like.count )
2094
+ return NO;
2095
+
2096
+ NSMutableString * sql = [NSMutableString string];
2097
+
2098
+ [sql appendFormat:@"DELETE FROM %@", table];
2099
+
2100
+ if ( _where.count || _like.count )
2101
+ {
2102
+ [sql appendString:@" WHERE "];
2103
+
2104
+ if ( _where.count )
2105
+ {
2106
+ for ( NSString * where in _where )
2107
+ {
2108
+ [sql appendFormat:@" %@ ", where];
2109
+ }
2110
+ }
2111
+
2112
+ if ( _like.count )
2113
+ {
2114
+ if ( _where.count )
2115
+ {
2116
+ [sql appendString:@" AND "];
2117
+ }
2118
+
2119
+ for ( NSString * like in _like )
2120
+ {
2121
+ [sql appendFormat:@" %@ ", like];
2122
+ }
2123
+ }
2124
+ }
2125
+
2126
+ if ( _limit )
2127
+ {
2128
+ [sql appendFormat:@" LIMIT %u", _limit];
2129
+ }
2130
+
2131
+ [self __internalResetWrite];
2132
+
2133
+ BOOL ret = [_database executeUpdate:sql];
2134
+ if ( ret )
2135
+ {
2136
+ _lastUpdate = [NSDate timeIntervalSinceReferenceDate];
2137
+ _lastSucceed = YES;
2138
+
2139
+ // TODO: ...
2140
+ }
2141
+ return ret;
2142
+ }
2143
+
2144
+ + (NSString *)fieldNameForIdentifier:(NSString *)identifier
2145
+ {
2146
+ NSString * name = identifier;
2147
+ name = [name stringByReplacingOccurrencesOfString:@"." withString:@"_"];
2148
+ name = [name stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
2149
+ return name;
2150
+ }
2151
+
2152
+ + (NSString *)tableNameForClass:(Class)clazz
2153
+ {
2154
+ if ( [clazz respondsToSelector:@selector(mapTableName)] )
2155
+ {
2156
+ return [clazz performSelector:@selector(mapTableName)];
2157
+ }
2158
+
2159
+ return [NSString stringWithFormat:@"table_%@", [clazz description]];
2160
+ }
2161
+
2162
+ - (Class)classType
2163
+ {
2164
+ NSString * className = _classType.lastObject;
2165
+ if ( nil == className || 0 == className.length )
2166
+ return NULL;
2167
+
2168
+ Class classType = NSClassFromString( className );
2169
+ if ( nil == classType || NO == [classType conformsToProtocol:@protocol(BeeActiveProtocol)] )
2170
+ return NULL;
2171
+
2172
+ return classType;
2173
+ }
2174
+
2175
+ - (NSArray *)associateObjects
2176
+ {
2177
+ return _associate;
2178
+ }
2179
+
2180
+ - (NSArray *)associateObjectsFor:(Class)clazz
2181
+ {
2182
+ NSMutableArray * array = [NSMutableArray array];
2183
+
2184
+ for ( NSObject * obj in _associate )
2185
+ {
2186
+ if ( [obj isKindOfClass:clazz] )
2187
+ {
2188
+ [array addObject:obj];
2189
+ }
2190
+ }
2191
+
2192
+ return array;
2193
+ }
2194
+
2195
+ - (NSArray *)hasObjects
2196
+ {
2197
+ return _has;
2198
+ }
2199
+
2200
+ - (NSArray *)hasObjectsFor:(Class)clazz
2201
+ {
2202
+ NSMutableArray * array = [NSMutableArray array];
2203
+
2204
+ for ( NSObject * obj in _has )
2205
+ {
2206
+ if ( [obj isKindOfClass:clazz] )
2207
+ {
2208
+ [array addObject:obj];
2209
+ }
2210
+ }
2211
+
2212
+ return array;
2213
+ }
2214
+
2215
+ - (void)classType:(Class)clazz
2216
+ {
2217
+ if ( nil == clazz )
2218
+ return;
2219
+
2220
+ [_classType addObject:[clazz description]];
2221
+
2222
+ [self from:[BeeDatabase tableNameForClass:clazz]];
2223
+ }
2224
+
2225
+ - (void)associate:(NSObject *)obj
2226
+ {
2227
+ if ( nil == obj )
2228
+ return;
2229
+
2230
+ [_associate addObject:obj];
2231
+ }
2232
+
2233
+ - (void)has:(NSObject *)obj
2234
+ {
2235
+ if ( nil == obj )
2236
+ return;
2237
+
2238
+ [_has addObject:obj];
2239
+ }
2240
+
2241
+ - (BeeDatabaseBlockN)TABLE
2242
+ {
2243
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2244
+ {
2245
+ return [self table:(NSString *)first];
2246
+ };
2247
+
2248
+ return [[block copy] autorelease];
2249
+ }
2250
+
2251
+ - (BeeDatabaseBlockN)FIELD
2252
+ {
2253
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2254
+ {
2255
+ va_list args;
2256
+ va_start( args, first );
2257
+
2258
+ NSString * field = (NSString *)first;
2259
+ NSString * type = va_arg( args, NSString * );
2260
+ va_end( args );
2261
+ return [self field:field type:type size:0];
2262
+ };
2263
+
2264
+ return [[block copy] autorelease];
2265
+ }
2266
+
2267
+ - (BeeDatabaseBlockN)FIELD_WITH_SIZE
2268
+ {
2269
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2270
+ {
2271
+ va_list args;
2272
+ va_start( args, first );
2273
+
2274
+ NSString * field = (NSString *)first;
2275
+ NSString * type = va_arg( args, NSString * );
2276
+ NSUInteger size = va_arg( args, NSUInteger );
2277
+
2278
+ va_end( args );
2279
+
2280
+ return [self field:field type:type size:size];
2281
+ };
2282
+
2283
+ return [[block copy] autorelease];
2284
+ }
2285
+
2286
+ - (BeeDatabaseBlock)UNSIGNED
2287
+ {
2288
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2289
+ {
2290
+ return [self unsignedType];
2291
+ };
2292
+
2293
+ return [[block copy] autorelease];
2294
+ }
2295
+
2296
+ - (BeeDatabaseBlock)NOT_NULL
2297
+ {
2298
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2299
+ {
2300
+ return [self notNull];
2301
+ };
2302
+
2303
+ return [[block copy] autorelease];
2304
+ }
2305
+
2306
+ - (BeeDatabaseBlock)PRIMARY_KEY
2307
+ {
2308
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2309
+ {
2310
+ return [self primaryKey];
2311
+ };
2312
+
2313
+ return [[block copy] autorelease];
2314
+ }
2315
+
2316
+ - (BeeDatabaseBlock)AUTO_INREMENT
2317
+ {
2318
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2319
+ {
2320
+ return [self autoIncrement];
2321
+ };
2322
+
2323
+ return [[block copy] autorelease];
2324
+ }
2325
+
2326
+ - (BeeDatabaseBlock)DEFAULT_ZERO
2327
+ {
2328
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2329
+ {
2330
+ return [self defaultZero];
2331
+ };
2332
+
2333
+ return [[block copy] autorelease];
2334
+ }
2335
+
2336
+ - (BeeDatabaseBlock)DEFAULT_NULL
2337
+ {
2338
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2339
+ {
2340
+ return [self defaultNull];
2341
+ };
2342
+
2343
+ return [[block copy] autorelease];
2344
+ }
2345
+
2346
+ - (BeeDatabaseBlockN)DEFAULT
2347
+ {
2348
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2349
+ {
2350
+ return [self defaultValue:first];
2351
+ };
2352
+
2353
+ return [[block copy] autorelease];
2354
+ }
2355
+
2356
+ - (BeeDatabaseBlock)UNIQUE
2357
+ {
2358
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2359
+ {
2360
+ return [self unique];
2361
+ };
2362
+
2363
+ return [[block copy] autorelease];
2364
+ }
2365
+
2366
+ - (BeeDatabaseBlock)CREATE_IF_NOT_EXISTS
2367
+ {
2368
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2369
+ {
2370
+ return [self createTableIfNotExists] ? self : nil;
2371
+ };
2372
+
2373
+ return [[block copy] autorelease];
2374
+ }
2375
+
2376
+ - (BeeDatabaseBlockN)INDEX_ON
2377
+ {
2378
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id field, ... )
2379
+ {
2380
+ va_list args;
2381
+ va_start( args, field );
2382
+
2383
+ NSMutableArray * array = [NSMutableArray array];
2384
+
2385
+ for ( ;; field = nil )
2386
+ {
2387
+ NSObject * name = field ? field : va_arg( args, NSObject * );
2388
+ if ( nil == name || NO == [name isKindOfClass:[NSString class]] )
2389
+ break;
2390
+
2391
+ [array addObject:(NSString *)name];
2392
+ }
2393
+ va_end(args);
2394
+ return [self indexTableOn:array] ? self : nil;
2395
+ };
2396
+
2397
+ return [[block copy] autorelease];
2398
+ }
2399
+
2400
+ - (BeeDatabaseBlockN)SELECT
2401
+ {
2402
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2403
+ {
2404
+ return [self select:(NSString *)first];
2405
+ };
2406
+
2407
+ return [[block copy] autorelease];
2408
+ }
2409
+
2410
+ - (BeeDatabaseBlockN)SELECT_MAX
2411
+ {
2412
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2413
+ {
2414
+ return [self selectMax:(NSString *)first];
2415
+ };
2416
+
2417
+ return [[block copy] autorelease];
2418
+ }
2419
+
2420
+ - (BeeDatabaseBlockN)SELECT_MAX_ALIAS
2421
+ {
2422
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2423
+ {
2424
+ va_list args;
2425
+ va_start( args, first );
2426
+
2427
+ NSString * field = (NSString *)first;
2428
+ NSString * alias = (NSString *)va_arg( args, NSString * );
2429
+ va_end( args );
2430
+ return [self selectMax:field alias:alias];
2431
+ };
2432
+
2433
+ return [[block copy] autorelease];
2434
+ }
2435
+
2436
+ - (BeeDatabaseBlockN)SELECT_MIN
2437
+ {
2438
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2439
+ {
2440
+ return [self selectMin:(NSString *)first];
2441
+ };
2442
+
2443
+ return [[block copy] autorelease];
2444
+ }
2445
+
2446
+ - (BeeDatabaseBlockN)SELECT_MIN_ALIAS
2447
+ {
2448
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2449
+ {
2450
+ va_list args;
2451
+ va_start( args, first );
2452
+
2453
+ NSString * field = (NSString *)first;
2454
+ NSString * alias = (NSString *)va_arg( args, NSString * );
2455
+ va_end(args);
2456
+ return [self selectMin:field alias:alias];
2457
+ };
2458
+
2459
+ return [[block copy] autorelease];
2460
+ }
2461
+
2462
+ - (BeeDatabaseBlockN)SELECT_AVG
2463
+ {
2464
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2465
+ {
2466
+ return [self selectAvg:(NSString *)first];
2467
+ };
2468
+
2469
+ return [[block copy] autorelease];
2470
+ }
2471
+
2472
+ - (BeeDatabaseBlockN)SELECT_AVG_ALIAS
2473
+ {
2474
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2475
+ {
2476
+ va_list args;
2477
+ va_start( args, first );
2478
+
2479
+ NSString * field = (NSString *)first;
2480
+ NSString * alias = (NSString *)va_arg( args, NSString * );
2481
+ va_end( args );
2482
+ return [self selectAvg:field alias:alias];
2483
+ };
2484
+
2485
+ return [[block copy] autorelease];
2486
+ }
2487
+
2488
+ - (BeeDatabaseBlockN)SELECT_SUM
2489
+ {
2490
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2491
+ {
2492
+ return [self selectSum:(NSString *)first];
2493
+ };
2494
+
2495
+ return [[block copy] autorelease];
2496
+ }
2497
+
2498
+ - (BeeDatabaseBlockN)SELECT_SUM_ALIAS
2499
+ {
2500
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2501
+ {
2502
+ va_list args;
2503
+ va_start( args, first );
2504
+
2505
+ NSString * field = (NSString *)first;
2506
+ NSString * alias = (NSString *)va_arg( args, NSString * );
2507
+ va_end( args );
2508
+ return [self selectSum:field alias:alias];
2509
+ };
2510
+
2511
+ return [[block copy] autorelease];
2512
+ }
2513
+
2514
+ - (BeeDatabaseBlock)DISTINCT
2515
+ {
2516
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2517
+ {
2518
+ return [self distinct:YES];
2519
+ };
2520
+
2521
+ return [[block copy] autorelease];
2522
+ }
2523
+
2524
+ - (BeeDatabaseBlockN)FROM
2525
+ {
2526
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2527
+ {
2528
+ return [self from:(NSString *)first];
2529
+ };
2530
+
2531
+ return [[block copy] autorelease];
2532
+ }
2533
+
2534
+ - (BeeDatabaseBlockN)WHERE
2535
+ {
2536
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2537
+ {
2538
+ va_list args;
2539
+ va_start( args, first );
2540
+
2541
+ NSString * key = (NSString *)first;
2542
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2543
+ va_end( args );
2544
+ return [self where:key value:value];
2545
+ };
2546
+
2547
+ return [[block copy] autorelease];
2548
+ }
2549
+
2550
+ - (BeeDatabaseBlockN)OR_WHERE
2551
+ {
2552
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2553
+ {
2554
+ va_list args;
2555
+ va_start( args, first );
2556
+
2557
+ NSString * key = (NSString *)first;
2558
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2559
+ va_end( args );
2560
+ return [self orWhere:key value:value];
2561
+ };
2562
+
2563
+ return [[block copy] autorelease];
2564
+ }
2565
+
2566
+ - (BeeDatabaseBlockN)WHERE_IN
2567
+ {
2568
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id field, ... )
2569
+ {
2570
+ va_list args;
2571
+ va_start( args, field );
2572
+
2573
+ NSString * key = (NSString *)field;
2574
+
2575
+ NSMutableArray * array = [NSMutableArray array];
2576
+ for ( ;; )
2577
+ {
2578
+ NSObject * value = va_arg( args, NSObject * );
2579
+ if ( nil == value )
2580
+ break;
2581
+
2582
+ [array addObject:(NSString *)value];
2583
+ }
2584
+ va_end( args );
2585
+ return [self whereIn:key values:array];
2586
+ };
2587
+
2588
+ return [[block copy] autorelease];
2589
+ }
2590
+
2591
+ - (BeeDatabaseBlockN)OR_WHERE_IN
2592
+ {
2593
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id field, ... )
2594
+ {
2595
+ va_list args;
2596
+ va_start( args, field );
2597
+
2598
+ NSString * key = (NSString *)field;
2599
+
2600
+ NSMutableArray * array = [NSMutableArray array];
2601
+ for ( ;; )
2602
+ {
2603
+ NSObject * value = va_arg( args, NSObject * );
2604
+ if ( nil == value )
2605
+ break;
2606
+
2607
+ [array addObject:(NSString *)value];
2608
+ }
2609
+ va_end( args );
2610
+ return [self orWhereIn:key values:array];
2611
+ };
2612
+
2613
+ return [[block copy] autorelease];
2614
+ }
2615
+
2616
+ - (BeeDatabaseBlockN)WHERE_NOT_IN
2617
+ {
2618
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id field, ... )
2619
+ {
2620
+ va_list args;
2621
+ va_start( args, field );
2622
+
2623
+ NSString * key = (NSString *)field;
2624
+
2625
+ NSMutableArray * array = [NSMutableArray array];
2626
+ for ( ;; )
2627
+ {
2628
+ NSObject * value = va_arg( args, NSObject * );
2629
+ if ( nil == value )
2630
+ break;
2631
+
2632
+ [array addObject:(NSString *)value];
2633
+ }
2634
+ va_end( args );
2635
+ return [self whereNotIn:key values:array];
2636
+ };
2637
+
2638
+ return [[block copy] autorelease];
2639
+ }
2640
+
2641
+ - (BeeDatabaseBlockN)OR_WHERE_NOT_IN
2642
+ {
2643
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id field, ... )
2644
+ {
2645
+ va_list args;
2646
+ va_start( args, field );
2647
+
2648
+ NSString * key = (NSString *)field;
2649
+
2650
+ NSMutableArray * array = [NSMutableArray array];
2651
+ for ( ;; )
2652
+ {
2653
+ NSObject * value = va_arg( args, NSObject * );
2654
+ if ( nil == value )
2655
+ break;
2656
+
2657
+ [array addObject:(NSString *)value];
2658
+ }
2659
+ va_end( args );
2660
+ return [self orWhereNotIn:key values:array];
2661
+ };
2662
+
2663
+ return [[block copy] autorelease];
2664
+ }
2665
+
2666
+ - (BeeDatabaseBlockN)LIKE
2667
+ {
2668
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2669
+ {
2670
+ va_list args;
2671
+ va_start( args, first );
2672
+
2673
+ NSString * key = (NSString *)first;
2674
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2675
+ va_end( args );
2676
+ return [self like:key match:value];
2677
+ };
2678
+
2679
+ return [[block copy] autorelease];
2680
+ }
2681
+
2682
+ - (BeeDatabaseBlockN)NOT_LIKE
2683
+ {
2684
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2685
+ {
2686
+ va_list args;
2687
+ va_start( args, first );
2688
+
2689
+ NSString * key = (NSString *)first;
2690
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2691
+
2692
+ return [self notLike:key match:value];
2693
+ };
2694
+
2695
+ return [[block copy] autorelease];
2696
+ }
2697
+
2698
+ - (BeeDatabaseBlockN)OR_LIKE
2699
+ {
2700
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2701
+ {
2702
+ va_list args;
2703
+ va_start( args, first );
2704
+
2705
+ NSString * key = (NSString *)first;
2706
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2707
+ va_end( args );
2708
+ return [self orLike:key match:value];
2709
+ };
2710
+
2711
+ return [[block copy] autorelease];
2712
+ }
2713
+
2714
+ - (BeeDatabaseBlockN)OR_NOT_LIKE
2715
+ {
2716
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2717
+ {
2718
+ va_list args;
2719
+ va_start( args, first );
2720
+
2721
+ NSString * key = (NSString *)first;
2722
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2723
+ va_end( args );
2724
+ return [self orNotLike:key match:value];
2725
+ };
2726
+
2727
+ return [[block copy] autorelease];
2728
+ }
2729
+
2730
+ - (BeeDatabaseBlockN)GROUP_BY
2731
+ {
2732
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2733
+ {
2734
+ return [self groupBy:(NSString *)first];
2735
+ };
2736
+
2737
+ return [[block copy] autorelease];
2738
+ }
2739
+
2740
+ - (BeeDatabaseBlockN)HAVING
2741
+ {
2742
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2743
+ {
2744
+ va_list args;
2745
+ va_start( args, first );
2746
+
2747
+ NSString * key = (NSString *)first;
2748
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2749
+ va_end( args );
2750
+ return [self having:key value:value];
2751
+ };
2752
+
2753
+ return [[block copy] autorelease];
2754
+ }
2755
+
2756
+ - (BeeDatabaseBlockN)OR_HAVING
2757
+ {
2758
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2759
+ {
2760
+ va_list args;
2761
+ va_start( args, first );
2762
+
2763
+ NSString * key = (NSString *)first;
2764
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2765
+ va_end( args );
2766
+ return [self orHaving:key value:value];
2767
+ };
2768
+
2769
+ return [[block copy] autorelease];
2770
+ }
2771
+
2772
+ - (BeeDatabaseBlockN)ORDER_ASC_BY
2773
+ {
2774
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2775
+ {
2776
+ return [self orderAscendBy:(NSString *)first];
2777
+ };
2778
+
2779
+ return [[block copy] autorelease];
2780
+ }
2781
+
2782
+ - (BeeDatabaseBlockN)ORDER_DESC_BY
2783
+ {
2784
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2785
+ {
2786
+ return [self orderDescendBy:(NSString *)first];
2787
+ };
2788
+
2789
+ return [[block copy] autorelease];
2790
+ }
2791
+
2792
+ - (BeeDatabaseBlockN)ORDER_RAND_BY
2793
+ {
2794
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2795
+ {
2796
+ return [self orderRandomBy:(NSString *)first];
2797
+ };
2798
+
2799
+ return [[block copy] autorelease];
2800
+ }
2801
+
2802
+ - (BeeDatabaseBlockN)ORDER_BY
2803
+ {
2804
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2805
+ {
2806
+ va_list args;
2807
+ va_start( args, first );
2808
+
2809
+ NSString * by = (NSString *)first;
2810
+ NSString * direction = (NSString *)va_arg( args, NSString * );
2811
+ va_end( args );
2812
+ return [self orderBy:by direction:direction];
2813
+ };
2814
+
2815
+ return [[block copy] autorelease];
2816
+ }
2817
+
2818
+ - (BeeDatabaseBlockU)LIMIT
2819
+ {
2820
+ BeeDatabaseBlockU block = ^ BeeDatabase * ( NSUInteger value )
2821
+ {
2822
+ return [self limit:value];
2823
+ };
2824
+
2825
+ return [[block copy] autorelease];
2826
+ }
2827
+
2828
+ - (BeeDatabaseBlockU)OFFSET
2829
+ {
2830
+ BeeDatabaseBlockU block = ^ BeeDatabase * ( NSUInteger value )
2831
+ {
2832
+ return [self offset:value];
2833
+ };
2834
+
2835
+ return [[block copy] autorelease];
2836
+ }
2837
+
2838
+ - (BeeDatabaseBlockN)SET_NULL
2839
+ {
2840
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2841
+ {
2842
+ return [self set:(NSString *)first];
2843
+ };
2844
+
2845
+ return [[block copy] autorelease];
2846
+ }
2847
+
2848
+ - (BeeDatabaseBlockN)SET
2849
+ {
2850
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2851
+ {
2852
+ va_list args;
2853
+ va_start( args, first );
2854
+
2855
+ NSString * key = (NSString *)first;
2856
+ NSObject * value = (NSObject *)va_arg( args, NSObject * );
2857
+ va_end( args );
2858
+ return [self set:key value:value];
2859
+ };
2860
+
2861
+ return [[block copy] autorelease];
2862
+ }
2863
+
2864
+ - (BeeDatabaseBlock)GET
2865
+ {
2866
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2867
+ {
2868
+ [self get];
2869
+ return self;
2870
+ };
2871
+
2872
+ return [[block copy] autorelease];
2873
+ }
2874
+
2875
+ - (BeeDatabaseBlock)COUNT
2876
+ {
2877
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2878
+ {
2879
+ [self count];
2880
+ return self;
2881
+ };
2882
+
2883
+ return [[block copy] autorelease];
2884
+ }
2885
+
2886
+ - (BeeDatabaseBlock)INSERT
2887
+ {
2888
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2889
+ {
2890
+ [self insert];
2891
+ return self;
2892
+ };
2893
+
2894
+ return [[block copy] autorelease];
2895
+ }
2896
+
2897
+ - (BeeDatabaseBlock)UPDATE
2898
+ {
2899
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2900
+ {
2901
+ [self update];
2902
+ return self;
2903
+ };
2904
+
2905
+ return [[block copy] autorelease];
2906
+ }
2907
+
2908
+ - (BeeDatabaseBlock)EMPTY
2909
+ {
2910
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2911
+ {
2912
+ [self empty];
2913
+ return self;
2914
+ };
2915
+
2916
+ return [[block copy] autorelease];
2917
+ }
2918
+
2919
+ - (BeeDatabaseBlock)TRUNCATE
2920
+ {
2921
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2922
+ {
2923
+ [self truncate];
2924
+ return self;
2925
+ };
2926
+
2927
+ return [[block copy] autorelease];
2928
+ }
2929
+
2930
+ - (BeeDatabaseBlock)DELETE
2931
+ {
2932
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2933
+ {
2934
+ [self delete];
2935
+ return self;
2936
+ };
2937
+
2938
+ return [[block copy] autorelease];
2939
+ }
2940
+
2941
+ - (BeeDatabaseBlockN)CLASS_TYPE
2942
+ {
2943
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2944
+ {
2945
+ [self classType:(Class)first];
2946
+ return self;
2947
+ };
2948
+
2949
+ return [[block copy] autorelease];
2950
+ }
2951
+
2952
+ - (BeeDatabaseBlockN)ASSOCIATE
2953
+ {
2954
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2955
+ {
2956
+ [self associate:first];
2957
+ return self;
2958
+ };
2959
+
2960
+ return [[block copy] autorelease];
2961
+ }
2962
+
2963
+ - (BeeDatabaseBlockN)BELONG_TO
2964
+ {
2965
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2966
+ {
2967
+ [self associate:first];
2968
+ return self;
2969
+ };
2970
+
2971
+ return [[block copy] autorelease];
2972
+ }
2973
+
2974
+ - (BeeDatabaseBlockN)HAS
2975
+ {
2976
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
2977
+ {
2978
+ [self has:first];
2979
+ return self;
2980
+ };
2981
+
2982
+ return [[block copy] autorelease];
2983
+ }
2984
+
2985
+ - (BeeDatabaseBlock)BATCH_BEGIN
2986
+ {
2987
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2988
+ {
2989
+ _batch = YES;
2990
+ return self;
2991
+ };
2992
+
2993
+ return [[block copy] autorelease];
2994
+ }
2995
+
2996
+ - (BeeDatabaseBlock)BATCH_END
2997
+ {
2998
+ BeeDatabaseBlock block = ^ BeeDatabase * ( void )
2999
+ {
3000
+ _batch = NO;
3001
+ return self;
3002
+ };
3003
+
3004
+ return [[block copy] autorelease];
3005
+ }
3006
+
3007
+ @end