Guest User

Untitled

a guest
Dec 16th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.81 KB | None | 0 0
  1. @import Foundation;
  2.  
  3. NSString * const SQLCONNECTION_VERSION_NUM;
  4.  
  5. #import "SQLConnection.h"
  6.  
  7. #import "SQLViewController.h"
  8. #import "SQLTableViewController.h"
  9. #import "SQLCollectionViewController.h"
  10. #import "SQLSettings.h"
  11.  
  12. BOOL isNull(id obj);
  13. id nullReplace(id obj, id replacement);
  14.  
  15. #import "SQLConnectionDelegate.h"
  16. #import "SQLSettings.h"
  17.  
  18. @interface SQLConnection : NSObject
  19.  
  20. #pragma mark Properties
  21. /**
  22. * Indicates whether or not the database is currently connected
  23. */
  24. @property (nonatomic,assign,readonly) BOOL connected;
  25.  
  26. /**
  27. * The database server to use. Supports server, server:port, or serverinstance (be sure to escape the backslash)
  28. */
  29. @property (nonatomic,strong) NSString *server;
  30.  
  31. /**
  32. * The database username
  33. */
  34. @property (nonatomic,strong) NSString *username;
  35.  
  36. /**
  37. * The database password
  38. */
  39. @property (nonatomic,strong) NSString *password;
  40.  
  41. /**
  42. * The database name to use
  43. */
  44. @property (nonatomic,strong) NSString *database;
  45.  
  46. /**
  47. * Delegate to handle callbacks
  48. */
  49. @property (nonatomic,weak) id<SQLConnectionDelegate> delegate;
  50.  
  51. /**
  52. * The queue to execute database operations on. A default queue name is used, but can be overridden.
  53. */
  54. @property (nonatomic,strong) NSOperationQueue *workerQueue;
  55.  
  56. /**
  57. * The queue for delegate callbacks. Uses current queue by default, but can be overridden.
  58. */
  59. @property (nonatomic,strong) NSOperationQueue *callbackQueue;
  60.  
  61. /**
  62. * The character set to use for converting the UCS-2 server results. Default is UTF-8. Can be overridden to any charset supported by the iconv library.
  63. * To list all supported iconv character sets, open a Terminal window and enter:
  64. * $ iconv --list
  65. */
  66. @property (nonatomic,strong) NSString *charset;
  67.  
  68. /**
  69. * Login timeout, in seconds. Default is 5. Override before calling connect
  70. */
  71. @property (nonatomic,assign) int loginTimeout;
  72.  
  73. /**
  74. * Query timeout, in seconds. Default is 5. Override before calling executeQuery:
  75. */
  76. @property (nonatomic,assign) int executeTimeout;
  77.  
  78. /*
  79. * Tag for the object. Not used internally at all. Only used for the user to distinguish which connection is calling the delegate method if wanted.
  80. */
  81. @property (nonatomic,assign) NSInteger tag;
  82.  
  83. #pragma mark Initializer methods
  84.  
  85. - (id)init __attribute__((unavailable("Must initialize with a delegate")));
  86.  
  87. /**
  88. * Returns a SQLConnection instance using the defaults defined in the SQLSettings defaultSettings object
  89. *
  90. * @param delegate Required. An object conforming to the SQLConnectionDelegate protocol for receiving callback messages.
  91. *
  92. * @return SQLConnection object using the SQLSettings defaultSettings
  93. */
  94. + (instancetype)sqlConnectionWithDelegate:(NSObject<SQLConnectionDelegate>*)delegate;
  95.  
  96. /**
  97. * Returns a SQLConnection instance
  98. *
  99. * @param server Required. The database server to use. Supports server, server:port, or serverinstance (be sure to escape the backslash)
  100. * @param username Required. The database username.
  101. * @param password Required. The database password.
  102. * @param database Required. The database name.
  103. * @param delegate Required. An object conforming to the SQLConnectionDelegate protocol for receiving callback messages.
  104. *
  105. * @return SQLConnection object
  106. */
  107. - (id)initWithServer:(NSString*)server
  108. username:(NSString*)username
  109. password:(NSString*)password
  110. database:(NSString*)database
  111. delegate:(id<SQLConnectionDelegate>)delegate;
  112.  
  113. /**
  114. * Returns a SQLConnection instance
  115. *
  116. * @param server Required. The database server to use. Supports server, server:port, or serverinstance (be sure to escape the backslash)
  117. * @param username Required. The database username.
  118. * @param password Required. The database password.
  119. * @param database Required. The database name.
  120. * @param delegate Required. An object conforming to the SQLConnectionDelegate protocol for receiving callback messages.
  121. *
  122. * @return SQLConnection object
  123. */
  124. + (instancetype)sqlConnectionWithServer:(NSString*)server
  125. username:(NSString*)username
  126. password:(NSString*)password
  127. database:(NSString*)database
  128. delegate:(NSObject<SQLConnectionDelegate>*)delegate;
  129.  
  130. /**
  131. * Returns a SQLConnection instance
  132. *
  133. * @param settings Required. The settings to use for connecting to the database.
  134. * @param delegate Required. An object conforming to the SQLConnectionDelegate protocol for receiving callback messages.
  135. *
  136. * @return SQLConnection object
  137. */
  138. - (id)initWithSettings:(SQLSettings*)settings delegate:(NSObject<SQLConnectionDelegate>*)delegate;
  139.  
  140. /**
  141. * Returns a SQLConnection instance
  142. *
  143. * @param settings Required. The settings to use for connecting to the database.
  144. * @param delegate Required. An object conforming to the SQLConnectionDelegate protocol for receiving callback messages.
  145. *
  146. * @return SQLConnection object
  147. */
  148. + (instancetype)sqlConnectionWithSettings:(SQLSettings*)settings delegate:(NSObject<SQLConnectionDelegate>*)delegate;
  149.  
  150. #pragma mark Working methods
  151.  
  152. /**
  153. * Connects to the SQL database using the current connection settings.
  154. */
  155. - (void)connect;
  156.  
  157. /*
  158. * An optional alternative to connect. This method frees the connection info immediately after the connection attempt so it is not kept in memory.
  159. *
  160. * @param server Required. The database server to use. Supports server, server:port, or serverinstance (be sure to escape the backslash)
  161. * @param username Required. The database username.
  162. * @param password Required. The database password.
  163. * @param database Required. The database name.
  164. * @param charset Optional. The charset to use. Will default to preset charset if nil is passed.
  165. */
  166. - (void)connectToServer:(NSString *)server withUsername:(NSString *)username password:(NSString *)password usingDatabase:(NSString *)database charset:(NSString *)charset;
  167.  
  168. /**
  169. * Executes the provided SQL statement. Results are handled via the delegate methods.
  170. */
  171. - (void)execute:(NSString*)statement;
  172.  
  173. /**
  174. * Disconnects from database server
  175. */
  176. - (void)disconnect;
  177.  
  178. @end
  179.  
  180. @class SQLConnection;
  181.  
  182. @protocol SQLConnection <NSObject>
  183.  
  184. /*
  185. * Required delegate method to handle successful connection completion
  186. *
  187. * @param connection The SQLConnection instance which completed connection successfully
  188. */
  189. @required - (void)sqlConnectionDidSucceed:(SQLConnection *)connection;
  190.  
  191. /*
  192. * Required delegate method to handle connection failure
  193. *
  194. * @param connection The SQLConnection instance which failed to connect
  195. * @param error An error describing the connection problem
  196. */
  197. @required - (void)sqlConnection:(SQLConnection *)connection connectionDidFailWithError:(NSError *)error;
  198.  
  199. @end
  200.  
  201. @protocol SQLQuery <NSObject>
  202.  
  203. /*
  204. * Required delegate method to handle successful execution of a SQL command on the server
  205. *
  206. * @param connection The SQLConnection instance which handled the execution
  207. * @param results The results, if any, returned from the database
  208. */
  209. @required - (void)sqlConnection:(SQLConnection *)connection executeDidCompleteWithResults:(NSArray *)results;
  210.  
  211. /*
  212. * Required delegate method to handle unsuccessful execution of a SQL command on the server
  213. *
  214. * @param connection The SQLConnection instance which handled the execution
  215. * @param error An error describing the execution problem
  216. */
  217. @required - (void)sqlConnection:(SQLConnection *)connection executeDidFailWithError:(NSError *)error;
  218.  
  219. @end
  220.  
  221. @protocol SQLConnectionDelegate <SQLConnection, SQLQuery>
  222.  
  223. /*
  224. * Optional delegate method to handle message notifications from the server
  225. *
  226. * @param connection The SQLConnection instance which received the message
  227. * @param message The message from the server
  228. */
  229. @optional - (void)sqlConnection:(SQLConnection *)connection didReceiveServerMessage:(NSString *)message;
  230.  
  231. /*
  232. * Optional delegate method to handle error notifications from the server
  233. *
  234. * @param connection The SQLConnection instance which received the message
  235. * @param error The error message from the server
  236. * @param code The error code from the server
  237. * @param severity The error severity from the server
  238. */
  239. @optional - (void)sqlConnection:(SQLConnection *)connection didReceiveServerError:(NSString*)error code:(int)code severity:(int)severity;
  240.  
  241. @end
  242.  
  243. @import Foundation.NSObject;
  244. @import Foundation.NSString;
  245.  
  246. @interface SQLSettings : NSObject
  247.  
  248. /*
  249. * Returns a SQLSettings instance
  250. *
  251. * @return SLQSettings object
  252. */
  253. + (instancetype)settings;
  254.  
  255. /*
  256. * Returns a shared SQLSettings instance. This object can be used to specify default settings that SQLConnection objects will use when initialized without settings parameters.
  257. *
  258. * @return Default settings object
  259. */
  260. + (instancetype)defaultSettings;
  261.  
  262. /**
  263. * The database server to use. Supports server, server:port, or serverinstance (be sure to escape the backslash)
  264. */
  265. @property (nonatomic,strong) NSString *server;
  266.  
  267. /**
  268. * The database username
  269. */
  270. @property (nonatomic,strong) NSString *username;
  271.  
  272. /**
  273. * The database password
  274. */
  275. @property (nonatomic,strong) NSString *password;
  276.  
  277. /**
  278. * The database name to use
  279. */
  280. @property (nonatomic,strong) NSString *database;
  281.  
  282. @end
  283.  
  284. @interface SQLViewController : UIViewController
  285.  
  286. @property (nonatomic,assign) BOOL sqlDebugLogging;
  287.  
  288. - (void)viewDidLoad NS_REQUIRES_SUPER;
  289. - (void)viewWillAppear:(BOOL)animated NS_REQUIRES_SUPER;
  290. - (void)viewDidAppear:(BOOL)animated NS_REQUIRES_SUPER;
  291. - (void)viewWillDisappear:(BOOL)animated NS_REQUIRES_SUPER;
  292. - (void)viewDidDisappear:(BOOL)animated NS_REQUIRES_SUPER;
  293. - (void)viewWillLayoutSubviews NS_REQUIRES_SUPER;
  294. - (void)viewDidLayoutSubviews NS_REQUIRES_SUPER;
  295.  
  296. @end
  297.  
  298. @interface SQLTableViewController : UITableViewController
  299.  
  300. @property (nonatomic,assign) BOOL sqlDebugLogging;
  301.  
  302. - (void)viewDidLoad NS_REQUIRES_SUPER;
  303. - (void)viewWillAppear:(BOOL)animated NS_REQUIRES_SUPER;
  304. - (void)viewDidAppear:(BOOL)animated NS_REQUIRES_SUPER;
  305. - (void)viewWillDisappear:(BOOL)animated NS_REQUIRES_SUPER;
  306. - (void)viewDidDisappear:(BOOL)animated NS_REQUIRES_SUPER;
  307. - (void)viewWillLayoutSubviews NS_REQUIRES_SUPER;
  308. - (void)viewDidLayoutSubviews NS_REQUIRES_SUPER;
  309.  
  310. @end
  311.  
  312. @interface SQLCollectionViewController : UICollectionViewController
  313.  
  314. @property (nonatomic,assign) BOOL sqlDebugLogging;
  315.  
  316. - (void)viewDidLoad NS_REQUIRES_SUPER;
  317. - (void)viewWillAppear:(BOOL)animated NS_REQUIRES_SUPER;
  318. - (void)viewDidAppear:(BOOL)animated NS_REQUIRES_SUPER;
  319. - (void)viewWillDisappear:(BOOL)animated NS_REQUIRES_SUPER;
  320. - (void)viewDidDisappear:(BOOL)animated NS_REQUIRES_SUPER;
  321. - (void)viewWillLayoutSubviews NS_REQUIRES_SUPER;
  322. - (void)viewDidLayoutSubviews NS_REQUIRES_SUPER;
  323.  
  324. @end
  325.  
  326. @property (nonatomic, strong, readonly) NSString *server;
  327.  
  328. /* <---- need two * right there
  329. *
  330. * Required delegate method to handle successful execution of a SQL command on the server
  331. *
  332. * @param connection The SQLConnection instance which handled the execution
  333. * @param results The results, if any, returned from the database
  334. */
Add Comment
Please, Sign In to add comment