commit | author | age
|
6e1425
|
1 |
#import <Foundation/Foundation.h> |
H |
2 |
|
|
3 |
#ifndef __has_feature // Optional. |
|
4 |
#define __has_feature(x) 0 // Compatibility with non-clang compilers. |
|
5 |
#endif |
|
6 |
|
|
7 |
#ifndef NS_RETURNS_NOT_RETAINED |
|
8 |
#if __has_feature(attribute_ns_returns_not_retained) |
|
9 |
#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained)) |
|
10 |
#else |
|
11 |
#define NS_RETURNS_NOT_RETAINED |
|
12 |
#endif |
|
13 |
#endif |
|
14 |
|
|
15 |
@class FMDatabase; |
|
16 |
@class FMStatement; |
|
17 |
|
|
18 |
/** Represents the results of executing a query on an `<FMDatabase>`. |
|
19 |
|
|
20 |
### See also |
|
21 |
|
|
22 |
- `<FMDatabase>` |
|
23 |
*/ |
|
24 |
|
|
25 |
@interface FMResultSet : NSObject { |
|
26 |
FMDatabase *_parentDB; |
|
27 |
FMStatement *_statement; |
|
28 |
|
|
29 |
NSString *_query; |
|
30 |
NSMutableDictionary *_columnNameToIndexMap; |
|
31 |
} |
|
32 |
|
|
33 |
///----------------- |
|
34 |
/// @name Properties |
|
35 |
///----------------- |
|
36 |
|
|
37 |
/** Executed query */ |
|
38 |
|
|
39 |
@property (atomic, retain) NSString *query; |
|
40 |
|
|
41 |
/** `NSMutableDictionary` mapping column names to numeric index */ |
|
42 |
|
|
43 |
@property (readonly) NSMutableDictionary *columnNameToIndexMap; |
|
44 |
|
|
45 |
/** `FMStatement` used by result set. */ |
|
46 |
|
|
47 |
@property (atomic, retain) FMStatement *statement; |
|
48 |
|
|
49 |
///------------------------------------ |
|
50 |
/// @name Creating and closing database |
|
51 |
///------------------------------------ |
|
52 |
|
|
53 |
/** Create result set from `<FMStatement>` |
|
54 |
|
|
55 |
@param statement A `<FMStatement>` to be performed |
|
56 |
|
|
57 |
@param aDB A `<FMDatabase>` to be used |
|
58 |
|
|
59 |
@return A `FMResultSet` on success; `nil` on failure |
|
60 |
*/ |
|
61 |
|
|
62 |
+ (instancetype)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB; |
|
63 |
|
|
64 |
/** Close result set */ |
|
65 |
|
|
66 |
- (void)close; |
|
67 |
|
|
68 |
- (void)setParentDB:(FMDatabase *)newDb; |
|
69 |
|
|
70 |
///--------------------------------------- |
|
71 |
/// @name Iterating through the result set |
|
72 |
///--------------------------------------- |
|
73 |
|
|
74 |
/** Retrieve next row for result set. |
|
75 |
|
|
76 |
You must always invoke `next` or `nextWithError` before attempting to access the values returned in a query, even if you're only expecting one. |
|
77 |
|
|
78 |
@return `YES` if row successfully retrieved; `NO` if end of result set reached |
|
79 |
|
|
80 |
@see hasAnotherRow |
|
81 |
*/ |
|
82 |
|
|
83 |
- (BOOL)next; |
|
84 |
|
|
85 |
/** Retrieve next row for result set. |
|
86 |
|
|
87 |
You must always invoke `next` or `nextWithError` before attempting to access the values returned in a query, even if you're only expecting one. |
|
88 |
|
|
89 |
@param outErr A 'NSError' object to receive any error object (if any). |
|
90 |
|
|
91 |
@return 'YES' if row successfully retrieved; 'NO' if end of result set reached |
|
92 |
|
|
93 |
@see hasAnotherRow |
|
94 |
*/ |
|
95 |
|
|
96 |
- (BOOL)nextWithError:(NSError **)outErr; |
|
97 |
|
|
98 |
/** Did the last call to `<next>` succeed in retrieving another row? |
|
99 |
|
|
100 |
@return `YES` if the last call to `<next>` succeeded in retrieving another record; `NO` if not. |
|
101 |
|
|
102 |
@see next |
|
103 |
|
|
104 |
@warning The `hasAnotherRow` method must follow a call to `<next>`. If the previous database interaction was something other than a call to `next`, then this method may return `NO`, whether there is another row of data or not. |
|
105 |
*/ |
|
106 |
|
|
107 |
- (BOOL)hasAnotherRow; |
|
108 |
|
|
109 |
///--------------------------------------------- |
|
110 |
/// @name Retrieving information from result set |
|
111 |
///--------------------------------------------- |
|
112 |
|
|
113 |
/** How many columns in result set |
|
114 |
|
|
115 |
@return Integer value of the number of columns. |
|
116 |
*/ |
|
117 |
|
|
118 |
- (int)columnCount; |
|
119 |
|
|
120 |
/** Column index for column name |
|
121 |
|
|
122 |
@param columnName `NSString` value of the name of the column. |
|
123 |
|
|
124 |
@return Zero-based index for column. |
|
125 |
*/ |
|
126 |
|
|
127 |
- (int)columnIndexForName:(NSString*)columnName; |
|
128 |
|
|
129 |
/** Column name for column index |
|
130 |
|
|
131 |
@param columnIdx Zero-based index for column. |
|
132 |
|
|
133 |
@return columnName `NSString` value of the name of the column. |
|
134 |
*/ |
|
135 |
|
|
136 |
- (NSString*)columnNameForIndex:(int)columnIdx; |
|
137 |
|
|
138 |
/** Result set integer value for column. |
|
139 |
|
|
140 |
@param columnName `NSString` value of the name of the column. |
|
141 |
|
|
142 |
@return `int` value of the result set's column. |
|
143 |
*/ |
|
144 |
|
|
145 |
- (int)intForColumn:(NSString*)columnName; |
|
146 |
|
|
147 |
/** Result set integer value for column. |
|
148 |
|
|
149 |
@param columnIdx Zero-based index for column. |
|
150 |
|
|
151 |
@return `int` value of the result set's column. |
|
152 |
*/ |
|
153 |
|
|
154 |
- (int)intForColumnIndex:(int)columnIdx; |
|
155 |
|
|
156 |
/** Result set `long` value for column. |
|
157 |
|
|
158 |
@param columnName `NSString` value of the name of the column. |
|
159 |
|
|
160 |
@return `long` value of the result set's column. |
|
161 |
*/ |
|
162 |
|
|
163 |
- (long)longForColumn:(NSString*)columnName; |
|
164 |
|
|
165 |
/** Result set long value for column. |
|
166 |
|
|
167 |
@param columnIdx Zero-based index for column. |
|
168 |
|
|
169 |
@return `long` value of the result set's column. |
|
170 |
*/ |
|
171 |
|
|
172 |
- (long)longForColumnIndex:(int)columnIdx; |
|
173 |
|
|
174 |
/** Result set `long long int` value for column. |
|
175 |
|
|
176 |
@param columnName `NSString` value of the name of the column. |
|
177 |
|
|
178 |
@return `long long int` value of the result set's column. |
|
179 |
*/ |
|
180 |
|
|
181 |
- (long long int)longLongIntForColumn:(NSString*)columnName; |
|
182 |
|
|
183 |
/** Result set `long long int` value for column. |
|
184 |
|
|
185 |
@param columnIdx Zero-based index for column. |
|
186 |
|
|
187 |
@return `long long int` value of the result set's column. |
|
188 |
*/ |
|
189 |
|
|
190 |
- (long long int)longLongIntForColumnIndex:(int)columnIdx; |
|
191 |
|
|
192 |
/** Result set `unsigned long long int` value for column. |
|
193 |
|
|
194 |
@param columnName `NSString` value of the name of the column. |
|
195 |
|
|
196 |
@return `unsigned long long int` value of the result set's column. |
|
197 |
*/ |
|
198 |
|
|
199 |
- (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName; |
|
200 |
|
|
201 |
/** Result set `unsigned long long int` value for column. |
|
202 |
|
|
203 |
@param columnIdx Zero-based index for column. |
|
204 |
|
|
205 |
@return `unsigned long long int` value of the result set's column. |
|
206 |
*/ |
|
207 |
|
|
208 |
- (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx; |
|
209 |
|
|
210 |
/** Result set `BOOL` value for column. |
|
211 |
|
|
212 |
@param columnName `NSString` value of the name of the column. |
|
213 |
|
|
214 |
@return `BOOL` value of the result set's column. |
|
215 |
*/ |
|
216 |
|
|
217 |
- (BOOL)boolForColumn:(NSString*)columnName; |
|
218 |
|
|
219 |
/** Result set `BOOL` value for column. |
|
220 |
|
|
221 |
@param columnIdx Zero-based index for column. |
|
222 |
|
|
223 |
@return `BOOL` value of the result set's column. |
|
224 |
*/ |
|
225 |
|
|
226 |
- (BOOL)boolForColumnIndex:(int)columnIdx; |
|
227 |
|
|
228 |
/** Result set `double` value for column. |
|
229 |
|
|
230 |
@param columnName `NSString` value of the name of the column. |
|
231 |
|
|
232 |
@return `double` value of the result set's column. |
|
233 |
|
|
234 |
*/ |
|
235 |
|
|
236 |
- (double)doubleForColumn:(NSString*)columnName; |
|
237 |
|
|
238 |
/** Result set `double` value for column. |
|
239 |
|
|
240 |
@param columnIdx Zero-based index for column. |
|
241 |
|
|
242 |
@return `double` value of the result set's column. |
|
243 |
|
|
244 |
*/ |
|
245 |
|
|
246 |
- (double)doubleForColumnIndex:(int)columnIdx; |
|
247 |
|
|
248 |
/** Result set `NSString` value for column. |
|
249 |
|
|
250 |
@param columnName `NSString` value of the name of the column. |
|
251 |
|
|
252 |
@return `NSString` value of the result set's column. |
|
253 |
|
|
254 |
*/ |
|
255 |
|
|
256 |
- (NSString*)stringForColumn:(NSString*)columnName; |
|
257 |
|
|
258 |
/** Result set `NSString` value for column. |
|
259 |
|
|
260 |
@param columnIdx Zero-based index for column. |
|
261 |
|
|
262 |
@return `NSString` value of the result set's column. |
|
263 |
*/ |
|
264 |
|
|
265 |
- (NSString*)stringForColumnIndex:(int)columnIdx; |
|
266 |
|
|
267 |
/** Result set `NSDate` value for column. |
|
268 |
|
|
269 |
@param columnName `NSString` value of the name of the column. |
|
270 |
|
|
271 |
@return `NSDate` value of the result set's column. |
|
272 |
*/ |
|
273 |
|
|
274 |
- (NSDate*)dateForColumn:(NSString*)columnName; |
|
275 |
|
|
276 |
/** Result set `NSDate` value for column. |
|
277 |
|
|
278 |
@param columnIdx Zero-based index for column. |
|
279 |
|
|
280 |
@return `NSDate` value of the result set's column. |
|
281 |
|
|
282 |
*/ |
|
283 |
|
|
284 |
- (NSDate*)dateForColumnIndex:(int)columnIdx; |
|
285 |
|
|
286 |
/** Result set `NSData` value for column. |
|
287 |
|
|
288 |
This is useful when storing binary data in table (such as image or the like). |
|
289 |
|
|
290 |
@param columnName `NSString` value of the name of the column. |
|
291 |
|
|
292 |
@return `NSData` value of the result set's column. |
|
293 |
|
|
294 |
*/ |
|
295 |
|
|
296 |
- (NSData*)dataForColumn:(NSString*)columnName; |
|
297 |
|
|
298 |
/** Result set `NSData` value for column. |
|
299 |
|
|
300 |
@param columnIdx Zero-based index for column. |
|
301 |
|
|
302 |
@return `NSData` value of the result set's column. |
|
303 |
*/ |
|
304 |
|
|
305 |
- (NSData*)dataForColumnIndex:(int)columnIdx; |
|
306 |
|
|
307 |
/** Result set `(const unsigned char *)` value for column. |
|
308 |
|
|
309 |
@param columnName `NSString` value of the name of the column. |
|
310 |
|
|
311 |
@return `(const unsigned char *)` value of the result set's column. |
|
312 |
*/ |
|
313 |
|
|
314 |
- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName; |
|
315 |
|
|
316 |
/** Result set `(const unsigned char *)` value for column. |
|
317 |
|
|
318 |
@param columnIdx Zero-based index for column. |
|
319 |
|
|
320 |
@return `(const unsigned char *)` value of the result set's column. |
|
321 |
*/ |
|
322 |
|
|
323 |
- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx; |
|
324 |
|
|
325 |
/** Result set object for column. |
|
326 |
|
|
327 |
@param columnName `NSString` value of the name of the column. |
|
328 |
|
|
329 |
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object. |
|
330 |
|
|
331 |
@see objectForKeyedSubscript: |
|
332 |
*/ |
|
333 |
|
|
334 |
- (id)objectForColumnName:(NSString*)columnName; |
|
335 |
|
|
336 |
/** Result set object for column. |
|
337 |
|
|
338 |
@param columnIdx Zero-based index for column. |
|
339 |
|
|
340 |
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object. |
|
341 |
|
|
342 |
@see objectAtIndexedSubscript: |
|
343 |
*/ |
|
344 |
|
|
345 |
- (id)objectForColumnIndex:(int)columnIdx; |
|
346 |
|
|
347 |
/** Result set object for column. |
|
348 |
|
|
349 |
This method allows the use of the "boxed" syntax supported in Modern Objective-C. For example, by defining this method, the following syntax is now supported: |
|
350 |
|
|
351 |
id result = rs[@"employee_name"]; |
|
352 |
|
|
353 |
This simplified syntax is equivalent to calling: |
|
354 |
|
|
355 |
id result = [rs objectForKeyedSubscript:@"employee_name"]; |
|
356 |
|
|
357 |
which is, it turns out, equivalent to calling: |
|
358 |
|
|
359 |
id result = [rs objectForColumnName:@"employee_name"]; |
|
360 |
|
|
361 |
@param columnName `NSString` value of the name of the column. |
|
362 |
|
|
363 |
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object. |
|
364 |
*/ |
|
365 |
|
|
366 |
- (id)objectForKeyedSubscript:(NSString *)columnName; |
|
367 |
|
|
368 |
/** Result set object for column. |
|
369 |
|
|
370 |
This method allows the use of the "boxed" syntax supported in Modern Objective-C. For example, by defining this method, the following syntax is now supported: |
|
371 |
|
|
372 |
id result = rs[0]; |
|
373 |
|
|
374 |
This simplified syntax is equivalent to calling: |
|
375 |
|
|
376 |
id result = [rs objectForKeyedSubscript:0]; |
|
377 |
|
|
378 |
which is, it turns out, equivalent to calling: |
|
379 |
|
|
380 |
id result = [rs objectForColumnName:0]; |
|
381 |
|
|
382 |
@param columnIdx Zero-based index for column. |
|
383 |
|
|
384 |
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object. |
|
385 |
*/ |
|
386 |
|
|
387 |
- (id)objectAtIndexedSubscript:(int)columnIdx; |
|
388 |
|
|
389 |
/** Result set `NSData` value for column. |
|
390 |
|
|
391 |
@param columnName `NSString` value of the name of the column. |
|
392 |
|
|
393 |
@return `NSData` value of the result set's column. |
|
394 |
|
|
395 |
@warning If you are going to use this data after you iterate over the next row, or after you close the |
|
396 |
result set, make sure to make a copy of the data first (or just use `<dataForColumn:>`/`<dataForColumnIndex:>`) |
|
397 |
If you don't, you're going to be in a world of hurt when you try and use the data. |
|
398 |
|
|
399 |
*/ |
|
400 |
|
|
401 |
- (NSData*)dataNoCopyForColumn:(NSString*)columnName NS_RETURNS_NOT_RETAINED; |
|
402 |
|
|
403 |
/** Result set `NSData` value for column. |
|
404 |
|
|
405 |
@param columnIdx Zero-based index for column. |
|
406 |
|
|
407 |
@return `NSData` value of the result set's column. |
|
408 |
|
|
409 |
@warning If you are going to use this data after you iterate over the next row, or after you close the |
|
410 |
result set, make sure to make a copy of the data first (or just use `<dataForColumn:>`/`<dataForColumnIndex:>`) |
|
411 |
If you don't, you're going to be in a world of hurt when you try and use the data. |
|
412 |
|
|
413 |
*/ |
|
414 |
|
|
415 |
- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED; |
|
416 |
|
|
417 |
/** Is the column `NULL`? |
|
418 |
|
|
419 |
@param columnIdx Zero-based index for column. |
|
420 |
|
|
421 |
@return `YES` if column is `NULL`; `NO` if not `NULL`. |
|
422 |
*/ |
|
423 |
|
|
424 |
- (BOOL)columnIndexIsNull:(int)columnIdx; |
|
425 |
|
|
426 |
/** Is the column `NULL`? |
|
427 |
|
|
428 |
@param columnName `NSString` value of the name of the column. |
|
429 |
|
|
430 |
@return `YES` if column is `NULL`; `NO` if not `NULL`. |
|
431 |
*/ |
|
432 |
|
|
433 |
- (BOOL)columnIsNull:(NSString*)columnName; |
|
434 |
|
|
435 |
|
|
436 |
/** Returns a dictionary of the row results mapped to case sensitive keys of the column names. |
|
437 |
|
|
438 |
@returns `NSDictionary` of the row results. |
|
439 |
|
|
440 |
@warning The keys to the dictionary are case sensitive of the column names. |
|
441 |
*/ |
|
442 |
|
|
443 |
- (NSDictionary*)resultDictionary; |
|
444 |
|
|
445 |
/** Returns a dictionary of the row results |
|
446 |
|
|
447 |
@see resultDictionary |
|
448 |
|
|
449 |
@warning **Deprecated**: Please use `<resultDictionary>` instead. Also, beware that `<resultDictionary>` is case sensitive! |
|
450 |
*/ |
|
451 |
|
|
452 |
- (NSDictionary*)resultDict __attribute__ ((deprecated)); |
|
453 |
|
|
454 |
///----------------------------- |
|
455 |
/// @name Key value coding magic |
|
456 |
///----------------------------- |
|
457 |
|
|
458 |
/** Performs `setValue` to yield support for key value observing. |
|
459 |
|
|
460 |
@param object The object for which the values will be set. This is the key-value-coding compliant object that you might, for example, observe. |
|
461 |
|
|
462 |
*/ |
|
463 |
|
|
464 |
- (void)kvcMagic:(id)object; |
|
465 |
|
|
466 |
|
|
467 |
@end |
|
468 |
|