commit | author | age
|
6e1425
|
1 |
// |
H |
2 |
// FMDatabaseAdditions.h |
|
3 |
// fmdb |
|
4 |
// |
|
5 |
// Created by August Mueller on 10/30/05. |
|
6 |
// Copyright 2005 Flying Meat Inc.. All rights reserved. |
|
7 |
// |
|
8 |
|
|
9 |
#import <Foundation/Foundation.h> |
|
10 |
#import "FMDatabase.h" |
|
11 |
|
|
12 |
|
|
13 |
/** Category of additions for `<FMDatabase>` class. |
|
14 |
|
|
15 |
### See also |
|
16 |
|
|
17 |
- `<FMDatabase>` |
|
18 |
*/ |
|
19 |
|
|
20 |
@interface FMDatabase (FMDatabaseAdditions) |
|
21 |
|
|
22 |
///---------------------------------------- |
|
23 |
/// @name Return results of SQL to variable |
|
24 |
///---------------------------------------- |
|
25 |
|
|
26 |
/** Return `int` value for query |
|
27 |
|
|
28 |
@param query The SQL query to be performed. |
|
29 |
@param ... A list of parameters that will be bound to the `?` placeholders in the SQL query. |
|
30 |
|
|
31 |
@return `int` value. |
|
32 |
|
|
33 |
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project. |
|
34 |
*/ |
|
35 |
|
|
36 |
- (int)intForQuery:(NSString*)query, ...; |
|
37 |
|
|
38 |
/** Return `long` value for query |
|
39 |
|
|
40 |
@param query The SQL query to be performed. |
|
41 |
@param ... A list of parameters that will be bound to the `?` placeholders in the SQL query. |
|
42 |
|
|
43 |
@return `long` value. |
|
44 |
|
|
45 |
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project. |
|
46 |
*/ |
|
47 |
|
|
48 |
- (long)longForQuery:(NSString*)query, ...; |
|
49 |
|
|
50 |
/** Return `BOOL` value for query |
|
51 |
|
|
52 |
@param query The SQL query to be performed. |
|
53 |
@param ... A list of parameters that will be bound to the `?` placeholders in the SQL query. |
|
54 |
|
|
55 |
@return `BOOL` value. |
|
56 |
|
|
57 |
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project. |
|
58 |
*/ |
|
59 |
|
|
60 |
- (BOOL)boolForQuery:(NSString*)query, ...; |
|
61 |
|
|
62 |
/** Return `double` value for query |
|
63 |
|
|
64 |
@param query The SQL query to be performed. |
|
65 |
@param ... A list of parameters that will be bound to the `?` placeholders in the SQL query. |
|
66 |
|
|
67 |
@return `double` value. |
|
68 |
|
|
69 |
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project. |
|
70 |
*/ |
|
71 |
|
|
72 |
- (double)doubleForQuery:(NSString*)query, ...; |
|
73 |
|
|
74 |
/** Return `NSString` value for query |
|
75 |
|
|
76 |
@param query The SQL query to be performed. |
|
77 |
@param ... A list of parameters that will be bound to the `?` placeholders in the SQL query. |
|
78 |
|
|
79 |
@return `NSString` value. |
|
80 |
|
|
81 |
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project. |
|
82 |
*/ |
|
83 |
|
|
84 |
- (NSString*)stringForQuery:(NSString*)query, ...; |
|
85 |
|
|
86 |
/** Return `NSData` value for query |
|
87 |
|
|
88 |
@param query The SQL query to be performed. |
|
89 |
@param ... A list of parameters that will be bound to the `?` placeholders in the SQL query. |
|
90 |
|
|
91 |
@return `NSData` value. |
|
92 |
|
|
93 |
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project. |
|
94 |
*/ |
|
95 |
|
|
96 |
- (NSData*)dataForQuery:(NSString*)query, ...; |
|
97 |
|
|
98 |
/** Return `NSDate` value for query |
|
99 |
|
|
100 |
@param query The SQL query to be performed. |
|
101 |
@param ... A list of parameters that will be bound to the `?` placeholders in the SQL query. |
|
102 |
|
|
103 |
@return `NSDate` value. |
|
104 |
|
|
105 |
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project. |
|
106 |
*/ |
|
107 |
|
|
108 |
- (NSDate*)dateForQuery:(NSString*)query, ...; |
|
109 |
|
|
110 |
|
|
111 |
// Notice that there's no dataNoCopyForQuery:. |
|
112 |
// That would be a bad idea, because we close out the result set, and then what |
|
113 |
// happens to the data that we just didn't copy? Who knows, not I. |
|
114 |
|
|
115 |
|
|
116 |
///-------------------------------- |
|
117 |
/// @name Schema related operations |
|
118 |
///-------------------------------- |
|
119 |
|
|
120 |
/** Does table exist in database? |
|
121 |
|
|
122 |
@param tableName The name of the table being looked for. |
|
123 |
|
|
124 |
@return `YES` if table found; `NO` if not found. |
|
125 |
*/ |
|
126 |
|
|
127 |
- (BOOL)tableExists:(NSString*)tableName; |
|
128 |
|
|
129 |
/** The schema of the database. |
|
130 |
|
|
131 |
This will be the schema for the entire database. For each entity, each row of the result set will include the following fields: |
|
132 |
|
|
133 |
- `type` - The type of entity (e.g. table, index, view, or trigger) |
|
134 |
- `name` - The name of the object |
|
135 |
- `tbl_name` - The name of the table to which the object references |
|
136 |
- `rootpage` - The page number of the root b-tree page for tables and indices |
|
137 |
- `sql` - The SQL that created the entity |
|
138 |
|
|
139 |
@return `FMResultSet` of schema; `nil` on error. |
|
140 |
|
|
141 |
@see [SQLite File Format](http://www.sqlite.org/fileformat.html) |
|
142 |
*/ |
|
143 |
|
|
144 |
- (FMResultSet*)getSchema; |
|
145 |
|
|
146 |
/** The schema of the database. |
|
147 |
|
|
148 |
This will be the schema for a particular table as report by SQLite `PRAGMA`, for example: |
|
149 |
|
|
150 |
PRAGMA table_info('employees') |
|
151 |
|
|
152 |
This will report: |
|
153 |
|
|
154 |
- `cid` - The column ID number |
|
155 |
- `name` - The name of the column |
|
156 |
- `type` - The data type specified for the column |
|
157 |
- `notnull` - whether the field is defined as NOT NULL (i.e. values required) |
|
158 |
- `dflt_value` - The default value for the column |
|
159 |
- `pk` - Whether the field is part of the primary key of the table |
|
160 |
|
|
161 |
@param tableName The name of the table for whom the schema will be returned. |
|
162 |
|
|
163 |
@return `FMResultSet` of schema; `nil` on error. |
|
164 |
|
|
165 |
@see [table_info](http://www.sqlite.org/pragma.html#pragma_table_info) |
|
166 |
*/ |
|
167 |
|
|
168 |
- (FMResultSet*)getTableSchema:(NSString*)tableName; |
|
169 |
|
|
170 |
/** Test to see if particular column exists for particular table in database |
|
171 |
|
|
172 |
@param columnName The name of the column. |
|
173 |
|
|
174 |
@param tableName The name of the table. |
|
175 |
|
|
176 |
@return `YES` if column exists in table in question; `NO` otherwise. |
|
177 |
*/ |
|
178 |
|
|
179 |
- (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName; |
|
180 |
|
|
181 |
/** Test to see if particular column exists for particular table in database |
|
182 |
|
|
183 |
@param columnName The name of the column. |
|
184 |
|
|
185 |
@param tableName The name of the table. |
|
186 |
|
|
187 |
@return `YES` if column exists in table in question; `NO` otherwise. |
|
188 |
|
|
189 |
@see columnExists:inTableWithName: |
|
190 |
|
|
191 |
@warning Deprecated - use `<columnExists:inTableWithName:>` instead. |
|
192 |
*/ |
|
193 |
|
|
194 |
- (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __attribute__ ((deprecated)); |
|
195 |
|
|
196 |
|
|
197 |
/** Validate SQL statement |
|
198 |
|
|
199 |
This validates SQL statement by performing `sqlite3_prepare_v2`, but not returning the results, but instead immediately calling `sqlite3_finalize`. |
|
200 |
|
|
201 |
@param sql The SQL statement being validated. |
|
202 |
|
|
203 |
@param error This is a pointer to a `NSError` object that will receive the autoreleased `NSError` object if there was any error. If this is `nil`, no `NSError` result will be returned. |
|
204 |
|
|
205 |
@return `YES` if validation succeeded without incident; `NO` otherwise. |
|
206 |
|
|
207 |
*/ |
|
208 |
|
|
209 |
- (BOOL)validateSQL:(NSString*)sql error:(NSError**)error; |
|
210 |
|
|
211 |
|
|
212 |
///----------------------------------- |
|
213 |
/// @name Application identifier tasks |
|
214 |
///----------------------------------- |
|
215 |
|
|
216 |
/** Retrieve application ID |
|
217 |
|
|
218 |
@return The `uint32_t` numeric value of the application ID. |
|
219 |
|
|
220 |
@see setApplicationID: |
|
221 |
*/ |
|
222 |
|
|
223 |
- (uint32_t)applicationID; |
|
224 |
|
|
225 |
/** Set the application ID |
|
226 |
|
|
227 |
@param appID The `uint32_t` numeric value of the application ID. |
|
228 |
|
|
229 |
@see applicationID |
|
230 |
*/ |
|
231 |
|
|
232 |
- (void)setApplicationID:(uint32_t)appID; |
|
233 |
|
|
234 |
#if TARGET_OS_MAC && !TARGET_OS_IPHONE |
|
235 |
/** Retrieve application ID string |
|
236 |
|
|
237 |
@return The `NSString` value of the application ID. |
|
238 |
|
|
239 |
@see setApplicationIDString: |
|
240 |
*/ |
|
241 |
|
|
242 |
|
|
243 |
- (NSString*)applicationIDString; |
|
244 |
|
|
245 |
/** Set the application ID string |
|
246 |
|
|
247 |
@param string The `NSString` value of the application ID. |
|
248 |
|
|
249 |
@see applicationIDString |
|
250 |
*/ |
|
251 |
|
|
252 |
- (void)setApplicationIDString:(NSString*)string; |
|
253 |
|
|
254 |
#endif |
|
255 |
|
|
256 |
///----------------------------------- |
|
257 |
/// @name user version identifier tasks |
|
258 |
///----------------------------------- |
|
259 |
|
|
260 |
/** Retrieve user version |
|
261 |
|
|
262 |
@return The `uint32_t` numeric value of the user version. |
|
263 |
|
|
264 |
@see setUserVersion: |
|
265 |
*/ |
|
266 |
|
|
267 |
- (uint32_t)userVersion; |
|
268 |
|
|
269 |
/** Set the user-version |
|
270 |
|
|
271 |
@param version The `uint32_t` numeric value of the user version. |
|
272 |
|
|
273 |
@see userVersion |
|
274 |
*/ |
|
275 |
|
|
276 |
- (void)setUserVersion:(uint32_t)version; |
|
277 |
|
|
278 |
@end |