commit | author | age
|
6e1425
|
1 |
#import <Foundation/Foundation.h> |
H |
2 |
#import "FMResultSet.h" |
|
3 |
#import "FMDatabasePool.h" |
|
4 |
|
09e73a
|
5 |
NS_ASSUME_NONNULL_BEGIN |
6e1425
|
6 |
|
H |
7 |
#if ! __has_feature(objc_arc) |
|
8 |
#define FMDBAutorelease(__v) ([__v autorelease]); |
|
9 |
#define FMDBReturnAutoreleased FMDBAutorelease |
|
10 |
|
|
11 |
#define FMDBRetain(__v) ([__v retain]); |
|
12 |
#define FMDBReturnRetained FMDBRetain |
|
13 |
|
|
14 |
#define FMDBRelease(__v) ([__v release]); |
|
15 |
|
|
16 |
#define FMDBDispatchQueueRelease(__v) (dispatch_release(__v)); |
|
17 |
#else |
|
18 |
// -fobjc-arc |
|
19 |
#define FMDBAutorelease(__v) |
|
20 |
#define FMDBReturnAutoreleased(__v) (__v) |
|
21 |
|
|
22 |
#define FMDBRetain(__v) |
|
23 |
#define FMDBReturnRetained(__v) (__v) |
|
24 |
|
|
25 |
#define FMDBRelease(__v) |
|
26 |
|
|
27 |
// If OS_OBJECT_USE_OBJC=1, then the dispatch objects will be treated like ObjC objects |
|
28 |
// and will participate in ARC. |
|
29 |
// See the section on "Dispatch Queues and Automatic Reference Counting" in "Grand Central Dispatch (GCD) Reference" for details. |
|
30 |
#if OS_OBJECT_USE_OBJC |
|
31 |
#define FMDBDispatchQueueRelease(__v) |
|
32 |
#else |
|
33 |
#define FMDBDispatchQueueRelease(__v) (dispatch_release(__v)); |
|
34 |
#endif |
|
35 |
#endif |
|
36 |
|
|
37 |
#if !__has_feature(objc_instancetype) |
|
38 |
#define instancetype id |
|
39 |
#endif |
|
40 |
|
09e73a
|
41 |
/** |
L |
42 |
Callback block used by @c executeStatements:withResultBlock: |
|
43 |
*/ |
6e1425
|
44 |
typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary); |
H |
45 |
|
09e73a
|
46 |
/** |
L |
47 |
Enumeration used in checkpoint methods. |
6e1425
|
48 |
*/ |
09e73a
|
49 |
typedef NS_ENUM(int, FMDBCheckpointMode) { |
L |
50 |
FMDBCheckpointModePassive = 0, // SQLITE_CHECKPOINT_PASSIVE, |
|
51 |
FMDBCheckpointModeFull = 1, // SQLITE_CHECKPOINT_FULL, |
|
52 |
FMDBCheckpointModeRestart = 2, // SQLITE_CHECKPOINT_RESTART, |
|
53 |
FMDBCheckpointModeTruncate = 3 // SQLITE_CHECKPOINT_TRUNCATE |
|
54 |
}; |
6e1425
|
55 |
|
H |
56 |
#pragma clang diagnostic push |
|
57 |
#pragma clang diagnostic ignored "-Wobjc-interface-ivars" |
|
58 |
|
09e73a
|
59 |
/** A SQLite ([https://sqlite.org/](https://sqlite.org/)) Objective-C wrapper. |
6e1425
|
60 |
|
09e73a
|
61 |
Usage |
6e1425
|
62 |
|
09e73a
|
63 |
The three main classes in FMDB are: |
L |
64 |
|
|
65 |
- @c FMDatabase - Represents a single SQLite database. Used for executing SQL statements. |
|
66 |
|
|
67 |
- @c FMResultSet - Represents the results of executing a query on an @c FMDatabase . |
|
68 |
|
|
69 |
- @c FMDatabaseQueue - If you want to perform queries and updates on multiple threads, you'll want to use this class. |
|
70 |
|
|
71 |
See also |
|
72 |
|
|
73 |
- @c FMDatabasePool - A pool of @c FMDatabase objects |
|
74 |
|
|
75 |
- @c FMStatement - A wrapper for @c sqlite_stmt |
|
76 |
|
|
77 |
External links |
|
78 |
|
|
79 |
- [FMDB on GitHub](https://github.com/ccgus/fmdb) including introductory documentation |
|
80 |
- [SQLite web site](https://sqlite.org/) |
|
81 |
- [FMDB mailing list](http://groups.google.com/group/fmdb) |
|
82 |
- [SQLite FAQ](https://sqlite.org/faq.html) |
|
83 |
|
|
84 |
@warning Do not instantiate a single @c FMDatabase object and use it across multiple threads. Instead, use @c FMDatabaseQueue . |
|
85 |
|
|
86 |
*/ |
|
87 |
|
|
88 |
@interface FMDatabase : NSObject |
6e1425
|
89 |
|
H |
90 |
///----------------- |
|
91 |
/// @name Properties |
|
92 |
///----------------- |
|
93 |
|
|
94 |
/** Whether should trace execution */ |
|
95 |
|
|
96 |
@property (atomic, assign) BOOL traceExecution; |
|
97 |
|
|
98 |
/** Whether checked out or not */ |
|
99 |
|
|
100 |
@property (atomic, assign) BOOL checkedOut; |
|
101 |
|
|
102 |
/** Crash on errors */ |
|
103 |
|
|
104 |
@property (atomic, assign) BOOL crashOnErrors; |
|
105 |
|
|
106 |
/** Logs errors */ |
|
107 |
|
|
108 |
@property (atomic, assign) BOOL logsErrors; |
|
109 |
|
|
110 |
/** Dictionary of cached statements */ |
|
111 |
|
09e73a
|
112 |
@property (atomic, retain, nullable) NSMutableDictionary *cachedStatements; |
6e1425
|
113 |
|
H |
114 |
///--------------------- |
|
115 |
/// @name Initialization |
|
116 |
///--------------------- |
|
117 |
|
09e73a
|
118 |
/** Create a @c FMDatabase object. |
6e1425
|
119 |
|
09e73a
|
120 |
An @c FMDatabase is created with a path to a SQLite database file. This path can be one of these three: |
6e1425
|
121 |
|
H |
122 |
1. A file system path. The file does not have to exist on disk. If it does not exist, it is created for you. |
|
123 |
|
09e73a
|
124 |
2. An zero-length string. An empty database is created at a temporary location. This database is deleted with the @c FMDatabase connection is closed. |
6e1425
|
125 |
|
09e73a
|
126 |
3. @c nil . An in-memory database is created. This database will be destroyed with the @c FMDatabase connection is closed. |
6e1425
|
127 |
|
09e73a
|
128 |
For example, to open a database in the app's “Application Support” directory: |
6e1425
|
129 |
|
09e73a
|
130 |
@code |
L |
131 |
NSURL *folder = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:true error:&error]; |
|
132 |
NSURL *fileURL = [folder URLByAppendingPathComponent:@"test.db"]; |
|
133 |
FMDatabase *db = [FMDatabase databaseWithPath:fileURL.path]; |
|
134 |
@endcode |
6e1425
|
135 |
|
09e73a
|
136 |
(For more information on temporary and in-memory databases, read the sqlite documentation on the subject: [https://sqlite.org/inmemorydb.html](https://sqlite.org/inmemorydb.html)) |
6e1425
|
137 |
|
H |
138 |
@param inPath Path of database file |
|
139 |
|
09e73a
|
140 |
@return @c FMDatabase object if successful; @c nil if failure. |
6e1425
|
141 |
|
H |
142 |
*/ |
|
143 |
|
09e73a
|
144 |
+ (instancetype)databaseWithPath:(NSString * _Nullable)inPath; |
6e1425
|
145 |
|
09e73a
|
146 |
/** Create a @c FMDatabase object. |
6e1425
|
147 |
|
09e73a
|
148 |
An @c FMDatabase is created with a path to a SQLite database file. This path can be one of these three: |
L |
149 |
|
|
150 |
1. A file system URL. The file does not have to exist on disk. If it does not exist, it is created for you. |
|
151 |
|
|
152 |
2. @c nil . An in-memory database is created. This database will be destroyed with the @c FMDatabase connection is closed. |
|
153 |
|
|
154 |
For example, to open a database in the app's “Application Support” directory: |
|
155 |
|
|
156 |
@code |
|
157 |
NSURL *folder = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:true error:&error]; |
|
158 |
NSURL *fileURL = [folder URLByAppendingPathComponent:@"test.db"]; |
|
159 |
FMDatabase *db = [FMDatabase databaseWithURL:fileURL]; |
|
160 |
@endcode |
|
161 |
|
|
162 |
(For more information on temporary and in-memory databases, read the sqlite documentation on the subject: [https://sqlite.org/inmemorydb.html](https://sqlite.org/inmemorydb.html)) |
|
163 |
|
|
164 |
@param url The local file URL (not remote URL) of database file |
|
165 |
|
|
166 |
@return @c FMDatabase object if successful; @c nil if failure. |
|
167 |
|
|
168 |
*/ |
|
169 |
|
|
170 |
+ (instancetype)databaseWithURL:(NSURL * _Nullable)url; |
|
171 |
|
|
172 |
/** Initialize a @c FMDatabase object. |
|
173 |
|
|
174 |
An @c FMDatabase is created with a path to a SQLite database file. This path can be one of these three: |
6e1425
|
175 |
|
H |
176 |
1. A file system path. The file does not have to exist on disk. If it does not exist, it is created for you. |
|
177 |
|
09e73a
|
178 |
2. A zero-length string. An empty database is created at a temporary location. This database is deleted with the @c FMDatabase connection is closed. |
6e1425
|
179 |
|
09e73a
|
180 |
3. @c nil . An in-memory database is created. This database will be destroyed with the @c FMDatabase connection is closed. |
6e1425
|
181 |
|
09e73a
|
182 |
For example, to open a database in the app's “Application Support” directory: |
6e1425
|
183 |
|
09e73a
|
184 |
@code |
L |
185 |
NSURL *folder = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:true error:&error]; |
|
186 |
NSURL *fileURL = [folder URLByAppendingPathComponent:@"test.db"]; |
|
187 |
FMDatabase *db = [[FMDatabase alloc] initWithPath:fileURL.path]; |
|
188 |
@endcode |
6e1425
|
189 |
|
H |
190 |
|
09e73a
|
191 |
(For more information on temporary and in-memory databases, read the sqlite documentation on the subject: [https://sqlite.org/inmemorydb.html](https://sqlite.org/inmemorydb.html)) |
L |
192 |
|
|
193 |
@param path Path of database file. |
6e1425
|
194 |
|
09e73a
|
195 |
@return @c FMDatabase object if successful; @c nil if failure. |
6e1425
|
196 |
|
H |
197 |
*/ |
|
198 |
|
09e73a
|
199 |
- (instancetype)initWithPath:(NSString * _Nullable)path; |
6e1425
|
200 |
|
09e73a
|
201 |
/** Initialize a @c FMDatabase object. |
L |
202 |
|
|
203 |
An @c FMDatabase is created with a local file URL to a SQLite database file. This path can be one of these three: |
|
204 |
|
|
205 |
1. A file system URL. The file does not have to exist on disk. If it does not exist, it is created for you. |
|
206 |
|
|
207 |
2. @c nil . An in-memory database is created. This database will be destroyed with the @c FMDatabase connection is closed. |
|
208 |
|
|
209 |
For example, to open a database in the app's “Application Support” directory: |
|
210 |
|
|
211 |
@code |
|
212 |
NSURL *folder = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:true error:&error]; |
|
213 |
NSURL *fileURL = [folder URLByAppendingPathComponent:@"test.db"]; |
|
214 |
FMDatabase *db = [[FMDatabase alloc] initWithURL:fileURL]; |
|
215 |
@endcode |
|
216 |
|
|
217 |
(For more information on temporary and in-memory databases, read the sqlite documentation on the subject: [https://sqlite.org/inmemorydb.html](https://sqlite.org/inmemorydb.html)) |
|
218 |
|
|
219 |
@param url The file @c NSURL of database file. |
|
220 |
|
|
221 |
@return @c FMDatabase object if successful; @c nil if failure. |
|
222 |
|
|
223 |
*/ |
|
224 |
|
|
225 |
- (instancetype)initWithURL:(NSURL * _Nullable)url; |
6e1425
|
226 |
|
H |
227 |
///----------------------------------- |
|
228 |
/// @name Opening and closing database |
|
229 |
///----------------------------------- |
|
230 |
|
09e73a
|
231 |
/// Is the database open or not? |
L |
232 |
|
|
233 |
@property (nonatomic) BOOL isOpen; |
|
234 |
|
6e1425
|
235 |
/** Opening a new database connection |
H |
236 |
|
|
237 |
The database is opened for reading and writing, and is created if it does not already exist. |
|
238 |
|
09e73a
|
239 |
@return @c YES if successful, @c NO on error. |
6e1425
|
240 |
|
09e73a
|
241 |
@see [sqlite3_open()](https://sqlite.org/c3ref/open.html) |
6e1425
|
242 |
@see openWithFlags: |
H |
243 |
@see close |
|
244 |
*/ |
|
245 |
|
|
246 |
- (BOOL)open; |
|
247 |
|
|
248 |
/** Opening a new database connection with flags and an optional virtual file system (VFS) |
|
249 |
|
09e73a
|
250 |
@param flags One of the following three values, optionally combined with the @c SQLITE_OPEN_NOMUTEX , @c SQLITE_OPEN_FULLMUTEX , @c SQLITE_OPEN_SHAREDCACHE , @c SQLITE_OPEN_PRIVATECACHE , and/or @c SQLITE_OPEN_URI flags: |
6e1425
|
251 |
|
09e73a
|
252 |
@code |
L |
253 |
SQLITE_OPEN_READONLY |
|
254 |
@endcode |
6e1425
|
255 |
|
H |
256 |
The database is opened in read-only mode. If the database does not already exist, an error is returned. |
|
257 |
|
09e73a
|
258 |
@code |
L |
259 |
SQLITE_OPEN_READWRITE |
|
260 |
@endcode |
6e1425
|
261 |
|
09e73a
|
262 |
The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned. |
L |
263 |
|
|
264 |
@code |
|
265 |
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
|
266 |
@endcode |
|
267 |
|
|
268 |
The database is opened for reading and writing, and is created if it does not already exist. This is the behavior that is always used for @c open method. |
|
269 |
|
|
270 |
@return @c YES if successful, @c NO on error. |
|
271 |
|
|
272 |
@see [sqlite3_open_v2()](https://sqlite.org/c3ref/open.html) |
6e1425
|
273 |
@see open |
H |
274 |
@see close |
|
275 |
*/ |
|
276 |
|
|
277 |
- (BOOL)openWithFlags:(int)flags; |
|
278 |
|
|
279 |
/** Opening a new database connection with flags and an optional virtual file system (VFS) |
|
280 |
|
09e73a
|
281 |
@param flags One of the following three values, optionally combined with the @c SQLITE_OPEN_NOMUTEX , `SQLITE_OPEN_FULLMUTEX`, `SQLITE_OPEN_SHAREDCACHE`, @c SQLITE_OPEN_PRIVATECACHE , and/or @c SQLITE_OPEN_URI flags: |
6e1425
|
282 |
|
09e73a
|
283 |
@code |
L |
284 |
SQLITE_OPEN_READONLY |
|
285 |
@endcode |
|
286 |
|
|
287 |
The database is opened in read-only mode. If the database does not already exist, an error is returned. |
|
288 |
|
|
289 |
@code |
|
290 |
SQLITE_OPEN_READWRITE |
|
291 |
@endcode |
|
292 |
|
|
293 |
The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned. |
|
294 |
|
|
295 |
@code |
|
296 |
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
|
297 |
@endcode |
|
298 |
|
|
299 |
The database is opened for reading and writing, and is created if it does not already exist. This is the behavior that is always used for @c open method. |
6e1425
|
300 |
|
H |
301 |
@param vfsName If vfs is given the value is passed to the vfs parameter of sqlite3_open_v2. |
|
302 |
|
09e73a
|
303 |
@return @c YES if successful, @c NO on error. |
6e1425
|
304 |
|
09e73a
|
305 |
@see [sqlite3_open_v2()](https://sqlite.org/c3ref/open.html) |
6e1425
|
306 |
@see open |
H |
307 |
@see close |
|
308 |
*/ |
|
309 |
|
09e73a
|
310 |
- (BOOL)openWithFlags:(int)flags vfs:(NSString * _Nullable)vfsName; |
6e1425
|
311 |
|
H |
312 |
/** Closing a database connection |
|
313 |
|
09e73a
|
314 |
@return @c YES if success, @c NO on error. |
6e1425
|
315 |
|
09e73a
|
316 |
@see [sqlite3_close()](https://sqlite.org/c3ref/close.html) |
6e1425
|
317 |
@see open |
H |
318 |
@see openWithFlags: |
|
319 |
*/ |
|
320 |
|
|
321 |
- (BOOL)close; |
|
322 |
|
|
323 |
/** Test to see if we have a good connection to the database. |
|
324 |
|
|
325 |
This will confirm whether: |
|
326 |
|
|
327 |
- is database open |
|
328 |
|
09e73a
|
329 |
- if open, it will try a simple @c SELECT statement and confirm that it succeeds. |
L |
330 |
|
|
331 |
@return @c YES if everything succeeds, @c NO on failure. |
6e1425
|
332 |
*/ |
H |
333 |
|
09e73a
|
334 |
@property (nonatomic, readonly) BOOL goodConnection; |
6e1425
|
335 |
|
H |
336 |
|
|
337 |
///---------------------- |
|
338 |
/// @name Perform updates |
|
339 |
///---------------------- |
|
340 |
|
|
341 |
/** Execute single update statement |
|
342 |
|
09e73a
|
343 |
This method executes a single SQL update statement (i.e. any SQL that does not return results, such as @c UPDATE , @c INSERT , or @c DELETE . This method employs [`sqlite3_prepare_v2`](https://sqlite.org/c3ref/prepare.html), [`sqlite3_bind`](https://sqlite.org/c3ref/bind_blob.html) to bind values to `?` placeholders in the SQL with the optional list of parameters, and [`sqlite_step`](https://sqlite.org/c3ref/step.html) to perform the update. |
6e1425
|
344 |
|
09e73a
|
345 |
The optional values provided to this method should be objects (e.g. @c NSString , @c NSNumber , @c NSNull , @c NSDate , and @c NSData objects), not fundamental data types (e.g. @c int , @c long , @c NSInteger , etc.). This method automatically handles the aforementioned object types, and all other object types will be interpreted as text values using the object's @c description method. |
6e1425
|
346 |
|
09e73a
|
347 |
@param sql The SQL to be performed, with optional `?` placeholders. This can be followed by iptional parameters to bind to `?` placeholders in the SQL statement. These should be Objective-C objects (e.g. @c NSString , @c NSNumber , etc.), not fundamental C data types (e.g. @c int , etc.). |
6e1425
|
348 |
|
09e73a
|
349 |
@param outErr A reference to the @c NSError pointer to be updated with an auto released @c NSError object if an error if an error occurs. If @c nil , no @c NSError object will be returned. |
6e1425
|
350 |
|
09e73a
|
351 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
352 |
|
H |
353 |
@see lastError |
|
354 |
@see lastErrorCode |
|
355 |
@see lastErrorMessage |
09e73a
|
356 |
@see [`sqlite3_bind`](https://sqlite.org/c3ref/bind_blob.html) |
6e1425
|
357 |
*/ |
H |
358 |
|
09e73a
|
359 |
- (BOOL)executeUpdate:(NSString*)sql withErrorAndBindings:(NSError * _Nullable __autoreleasing *)outErr, ...; |
6e1425
|
360 |
|
H |
361 |
/** Execute single update statement |
|
362 |
|
|
363 |
@see executeUpdate:withErrorAndBindings: |
|
364 |
|
|
365 |
@warning **Deprecated**: Please use `<executeUpdate:withErrorAndBindings>` instead. |
|
366 |
*/ |
|
367 |
|
09e73a
|
368 |
- (BOOL)update:(NSString*)sql withErrorAndBindings:(NSError * _Nullable __autoreleasing *)outErr, ... __deprecated_msg("Use executeUpdate:withErrorAndBindings: instead");; |
6e1425
|
369 |
|
H |
370 |
/** Execute single update statement |
|
371 |
|
09e73a
|
372 |
This method executes a single SQL update statement (i.e. any SQL that does not return results, such as @c UPDATE , @c INSERT , or @c DELETE . This method employs [`sqlite3_prepare_v2`](https://sqlite.org/c3ref/prepare.html), [`sqlite3_bind`](https://sqlite.org/c3ref/bind_blob.html) to bind values to `?` placeholders in the SQL with the optional list of parameters, and [`sqlite_step`](https://sqlite.org/c3ref/step.html) to perform the update. |
6e1425
|
373 |
|
09e73a
|
374 |
The optional values provided to this method should be objects (e.g. @c NSString , @c NSNumber , @c NSNull , @c NSDate , and @c NSData objects), not fundamental data types (e.g. @c int , @c long , @c NSInteger , etc.). This method automatically handles the aforementioned object types, and all other object types will be interpreted as text values using the object's @c description method. |
6e1425
|
375 |
|
09e73a
|
376 |
@param sql The SQL to be performed, with optional `?` placeholders, followed by optional parameters to bind to `?` placeholders in the SQL statement. These should be Objective-C objects (e.g. @c NSString , @c NSNumber , etc.), not fundamental C data types (e.g. @c int , etc.). |
6e1425
|
377 |
|
09e73a
|
378 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
379 |
|
H |
380 |
@see lastError |
|
381 |
@see lastErrorCode |
|
382 |
@see lastErrorMessage |
09e73a
|
383 |
@see [`sqlite3_bind`](https://sqlite.org/c3ref/bind_blob.html) |
6e1425
|
384 |
|
09e73a
|
385 |
@note This technique supports the use of `?` placeholders in the SQL, automatically binding any supplied value parameters to those placeholders. This approach is more robust than techniques that entail using @c stringWithFormat to manually build SQL statements, which can be problematic if the values happened to include any characters that needed to be quoted. |
6e1425
|
386 |
|
09e73a
|
387 |
@note You cannot use this method from Swift due to incompatibilities between Swift and Objective-C variadic implementations. Consider using `<executeUpdate:values:>` instead. |
6e1425
|
388 |
*/ |
H |
389 |
|
|
390 |
- (BOOL)executeUpdate:(NSString*)sql, ...; |
|
391 |
|
|
392 |
/** Execute single update statement |
|
393 |
|
09e73a
|
394 |
This method executes a single SQL update statement (i.e. any SQL that does not return results, such as @c UPDATE , @c INSERT , or @c DELETE . This method employs [`sqlite3_prepare_v2`](https://sqlite.org/c3ref/prepare.html) and [`sqlite_step`](https://sqlite.org/c3ref/step.html) to perform the update. Unlike the other @c executeUpdate methods, this uses printf-style formatters (e.g. `%s`, `%d`, etc.) to build the SQL. Do not use `?` placeholders in the SQL if you use this method. |
6e1425
|
395 |
|
09e73a
|
396 |
@param format The SQL to be performed, with `printf`-style escape sequences, followed by optional parameters to bind to use in conjunction with the `printf`-style escape sequences in the SQL statement. |
6e1425
|
397 |
|
09e73a
|
398 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
399 |
|
H |
400 |
@see executeUpdate: |
|
401 |
@see lastError |
|
402 |
@see lastErrorCode |
|
403 |
@see lastErrorMessage |
|
404 |
|
|
405 |
@note This method does not technically perform a traditional printf-style replacement. What this method actually does is replace the printf-style percent sequences with a SQLite `?` placeholder, and then bind values to that placeholder. Thus the following command |
|
406 |
|
09e73a
|
407 |
@code |
L |
408 |
[db executeUpdateWithFormat:@"INSERT INTO test (name) VALUES (%@)", @"Gus"]; |
|
409 |
@endcode |
6e1425
|
410 |
|
H |
411 |
is actually replacing the `%@` with `?` placeholder, and then performing something equivalent to `<executeUpdate:>` |
|
412 |
|
09e73a
|
413 |
@code |
L |
414 |
[db executeUpdate:@"INSERT INTO test (name) VALUES (?)", @"Gus"]; |
|
415 |
@endcode |
6e1425
|
416 |
|
09e73a
|
417 |
There are two reasons why this distinction is important. First, the printf-style escape sequences can only be used where it is permissible to use a SQLite `?` placeholder. You can use it only for values in SQL statements, but not for table names or column names or any other non-value context. This method also cannot be used in conjunction with `pragma` statements and the like. Second, note the lack of quotation marks in the SQL. The `VALUES` clause was _not_ `VALUES ('%@')` (like you might have to do if you built a SQL statement using @c NSString method @c stringWithFormat ), but rather simply `VALUES (%@)`. |
6e1425
|
418 |
*/ |
H |
419 |
|
|
420 |
- (BOOL)executeUpdateWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2); |
|
421 |
|
|
422 |
/** Execute single update statement |
|
423 |
|
09e73a
|
424 |
This method executes a single SQL update statement (i.e. any SQL that does not return results, such as @c UPDATE , @c INSERT , or @c DELETE . This method employs [`sqlite3_prepare_v2`](https://sqlite.org/c3ref/prepare.html) and [`sqlite3_bind`](https://sqlite.org/c3ref/bind_blob.html) binding any `?` placeholders in the SQL with the optional list of parameters. |
6e1425
|
425 |
|
09e73a
|
426 |
The optional values provided to this method should be objects (e.g. @c NSString , @c NSNumber , @c NSNull , @c NSDate , and @c NSData objects), not fundamental data types (e.g. @c int , @c long , @c NSInteger , etc.). This method automatically handles the aforementioned object types, and all other object types will be interpreted as text values using the object's @c description method. |
6e1425
|
427 |
|
H |
428 |
@param sql The SQL to be performed, with optional `?` placeholders. |
|
429 |
|
09e73a
|
430 |
@param arguments A @c NSArray of objects to be used when binding values to the `?` placeholders in the SQL statement. |
6e1425
|
431 |
|
09e73a
|
432 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
433 |
|
H |
434 |
@see executeUpdate:values:error: |
|
435 |
@see lastError |
|
436 |
@see lastErrorCode |
|
437 |
@see lastErrorMessage |
|
438 |
*/ |
|
439 |
|
|
440 |
- (BOOL)executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments; |
|
441 |
|
|
442 |
/** Execute single update statement |
|
443 |
|
09e73a
|
444 |
This method executes a single SQL update statement (i.e. any SQL that does not return results, such as @c UPDATE , @c INSERT , or @c DELETE . This method employs [`sqlite3_prepare_v2`](https://sqlite.org/c3ref/prepare.html) and [`sqlite3_bind`](https://sqlite.org/c3ref/bind_blob.html) binding any `?` placeholders in the SQL with the optional list of parameters. |
6e1425
|
445 |
|
09e73a
|
446 |
The optional values provided to this method should be objects (e.g. @c NSString , @c NSNumber , @c NSNull , @c NSDate , and @c NSData objects), not fundamental data types (e.g. @c int , @c long , @c NSInteger , etc.). This method automatically handles the aforementioned object types, and all other object types will be interpreted as text values using the object's @c description method. |
6e1425
|
447 |
|
09e73a
|
448 |
This is similar to @c executeUpdate:withArgumentsInArray: , except that this also accepts a pointer to a @c NSError pointer, so that errors can be returned. |
6e1425
|
449 |
|
09e73a
|
450 |
In Swift, this throws errors, as if it were defined as follows: |
6e1425
|
451 |
|
09e73a
|
452 |
@code |
L |
453 |
func executeUpdate(sql: String, values: [Any]?) throws -> Bool { } |
|
454 |
@endcode |
|
455 |
|
6e1425
|
456 |
@param sql The SQL to be performed, with optional `?` placeholders. |
H |
457 |
|
09e73a
|
458 |
@param values A @c NSArray of objects to be used when binding values to the `?` placeholders in the SQL statement. |
6e1425
|
459 |
|
09e73a
|
460 |
@param error A @c NSError object to receive any error object (if any). |
6e1425
|
461 |
|
09e73a
|
462 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
463 |
|
H |
464 |
@see lastError |
|
465 |
@see lastErrorCode |
|
466 |
@see lastErrorMessage |
|
467 |
|
|
468 |
*/ |
|
469 |
|
09e73a
|
470 |
- (BOOL)executeUpdate:(NSString*)sql values:(NSArray * _Nullable)values error:(NSError * _Nullable __autoreleasing *)error; |
6e1425
|
471 |
|
H |
472 |
/** Execute single update statement |
|
473 |
|
09e73a
|
474 |
This method executes a single SQL update statement (i.e. any SQL that does not return results, such as @c UPDATE , @c INSERT , or @c DELETE . This method employs [`sqlite3_prepare_v2`](https://sqlite.org/c3ref/prepare.html) and [`sqlite_step`](https://sqlite.org/c3ref/step.html) to perform the update. Unlike the other @c executeUpdate methods, this uses printf-style formatters (e.g. `%s`, `%d`, etc.) to build the SQL. |
6e1425
|
475 |
|
09e73a
|
476 |
The optional values provided to this method should be objects (e.g. @c NSString , @c NSNumber , @c NSNull , @c NSDate , and @c NSData objects), not fundamental data types (e.g. @c int , @c long , @c NSInteger , etc.). This method automatically handles the aforementioned object types, and all other object types will be interpreted as text values using the object's @c description method. |
6e1425
|
477 |
|
H |
478 |
@param sql The SQL to be performed, with optional `?` placeholders. |
|
479 |
|
09e73a
|
480 |
@param arguments A @c NSDictionary of objects keyed by column names that will be used when binding values to the `?` placeholders in the SQL statement. |
6e1425
|
481 |
|
09e73a
|
482 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
483 |
|
H |
484 |
@see lastError |
|
485 |
@see lastErrorCode |
|
486 |
@see lastErrorMessage |
|
487 |
*/ |
|
488 |
|
|
489 |
- (BOOL)executeUpdate:(NSString*)sql withParameterDictionary:(NSDictionary *)arguments; |
|
490 |
|
|
491 |
|
|
492 |
/** Execute single update statement |
|
493 |
|
09e73a
|
494 |
This method executes a single SQL update statement (i.e. any SQL that does not return results, such as @c UPDATE , @c INSERT , or @c DELETE . This method employs [`sqlite3_prepare_v2`](https://sqlite.org/c3ref/prepare.html) and [`sqlite_step`](https://sqlite.org/c3ref/step.html) to perform the update. Unlike the other @c executeUpdate methods, this uses printf-style formatters (e.g. `%s`, `%d`, etc.) to build the SQL. |
6e1425
|
495 |
|
09e73a
|
496 |
The optional values provided to this method should be objects (e.g. @c NSString , @c NSNumber , @c NSNull , @c NSDate , and @c NSData objects), not fundamental data types (e.g. @c int , @c long , @c NSInteger , etc.). This method automatically handles the aforementioned object types, and all other object types will be interpreted as text values using the object's @c description method. |
6e1425
|
497 |
|
H |
498 |
@param sql The SQL to be performed, with optional `?` placeholders. |
|
499 |
|
|
500 |
@param args A `va_list` of arguments. |
|
501 |
|
09e73a
|
502 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
503 |
|
H |
504 |
@see lastError |
|
505 |
@see lastErrorCode |
|
506 |
@see lastErrorMessage |
|
507 |
*/ |
|
508 |
|
|
509 |
- (BOOL)executeUpdate:(NSString*)sql withVAList: (va_list)args; |
|
510 |
|
|
511 |
/** Execute multiple SQL statements |
|
512 |
|
09e73a
|
513 |
This executes a series of SQL statements that are combined in a single string (e.g. the SQL generated by the `sqlite3` command line `.dump` command). This accepts no value parameters, but rather simply expects a single string with multiple SQL statements, each terminated with a semicolon. This uses @c sqlite3_exec . |
6e1425
|
514 |
|
H |
515 |
@param sql The SQL to be performed |
|
516 |
|
09e73a
|
517 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
518 |
|
H |
519 |
@see executeStatements:withResultBlock: |
09e73a
|
520 |
@see [sqlite3_exec()](https://sqlite.org/c3ref/exec.html) |
6e1425
|
521 |
|
H |
522 |
*/ |
|
523 |
|
|
524 |
- (BOOL)executeStatements:(NSString *)sql; |
|
525 |
|
|
526 |
/** Execute multiple SQL statements with callback handler |
|
527 |
|
|
528 |
This executes a series of SQL statements that are combined in a single string (e.g. the SQL generated by the `sqlite3` command line `.dump` command). This accepts no value parameters, but rather simply expects a single string with multiple SQL statements, each terminated with a semicolon. This uses `sqlite3_exec`. |
|
529 |
|
|
530 |
@param sql The SQL to be performed. |
|
531 |
@param block A block that will be called for any result sets returned by any SQL statements. |
09e73a
|
532 |
Note, if you supply this block, it must return integer value, zero upon success (this would be a good opportunity to use @c SQLITE_OK ), |
6e1425
|
533 |
non-zero value upon failure (which will stop the bulk execution of the SQL). If a statement returns values, the block will be called with the results from the query in NSDictionary *resultsDictionary. |
09e73a
|
534 |
This may be @c nil if you don't care to receive any results. |
6e1425
|
535 |
|
09e73a
|
536 |
@return @c YES upon success; @c NO upon failure. If failed, you can call @c lastError , |
L |
537 |
@c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
538 |
|
H |
539 |
@see executeStatements: |
09e73a
|
540 |
@see [sqlite3_exec()](https://sqlite.org/c3ref/exec.html) |
6e1425
|
541 |
|
H |
542 |
*/ |
|
543 |
|
09e73a
|
544 |
- (BOOL)executeStatements:(NSString *)sql withResultBlock:(__attribute__((noescape)) FMDBExecuteStatementsCallbackBlock _Nullable)block; |
6e1425
|
545 |
|
H |
546 |
/** Last insert rowid |
|
547 |
|
|
548 |
Each entry in an SQLite table has a unique 64-bit signed integer key called the "rowid". The rowid is always available as an undeclared column named `ROWID`, `OID`, or `_ROWID_` as long as those names are not also used by explicitly declared columns. If the table has a column of type `INTEGER PRIMARY KEY` then that column is another alias for the rowid. |
|
549 |
|
09e73a
|
550 |
This routine returns the rowid of the most recent successful @c INSERT into the database from the database connection in the first argument. As of SQLite version 3.7.7, this routines records the last insert rowid of both ordinary tables and virtual tables. If no successful @c INSERT statements have ever occurred on that database connection, zero is returned. |
6e1425
|
551 |
|
H |
552 |
@return The rowid of the last inserted row. |
|
553 |
|
09e73a
|
554 |
@see [sqlite3_last_insert_rowid()](https://sqlite.org/c3ref/last_insert_rowid.html) |
6e1425
|
555 |
|
H |
556 |
*/ |
|
557 |
|
09e73a
|
558 |
@property (nonatomic, readonly) int64_t lastInsertRowId; |
6e1425
|
559 |
|
H |
560 |
/** The number of rows changed by prior SQL statement. |
|
561 |
|
09e73a
|
562 |
This function returns the number of database rows that were changed or inserted or deleted by the most recently completed SQL statement on the database connection specified by the first parameter. Only changes that are directly specified by the @c INSERT , @c UPDATE , or @c DELETE statement are counted. |
6e1425
|
563 |
|
H |
564 |
@return The number of rows changed by prior SQL statement. |
|
565 |
|
09e73a
|
566 |
@see [sqlite3_changes()](https://sqlite.org/c3ref/changes.html) |
6e1425
|
567 |
|
H |
568 |
*/ |
|
569 |
|
09e73a
|
570 |
@property (nonatomic, readonly) int changes; |
6e1425
|
571 |
|
H |
572 |
|
|
573 |
///------------------------- |
|
574 |
/// @name Retrieving results |
|
575 |
///------------------------- |
|
576 |
|
|
577 |
/** Execute select statement |
|
578 |
|
09e73a
|
579 |
Executing queries returns an @c FMResultSet object if successful, and @c nil upon failure. Like executing updates, there is a variant that accepts an `NSError **` parameter. Otherwise you should use the @c lastErrorMessage and @c lastErrorMessage methods to determine why a query failed. |
6e1425
|
580 |
|
H |
581 |
In order to iterate through the results of your query, you use a `while()` loop. You also need to "step" (via `<[FMResultSet next]>`) from one record to the other. |
|
582 |
|
09e73a
|
583 |
This method employs [`sqlite3_bind`](https://sqlite.org/c3ref/bind_blob.html) for any optional value parameters. This properly escapes any characters that need escape sequences (e.g. quotation marks), which eliminates simple SQL errors as well as protects against SQL injection attacks. This method natively handles @c NSString , @c NSNumber , @c NSNull , @c NSDate , and @c NSData objects. All other object types will be interpreted as text values using the object's @c description method. |
6e1425
|
584 |
|
09e73a
|
585 |
@param sql The SELECT statement to be performed, with optional `?` placeholders, followed by optional parameters to bind to `?` placeholders in the SQL statement. These should be Objective-C objects (e.g. @c NSString , @c NSNumber , etc.), not fundamental C data types (e.g. @c int , etc.). |
6e1425
|
586 |
|
09e73a
|
587 |
@return A @c FMResultSet for the result set upon success; @c nil upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
588 |
|
H |
589 |
@see FMResultSet |
|
590 |
@see [`FMResultSet next`](<[FMResultSet next]>) |
09e73a
|
591 |
@see [`sqlite3_bind`](https://sqlite.org/c3ref/bind_blob.html) |
6e1425
|
592 |
|
09e73a
|
593 |
@note You cannot use this method from Swift due to incompatibilities between Swift and Objective-C variadic implementations. Consider using `<executeQuery:values:>` instead. |
6e1425
|
594 |
*/ |
H |
595 |
|
09e73a
|
596 |
- (FMResultSet * _Nullable)executeQuery:(NSString*)sql, ...; |
6e1425
|
597 |
|
H |
598 |
/** Execute select statement |
|
599 |
|
09e73a
|
600 |
Executing queries returns an @c FMResultSet object if successful, and @c nil upon failure. Like executing updates, there is a variant that accepts an `NSError **` parameter. Otherwise you should use the @c lastErrorMessage and @c lastErrorMessage methods to determine why a query failed. |
6e1425
|
601 |
|
H |
602 |
In order to iterate through the results of your query, you use a `while()` loop. You also need to "step" (via `<[FMResultSet next]>`) from one record to the other. |
|
603 |
|
09e73a
|
604 |
@param format The SQL to be performed, with `printf`-style escape sequences, followed by ptional parameters to bind to use in conjunction with the `printf`-style escape sequences in the SQL statement. |
6e1425
|
605 |
|
09e73a
|
606 |
@return A @c FMResultSet for the result set upon success; @c nil upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
607 |
|
H |
608 |
@see executeQuery: |
|
609 |
@see FMResultSet |
|
610 |
@see [`FMResultSet next`](<[FMResultSet next]>) |
|
611 |
|
|
612 |
@note This method does not technically perform a traditional printf-style replacement. What this method actually does is replace the printf-style percent sequences with a SQLite `?` placeholder, and then bind values to that placeholder. Thus the following command |
|
613 |
|
09e73a
|
614 |
@code |
L |
615 |
[db executeQueryWithFormat:@"SELECT * FROM test WHERE name=%@", @"Gus"]; |
|
616 |
@endcode |
|
617 |
|
6e1425
|
618 |
is actually replacing the `%@` with `?` placeholder, and then performing something equivalent to `<executeQuery:>` |
09e73a
|
619 |
|
L |
620 |
@code |
|
621 |
[db executeQuery:@"SELECT * FROM test WHERE name=?", @"Gus"]; |
|
622 |
@endcode |
|
623 |
|
|
624 |
There are two reasons why this distinction is important. First, the printf-style escape sequences can only be used where it is permissible to use a SQLite `?` placeholder. You can use it only for values in SQL statements, but not for table names or column names or any other non-value context. This method also cannot be used in conjunction with `pragma` statements and the like. Second, note the lack of quotation marks in the SQL. The @c WHERE clause was _not_ `WHERE name='%@'` (like you might have to do if you built a SQL statement using @c NSString method @c stringWithFormat ), but rather simply `WHERE name=%@`. |
6e1425
|
625 |
|
H |
626 |
*/ |
|
627 |
|
09e73a
|
628 |
- (FMResultSet * _Nullable)executeQueryWithFormat:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2); |
6e1425
|
629 |
|
H |
630 |
/** Execute select statement |
|
631 |
|
09e73a
|
632 |
Executing queries returns an @c FMResultSet object if successful, and @c nil upon failure. Like executing updates, there is a variant that accepts an `NSError **` parameter. Otherwise you should use the @c lastErrorMessage and @c lastErrorMessage methods to determine why a query failed. |
6e1425
|
633 |
|
H |
634 |
In order to iterate through the results of your query, you use a `while()` loop. You also need to "step" (via `<[FMResultSet next]>`) from one record to the other. |
|
635 |
|
|
636 |
@param sql The SELECT statement to be performed, with optional `?` placeholders. |
|
637 |
|
09e73a
|
638 |
@param arguments A @c NSArray of objects to be used when binding values to the `?` placeholders in the SQL statement. |
6e1425
|
639 |
|
09e73a
|
640 |
@return A @c FMResultSet for the result set upon success; @c nil upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
641 |
|
H |
642 |
@see -executeQuery:values:error: |
|
643 |
@see FMResultSet |
|
644 |
@see [`FMResultSet next`](<[FMResultSet next]>) |
|
645 |
*/ |
|
646 |
|
09e73a
|
647 |
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments; |
6e1425
|
648 |
|
H |
649 |
/** Execute select statement |
|
650 |
|
09e73a
|
651 |
Executing queries returns an @c FMResultSet object if successful, and @c nil upon failure. Like executing updates, there is a variant that accepts an `NSError **` parameter. Otherwise you should use the @c lastErrorMessage and @c lastErrorMessage methods to determine why a query failed. |
6e1425
|
652 |
|
H |
653 |
In order to iterate through the results of your query, you use a `while()` loop. You also need to "step" (via `<[FMResultSet next]>`) from one record to the other. |
|
654 |
|
09e73a
|
655 |
This is similar to `<executeQuery:withArgumentsInArray:>`, except that this also accepts a pointer to a @c NSError pointer, so that errors can be returned. |
6e1425
|
656 |
|
09e73a
|
657 |
In Swift, this throws errors, as if it were defined as follows: |
6e1425
|
658 |
|
09e73a
|
659 |
`func executeQuery(sql: String, values: [Any]?) throws -> FMResultSet!` |
6e1425
|
660 |
|
H |
661 |
@param sql The SELECT statement to be performed, with optional `?` placeholders. |
|
662 |
|
09e73a
|
663 |
@param values A @c NSArray of objects to be used when binding values to the `?` placeholders in the SQL statement. |
6e1425
|
664 |
|
09e73a
|
665 |
@param error A @c NSError object to receive any error object (if any). |
6e1425
|
666 |
|
09e73a
|
667 |
@return A @c FMResultSet for the result set upon success; @c nil upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
668 |
|
H |
669 |
@see FMResultSet |
|
670 |
@see [`FMResultSet next`](<[FMResultSet next]>) |
|
671 |
|
|
672 |
@note When called from Swift, only use the first two parameters, `sql` and `values`. This but throws the error. |
|
673 |
|
|
674 |
*/ |
|
675 |
|
09e73a
|
676 |
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql values:(NSArray * _Nullable)values error:(NSError * _Nullable __autoreleasing *)error; |
6e1425
|
677 |
|
H |
678 |
/** Execute select statement |
|
679 |
|
09e73a
|
680 |
Executing queries returns an @c FMResultSet object if successful, and @c nil upon failure. Like executing updates, there is a variant that accepts an `NSError **` parameter. Otherwise you should use the @c lastErrorMessage and @c lastErrorMessage methods to determine why a query failed. |
6e1425
|
681 |
|
H |
682 |
In order to iterate through the results of your query, you use a `while()` loop. You also need to "step" (via `<[FMResultSet next]>`) from one record to the other. |
|
683 |
|
|
684 |
@param sql The SELECT statement to be performed, with optional `?` placeholders. |
|
685 |
|
09e73a
|
686 |
@param arguments A @c NSDictionary of objects keyed by column names that will be used when binding values to the `?` placeholders in the SQL statement. |
6e1425
|
687 |
|
09e73a
|
688 |
@return A @c FMResultSet for the result set upon success; @c nil upon failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
689 |
|
H |
690 |
@see FMResultSet |
|
691 |
@see [`FMResultSet next`](<[FMResultSet next]>) |
|
692 |
*/ |
|
693 |
|
09e73a
|
694 |
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql withParameterDictionary:(NSDictionary * _Nullable)arguments; |
6e1425
|
695 |
|
H |
696 |
|
|
697 |
// Documentation forthcoming. |
09e73a
|
698 |
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql withVAList:(va_list)args; |
L |
699 |
|
|
700 |
/// Prepare SQL statement. |
|
701 |
/// |
|
702 |
/// @param sql SQL statement to prepare, generally with `?` placeholders. |
|
703 |
|
|
704 |
- (FMResultSet *)prepare:(NSString *)sql; |
6e1425
|
705 |
|
H |
706 |
///------------------- |
|
707 |
/// @name Transactions |
|
708 |
///------------------- |
|
709 |
|
|
710 |
/** Begin a transaction |
|
711 |
|
09e73a
|
712 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
713 |
|
H |
714 |
@see commit |
|
715 |
@see rollback |
|
716 |
@see beginDeferredTransaction |
09e73a
|
717 |
@see isInTransaction |
L |
718 |
|
|
719 |
@warning Unlike SQLite's `BEGIN TRANSACTION`, this method currently performs |
|
720 |
an exclusive transaction, not a deferred transaction. This behavior |
|
721 |
is likely to change in future versions of FMDB, whereby this method |
|
722 |
will likely eventually adopt standard SQLite behavior and perform |
|
723 |
deferred transactions. If you really need exclusive tranaction, it is |
|
724 |
recommended that you use @c beginExclusiveTransaction, instead, not |
|
725 |
only to make your intent explicit, but also to future-proof your code. |
|
726 |
|
6e1425
|
727 |
*/ |
H |
728 |
|
|
729 |
- (BOOL)beginTransaction; |
|
730 |
|
|
731 |
/** Begin a deferred transaction |
|
732 |
|
09e73a
|
733 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
734 |
|
H |
735 |
@see commit |
|
736 |
@see rollback |
|
737 |
@see beginTransaction |
09e73a
|
738 |
@see isInTransaction |
6e1425
|
739 |
*/ |
H |
740 |
|
|
741 |
- (BOOL)beginDeferredTransaction; |
09e73a
|
742 |
|
L |
743 |
/** Begin an immediate transaction |
|
744 |
|
|
745 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
|
746 |
|
|
747 |
@see commit |
|
748 |
@see rollback |
|
749 |
@see beginTransaction |
|
750 |
@see isInTransaction |
|
751 |
*/ |
|
752 |
|
|
753 |
- (BOOL)beginImmediateTransaction; |
|
754 |
|
|
755 |
/** Begin an exclusive transaction |
|
756 |
|
|
757 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
|
758 |
|
|
759 |
@see commit |
|
760 |
@see rollback |
|
761 |
@see beginTransaction |
|
762 |
@see isInTransaction |
|
763 |
*/ |
|
764 |
|
|
765 |
- (BOOL)beginExclusiveTransaction; |
6e1425
|
766 |
|
H |
767 |
/** Commit a transaction |
|
768 |
|
|
769 |
Commit a transaction that was initiated with either `<beginTransaction>` or with `<beginDeferredTransaction>`. |
|
770 |
|
09e73a
|
771 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
772 |
|
H |
773 |
@see beginTransaction |
|
774 |
@see beginDeferredTransaction |
|
775 |
@see rollback |
09e73a
|
776 |
@see isInTransaction |
6e1425
|
777 |
*/ |
H |
778 |
|
|
779 |
- (BOOL)commit; |
|
780 |
|
|
781 |
/** Rollback a transaction |
|
782 |
|
|
783 |
Rollback a transaction that was initiated with either `<beginTransaction>` or with `<beginDeferredTransaction>`. |
|
784 |
|
09e73a
|
785 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
786 |
|
H |
787 |
@see beginTransaction |
|
788 |
@see beginDeferredTransaction |
|
789 |
@see commit |
09e73a
|
790 |
@see isInTransaction |
6e1425
|
791 |
*/ |
H |
792 |
|
|
793 |
- (BOOL)rollback; |
|
794 |
|
|
795 |
/** Identify whether currently in a transaction or not |
09e73a
|
796 |
|
6e1425
|
797 |
@see beginTransaction |
H |
798 |
@see beginDeferredTransaction |
|
799 |
@see commit |
|
800 |
@see rollback |
|
801 |
*/ |
|
802 |
|
09e73a
|
803 |
@property (nonatomic, readonly) BOOL isInTransaction; |
L |
804 |
|
|
805 |
- (BOOL)inTransaction __deprecated_msg("Use isInTransaction property instead"); |
6e1425
|
806 |
|
H |
807 |
|
|
808 |
///---------------------------------------- |
|
809 |
/// @name Cached statements and result sets |
|
810 |
///---------------------------------------- |
|
811 |
|
|
812 |
/** Clear cached statements */ |
|
813 |
|
|
814 |
- (void)clearCachedStatements; |
|
815 |
|
|
816 |
/** Close all open result sets */ |
|
817 |
|
|
818 |
- (void)closeOpenResultSets; |
|
819 |
|
|
820 |
/** Whether database has any open result sets |
|
821 |
|
09e73a
|
822 |
@return @c YES if there are open result sets; @c NO if not. |
6e1425
|
823 |
*/ |
H |
824 |
|
09e73a
|
825 |
@property (nonatomic, readonly) BOOL hasOpenResultSets; |
6e1425
|
826 |
|
09e73a
|
827 |
/** Whether should cache statements or not |
L |
828 |
*/ |
|
829 |
|
|
830 |
@property (nonatomic) BOOL shouldCacheStatements; |
|
831 |
|
|
832 |
/** Interupt pending database operation |
6e1425
|
833 |
|
09e73a
|
834 |
This method causes any pending database operation to abort and return at its earliest opportunity |
6e1425
|
835 |
|
09e73a
|
836 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
L |
837 |
|
6e1425
|
838 |
*/ |
H |
839 |
|
09e73a
|
840 |
- (BOOL)interrupt; |
6e1425
|
841 |
|
H |
842 |
///------------------------- |
|
843 |
/// @name Encryption methods |
|
844 |
///------------------------- |
|
845 |
|
|
846 |
/** Set encryption key. |
|
847 |
|
|
848 |
@param key The key to be used. |
|
849 |
|
09e73a
|
850 |
@return @c YES if success, @c NO on error. |
6e1425
|
851 |
|
H |
852 |
@see https://www.zetetic.net/sqlcipher/ |
|
853 |
|
|
854 |
@warning You need to have purchased the sqlite encryption extensions for this method to work. |
|
855 |
*/ |
|
856 |
|
|
857 |
- (BOOL)setKey:(NSString*)key; |
|
858 |
|
|
859 |
/** Reset encryption key |
|
860 |
|
|
861 |
@param key The key to be used. |
|
862 |
|
09e73a
|
863 |
@return @c YES if success, @c NO on error. |
6e1425
|
864 |
|
H |
865 |
@see https://www.zetetic.net/sqlcipher/ |
|
866 |
|
|
867 |
@warning You need to have purchased the sqlite encryption extensions for this method to work. |
|
868 |
*/ |
|
869 |
|
|
870 |
- (BOOL)rekey:(NSString*)key; |
|
871 |
|
|
872 |
/** Set encryption key using `keyData`. |
|
873 |
|
09e73a
|
874 |
@param keyData The @c NSData to be used. |
6e1425
|
875 |
|
09e73a
|
876 |
@return @c YES if success, @c NO on error. |
6e1425
|
877 |
|
H |
878 |
@see https://www.zetetic.net/sqlcipher/ |
|
879 |
|
|
880 |
@warning You need to have purchased the sqlite encryption extensions for this method to work. |
|
881 |
*/ |
|
882 |
|
|
883 |
- (BOOL)setKeyWithData:(NSData *)keyData; |
|
884 |
|
|
885 |
/** Reset encryption key using `keyData`. |
|
886 |
|
09e73a
|
887 |
@param keyData The @c NSData to be used. |
6e1425
|
888 |
|
09e73a
|
889 |
@return @c YES if success, @c NO on error. |
6e1425
|
890 |
|
H |
891 |
@see https://www.zetetic.net/sqlcipher/ |
|
892 |
|
|
893 |
@warning You need to have purchased the sqlite encryption extensions for this method to work. |
|
894 |
*/ |
|
895 |
|
|
896 |
- (BOOL)rekeyWithData:(NSData *)keyData; |
|
897 |
|
|
898 |
|
|
899 |
///------------------------------ |
|
900 |
/// @name General inquiry methods |
|
901 |
///------------------------------ |
|
902 |
|
09e73a
|
903 |
/** The path of the database file. |
6e1425
|
904 |
*/ |
H |
905 |
|
09e73a
|
906 |
@property (nonatomic, readonly, nullable) NSString *databasePath; |
6e1425
|
907 |
|
09e73a
|
908 |
/** The file URL of the database file. |
L |
909 |
*/ |
|
910 |
|
|
911 |
@property (nonatomic, readonly, nullable) NSURL *databaseURL; |
|
912 |
|
|
913 |
/** The underlying SQLite handle . |
6e1425
|
914 |
|
H |
915 |
@return The `sqlite3` pointer. |
|
916 |
|
|
917 |
*/ |
|
918 |
|
09e73a
|
919 |
@property (nonatomic, readonly) void *sqliteHandle; |
6e1425
|
920 |
|
H |
921 |
|
|
922 |
///----------------------------- |
|
923 |
/// @name Retrieving error codes |
|
924 |
///----------------------------- |
|
925 |
|
|
926 |
/** Last error message |
|
927 |
|
|
928 |
Returns the English-language text that describes the most recent failed SQLite API call associated with a database connection. If a prior API call failed but the most recent API call succeeded, this return value is undefined. |
|
929 |
|
09e73a
|
930 |
@return @c NSString of the last error message. |
6e1425
|
931 |
|
09e73a
|
932 |
@see [sqlite3_errmsg()](https://sqlite.org/c3ref/errcode.html) |
6e1425
|
933 |
@see lastErrorCode |
H |
934 |
@see lastError |
|
935 |
|
|
936 |
*/ |
|
937 |
|
|
938 |
- (NSString*)lastErrorMessage; |
|
939 |
|
|
940 |
/** Last error code |
|
941 |
|
|
942 |
Returns the numeric result code or extended result code for the most recent failed SQLite API call associated with a database connection. If a prior API call failed but the most recent API call succeeded, this return value is undefined. |
09e73a
|
943 |
|
6e1425
|
944 |
@return Integer value of the last error code. |
09e73a
|
945 |
|
L |
946 |
@see [sqlite3_errcode()](https://sqlite.org/c3ref/errcode.html) |
6e1425
|
947 |
@see lastErrorMessage |
H |
948 |
@see lastError |
09e73a
|
949 |
|
6e1425
|
950 |
*/ |
H |
951 |
|
|
952 |
- (int)lastErrorCode; |
|
953 |
|
09e73a
|
954 |
/** Last extended error code |
L |
955 |
|
|
956 |
Returns the numeric extended result code for the most recent failed SQLite API call associated with a database connection. If a prior API call failed but the most recent API call succeeded, this return value is undefined. |
|
957 |
|
|
958 |
@return Integer value of the last extended error code. |
|
959 |
|
|
960 |
@see [sqlite3_errcode()](https://sqlite.org/c3ref/errcode.html) |
|
961 |
@see [2. Primary Result Codes versus Extended Result Codes](https://sqlite.org/rescode.html#primary_result_codes_versus_extended_result_codes) |
|
962 |
@see [5. Extended Result Code List](https://sqlite.org/rescode.html#extrc) |
|
963 |
@see lastErrorMessage |
|
964 |
@see lastError |
|
965 |
|
|
966 |
*/ |
|
967 |
|
|
968 |
- (int)lastExtendedErrorCode; |
|
969 |
|
6e1425
|
970 |
/** Had error |
H |
971 |
|
09e73a
|
972 |
@return @c YES if there was an error, @c NO if no error. |
6e1425
|
973 |
|
H |
974 |
@see lastError |
|
975 |
@see lastErrorCode |
|
976 |
@see lastErrorMessage |
|
977 |
|
|
978 |
*/ |
|
979 |
|
|
980 |
- (BOOL)hadError; |
|
981 |
|
|
982 |
/** Last error |
|
983 |
|
09e73a
|
984 |
@return @c NSError representing the last error. |
6e1425
|
985 |
|
H |
986 |
@see lastErrorCode |
|
987 |
@see lastErrorMessage |
|
988 |
|
|
989 |
*/ |
|
990 |
|
09e73a
|
991 |
- (NSError *)lastError; |
6e1425
|
992 |
|
H |
993 |
|
|
994 |
// description forthcoming |
09e73a
|
995 |
@property (nonatomic) NSTimeInterval maxBusyRetryTimeInterval; |
6e1425
|
996 |
|
H |
997 |
|
|
998 |
///------------------ |
|
999 |
/// @name Save points |
|
1000 |
///------------------ |
|
1001 |
|
|
1002 |
/** Start save point |
|
1003 |
|
|
1004 |
@param name Name of save point. |
|
1005 |
|
09e73a
|
1006 |
@param outErr A @c NSError object to receive any error object (if any). |
6e1425
|
1007 |
|
09e73a
|
1008 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
1009 |
|
H |
1010 |
@see releaseSavePointWithName:error: |
|
1011 |
@see rollbackToSavePointWithName:error: |
|
1012 |
*/ |
|
1013 |
|
09e73a
|
1014 |
- (BOOL)startSavePointWithName:(NSString*)name error:(NSError * _Nullable __autoreleasing *)outErr; |
6e1425
|
1015 |
|
H |
1016 |
/** Release save point |
|
1017 |
|
|
1018 |
@param name Name of save point. |
|
1019 |
|
09e73a
|
1020 |
@param outErr A @c NSError object to receive any error object (if any). |
6e1425
|
1021 |
|
09e73a
|
1022 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
1023 |
|
H |
1024 |
@see startSavePointWithName:error: |
|
1025 |
@see rollbackToSavePointWithName:error: |
|
1026 |
|
|
1027 |
*/ |
|
1028 |
|
09e73a
|
1029 |
- (BOOL)releaseSavePointWithName:(NSString*)name error:(NSError * _Nullable __autoreleasing *)outErr; |
6e1425
|
1030 |
|
H |
1031 |
/** Roll back to save point |
|
1032 |
|
|
1033 |
@param name Name of save point. |
09e73a
|
1034 |
@param outErr A @c NSError object to receive any error object (if any). |
6e1425
|
1035 |
|
09e73a
|
1036 |
@return @c YES on success; @c NO on failure. If failed, you can call @c lastError , @c lastErrorCode , or @c lastErrorMessage for diagnostic information regarding the failure. |
6e1425
|
1037 |
|
H |
1038 |
@see startSavePointWithName:error: |
|
1039 |
@see releaseSavePointWithName:error: |
|
1040 |
|
|
1041 |
*/ |
|
1042 |
|
09e73a
|
1043 |
- (BOOL)rollbackToSavePointWithName:(NSString*)name error:(NSError * _Nullable __autoreleasing *)outErr; |
6e1425
|
1044 |
|
H |
1045 |
/** Start save point |
|
1046 |
|
|
1047 |
@param block Block of code to perform from within save point. |
|
1048 |
|
09e73a
|
1049 |
@return The NSError corresponding to the error, if any. If no error, returns @c nil . |
6e1425
|
1050 |
|
H |
1051 |
@see startSavePointWithName:error: |
|
1052 |
@see releaseSavePointWithName:error: |
|
1053 |
@see rollbackToSavePointWithName:error: |
|
1054 |
|
|
1055 |
*/ |
|
1056 |
|
09e73a
|
1057 |
- (NSError * _Nullable)inSavePoint:(__attribute__((noescape)) void (^)(BOOL *rollback))block; |
L |
1058 |
|
|
1059 |
|
|
1060 |
///----------------- |
|
1061 |
/// @name Checkpoint |
|
1062 |
///----------------- |
|
1063 |
|
|
1064 |
/** Performs a WAL checkpoint |
|
1065 |
|
|
1066 |
@param checkpointMode The checkpoint mode for @c sqlite3_wal_checkpoint_v2 |
|
1067 |
@param error The @c NSError corresponding to the error, if any. |
|
1068 |
@return @c YES on success, otherwise @c NO . |
|
1069 |
*/ |
|
1070 |
- (BOOL)checkpoint:(FMDBCheckpointMode)checkpointMode error:(NSError * _Nullable *)error; |
|
1071 |
|
|
1072 |
/** Performs a WAL checkpoint |
|
1073 |
|
|
1074 |
@param checkpointMode The checkpoint mode for @c sqlite3_wal_checkpoint_v2 |
|
1075 |
@param name The db name for @c sqlite3_wal_checkpoint_v2 |
|
1076 |
@param error The @c NSError corresponding to the error, if any. |
|
1077 |
@return @c YES on success, otherwise @c NO . |
|
1078 |
*/ |
|
1079 |
- (BOOL)checkpoint:(FMDBCheckpointMode)checkpointMode name:(NSString * _Nullable)name error:(NSError * _Nullable *)error; |
|
1080 |
|
|
1081 |
/** Performs a WAL checkpoint |
|
1082 |
|
|
1083 |
@param checkpointMode The checkpoint mode for sqlite3_wal_checkpoint_v2 |
|
1084 |
@param name The db name for sqlite3_wal_checkpoint_v2 |
|
1085 |
@param error The NSError corresponding to the error, if any. |
|
1086 |
@param logFrameCount If not @c NULL , then this is set to the total number of frames in the log file or to -1 if the checkpoint could not run because of an error or because the database is not in WAL mode. |
|
1087 |
@param checkpointCount If not @c NULL , then this is set to the total number of checkpointed frames in the log file (including any that were already checkpointed before the function was called) or to -1 if the checkpoint could not run due to an error or because the database is not in WAL mode. |
|
1088 |
@return @c YES on success, otherwise @c NO . |
|
1089 |
*/ |
|
1090 |
- (BOOL)checkpoint:(FMDBCheckpointMode)checkpointMode name:(NSString * _Nullable)name logFrameCount:(int * _Nullable)logFrameCount checkpointCount:(int * _Nullable)checkpointCount error:(NSError * _Nullable *)error; |
6e1425
|
1091 |
|
H |
1092 |
///---------------------------- |
|
1093 |
/// @name SQLite library status |
|
1094 |
///---------------------------- |
|
1095 |
|
|
1096 |
/** Test to see if the library is threadsafe |
|
1097 |
|
09e73a
|
1098 |
@return @c NO if and only if SQLite was compiled with mutexing code omitted due to the @c SQLITE_THREADSAFE compile-time option being set to 0. |
6e1425
|
1099 |
|
09e73a
|
1100 |
@see [sqlite3_threadsafe()](https://sqlite.org/c3ref/threadsafe.html) |
6e1425
|
1101 |
*/ |
H |
1102 |
|
|
1103 |
+ (BOOL)isSQLiteThreadSafe; |
09e73a
|
1104 |
|
L |
1105 |
/** Examine/set limits |
|
1106 |
|
|
1107 |
@param type The type of limit. See https://sqlite.org/c3ref/c_limit_attached.html |
|
1108 |
@param newLimit The new limit value. Use -1 if you don't want to change the limit, but rather only want to check it. |
|
1109 |
|
|
1110 |
@return Regardless, returns previous value. |
|
1111 |
|
|
1112 |
@see [sqlite3_limit()](https://sqlite.org/c3ref/limit.html) |
|
1113 |
*/ |
|
1114 |
|
|
1115 |
- (int)limitFor:(int)type value:(int)newLimit; |
6e1425
|
1116 |
|
H |
1117 |
/** Run-time library version numbers |
|
1118 |
|
|
1119 |
@return The sqlite library version string. |
|
1120 |
|
09e73a
|
1121 |
@see [sqlite3_libversion()](https://sqlite.org/c3ref/libversion.html) |
6e1425
|
1122 |
*/ |
H |
1123 |
|
|
1124 |
+ (NSString*)sqliteLibVersion; |
|
1125 |
|
09e73a
|
1126 |
/// The FMDB version number as a string in the form of @c "2.7.8" . |
L |
1127 |
/// |
|
1128 |
/// If you want to compare version number strings, you can use NSNumericSearch option: |
|
1129 |
/// |
|
1130 |
/// @code |
|
1131 |
/// NSComparisonResult result = [[FMDatabase FMDBUserVersion] compare:@"2.11.0" options:NSNumericSearch]; |
|
1132 |
/// @endcode |
|
1133 |
/// |
|
1134 |
/// @returns The version number string. |
6e1425
|
1135 |
|
H |
1136 |
+ (NSString*)FMDBUserVersion; |
|
1137 |
|
09e73a
|
1138 |
/** The FMDB version |
6e1425
|
1139 |
|
09e73a
|
1140 |
This returns the FMDB as hexadecimal value, e.g., @c 0x0243 for version 2.4.3. |
L |
1141 |
|
|
1142 |
@warning This routine will not work if any component of the version number exceeds 15. |
|
1143 |
For example, if it is version @c 2.17.3 , this will max out at @c 0x2f3. |
|
1144 |
For this reason, we would recommend using @c FMDBUserVersion and with @c NSNumericSearch option, e.g. |
|
1145 |
|
|
1146 |
@code |
|
1147 |
NSComparisonResult result = [[FMDatabase FMDBUserVersion] compare:@"2.11.0" options:NSNumericSearch]; |
|
1148 |
@endcode |
|
1149 |
|
|
1150 |
@returns The version number in hexadecimal, e.g., @c 0x0243 for version 2.4.3. If any component exceeds what can be |
|
1151 |
can be represented in four bits, we'll max it out at @c 0xf . |
|
1152 |
*/ |
|
1153 |
|
|
1154 |
+ (SInt32)FMDBVersion __deprecated_msg("Use FMDBUserVersion instead"); |
6e1425
|
1155 |
|
H |
1156 |
///------------------------ |
|
1157 |
/// @name Make SQL function |
|
1158 |
///------------------------ |
|
1159 |
|
|
1160 |
/** Adds SQL functions or aggregates or to redefine the behavior of existing SQL functions or aggregates. |
|
1161 |
|
|
1162 |
For example: |
|
1163 |
|
09e73a
|
1164 |
@code |
L |
1165 |
[db makeFunctionNamed:@"RemoveDiacritics" arguments:1 block:^(void *context, int argc, void **argv) { |
|
1166 |
SqliteValueType type = [self.db valueType:argv[0]]; |
|
1167 |
if (type == SqliteValueTypeNull) { |
|
1168 |
[self.db resultNullInContext:context]; |
|
1169 |
return; |
|
1170 |
} |
|
1171 |
if (type != SqliteValueTypeText) { |
|
1172 |
[self.db resultError:@"Expected text" context:context]; |
|
1173 |
return; |
|
1174 |
} |
|
1175 |
NSString *string = [self.db valueString:argv[0]]; |
|
1176 |
NSString *result = [string stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:nil]; |
|
1177 |
[self.db resultString:result context:context]; |
|
1178 |
}]; |
6e1425
|
1179 |
|
09e73a
|
1180 |
FMResultSet *rs = [db executeQuery:@"SELECT * FROM employees WHERE RemoveDiacritics(first_name) LIKE 'jose'"]; |
L |
1181 |
NSAssert(rs, @"Error %@", [db lastErrorMessage]); |
|
1182 |
@endcode |
6e1425
|
1183 |
|
09e73a
|
1184 |
@param name Name of function. |
6e1425
|
1185 |
|
09e73a
|
1186 |
@param arguments Maximum number of parameters. |
6e1425
|
1187 |
|
09e73a
|
1188 |
@param block The block of code for the function. |
6e1425
|
1189 |
|
09e73a
|
1190 |
@see [sqlite3_create_function()](https://sqlite.org/c3ref/create_function.html) |
6e1425
|
1191 |
*/ |
H |
1192 |
|
09e73a
|
1193 |
- (void)makeFunctionNamed:(NSString *)name arguments:(int)arguments block:(void (^)(void *context, int argc, void * _Nonnull * _Nonnull argv))block; |
6e1425
|
1194 |
|
09e73a
|
1195 |
- (void)makeFunctionNamed:(NSString *)name maximumArguments:(int)count withBlock:(void (^)(void *context, int argc, void * _Nonnull * _Nonnull argv))block __deprecated_msg("Use makeFunctionNamed:arguments:block:"); |
L |
1196 |
|
|
1197 |
- (SqliteValueType)valueType:(void *)argv; |
|
1198 |
|
|
1199 |
/** |
|
1200 |
Get integer value of parameter in custom function. |
|
1201 |
|
|
1202 |
@param value The argument whose value to return. |
|
1203 |
@return The integer value. |
|
1204 |
|
|
1205 |
@see makeFunctionNamed:arguments:block: |
|
1206 |
*/ |
|
1207 |
- (int)valueInt:(void *)value; |
|
1208 |
|
|
1209 |
/** |
|
1210 |
Get long value of parameter in custom function. |
|
1211 |
|
|
1212 |
@param value The argument whose value to return. |
|
1213 |
@return The long value. |
|
1214 |
|
|
1215 |
@see makeFunctionNamed:arguments:block: |
|
1216 |
*/ |
|
1217 |
- (long long)valueLong:(void *)value; |
|
1218 |
|
|
1219 |
/** |
|
1220 |
Get double value of parameter in custom function. |
|
1221 |
|
|
1222 |
@param value The argument whose value to return. |
|
1223 |
@return The double value. |
|
1224 |
|
|
1225 |
@see makeFunctionNamed:arguments:block: |
|
1226 |
*/ |
|
1227 |
- (double)valueDouble:(void *)value; |
|
1228 |
|
|
1229 |
/** |
|
1230 |
Get @c NSData value of parameter in custom function. |
|
1231 |
|
|
1232 |
@param value The argument whose value to return. |
|
1233 |
@return The data object. |
|
1234 |
|
|
1235 |
@see makeFunctionNamed:arguments:block: |
|
1236 |
*/ |
|
1237 |
- (NSData * _Nullable)valueData:(void *)value; |
|
1238 |
|
|
1239 |
/** |
|
1240 |
Get string value of parameter in custom function. |
|
1241 |
|
|
1242 |
@param value The argument whose value to return. |
|
1243 |
@return The string value. |
|
1244 |
|
|
1245 |
@see makeFunctionNamed:arguments:block: |
|
1246 |
*/ |
|
1247 |
- (NSString * _Nullable)valueString:(void *)value; |
|
1248 |
|
|
1249 |
/** |
|
1250 |
Return null value from custom function. |
|
1251 |
|
|
1252 |
@param context The context to which the null value will be returned. |
|
1253 |
|
|
1254 |
@see makeFunctionNamed:arguments:block: |
|
1255 |
*/ |
|
1256 |
- (void)resultNullInContext:(void *)context NS_SWIFT_NAME(resultNull(context:)); |
|
1257 |
|
|
1258 |
/** |
|
1259 |
Return integer value from custom function. |
|
1260 |
|
|
1261 |
@param value The integer value to be returned. |
|
1262 |
@param context The context to which the value will be returned. |
|
1263 |
|
|
1264 |
@see makeFunctionNamed:arguments:block: |
|
1265 |
*/ |
|
1266 |
- (void)resultInt:(int) value context:(void *)context; |
|
1267 |
|
|
1268 |
/** |
|
1269 |
Return long value from custom function. |
|
1270 |
|
|
1271 |
@param value The long value to be returned. |
|
1272 |
@param context The context to which the value will be returned. |
|
1273 |
|
|
1274 |
@see makeFunctionNamed:arguments:block: |
|
1275 |
*/ |
|
1276 |
- (void)resultLong:(long long)value context:(void *)context; |
|
1277 |
|
|
1278 |
/** |
|
1279 |
Return double value from custom function. |
|
1280 |
|
|
1281 |
@param value The double value to be returned. |
|
1282 |
@param context The context to which the value will be returned. |
|
1283 |
|
|
1284 |
@see makeFunctionNamed:arguments:block: |
|
1285 |
*/ |
|
1286 |
- (void)resultDouble:(double)value context:(void *)context; |
|
1287 |
|
|
1288 |
/** |
|
1289 |
Return @c NSData object from custom function. |
|
1290 |
|
|
1291 |
@param data The @c NSData object to be returned. |
|
1292 |
@param context The context to which the value will be returned. |
|
1293 |
|
|
1294 |
@see makeFunctionNamed:arguments:block: |
|
1295 |
*/ |
|
1296 |
- (void)resultData:(NSData *)data context:(void *)context; |
|
1297 |
|
|
1298 |
/** |
|
1299 |
Return string value from custom function. |
|
1300 |
|
|
1301 |
@param value The string value to be returned. |
|
1302 |
@param context The context to which the value will be returned. |
|
1303 |
|
|
1304 |
@see makeFunctionNamed:arguments:block: |
|
1305 |
*/ |
|
1306 |
- (void)resultString:(NSString *)value context:(void *)context; |
|
1307 |
|
|
1308 |
/** |
|
1309 |
Return error string from custom function. |
|
1310 |
|
|
1311 |
@param error The error string to be returned. |
|
1312 |
@param context The context to which the error will be returned. |
|
1313 |
|
|
1314 |
@see makeFunctionNamed:arguments:block: |
|
1315 |
*/ |
|
1316 |
- (void)resultError:(NSString *)error context:(void *)context; |
|
1317 |
|
|
1318 |
/** |
|
1319 |
Return error code from custom function. |
|
1320 |
|
|
1321 |
@param errorCode The integer error code to be returned. |
|
1322 |
@param context The context to which the error will be returned. |
|
1323 |
|
|
1324 |
@see makeFunctionNamed:arguments:block: |
|
1325 |
*/ |
|
1326 |
- (void)resultErrorCode:(int)errorCode context:(void *)context; |
|
1327 |
|
|
1328 |
/** |
|
1329 |
Report memory error in custom function. |
|
1330 |
|
|
1331 |
@param context The context to which the error will be returned. |
|
1332 |
|
|
1333 |
@see makeFunctionNamed:arguments:block: |
|
1334 |
*/ |
|
1335 |
- (void)resultErrorNoMemoryInContext:(void *)context NS_SWIFT_NAME(resultErrorNoMemory(context:)); |
|
1336 |
|
|
1337 |
/** |
|
1338 |
Report that string or BLOB is too long to represent in custom function. |
|
1339 |
|
|
1340 |
@param context The context to which the error will be returned. |
|
1341 |
|
|
1342 |
@see makeFunctionNamed:arguments:block: |
|
1343 |
*/ |
|
1344 |
- (void)resultErrorTooBigInContext:(void *)context NS_SWIFT_NAME(resultErrorTooBig(context:)); |
6e1425
|
1345 |
|
H |
1346 |
///--------------------- |
|
1347 |
/// @name Date formatter |
|
1348 |
///--------------------- |
|
1349 |
|
09e73a
|
1350 |
/** Generate an @c NSDateFormatter that won't be broken by permutations of timezones or locales. |
6e1425
|
1351 |
|
H |
1352 |
Use this method to generate values to set the dateFormat property. |
|
1353 |
|
|
1354 |
Example: |
|
1355 |
|
09e73a
|
1356 |
@code |
L |
1357 |
myDB.dateFormat = [FMDatabase storeableDateFormat:@"yyyy-MM-dd HH:mm:ss"]; |
|
1358 |
@endcode |
6e1425
|
1359 |
|
H |
1360 |
@param format A valid NSDateFormatter format string. |
|
1361 |
|
09e73a
|
1362 |
@return A @c NSDateFormatter that can be used for converting dates to strings and vice versa. |
6e1425
|
1363 |
|
H |
1364 |
@see hasDateFormatter |
|
1365 |
@see setDateFormat: |
|
1366 |
@see dateFromString: |
|
1367 |
@see stringFromDate: |
|
1368 |
@see storeableDateFormat: |
|
1369 |
|
09e73a
|
1370 |
@warning Note that @c NSDateFormatter is not thread-safe, so the formatter generated by this method should be assigned to only one FMDB instance and should not be used for other purposes. |
6e1425
|
1371 |
|
H |
1372 |
*/ |
|
1373 |
|
|
1374 |
+ (NSDateFormatter *)storeableDateFormat:(NSString *)format; |
|
1375 |
|
|
1376 |
/** Test whether the database has a date formatter assigned. |
|
1377 |
|
09e73a
|
1378 |
@return @c YES if there is a date formatter; @c NO if not. |
6e1425
|
1379 |
|
H |
1380 |
@see hasDateFormatter |
|
1381 |
@see setDateFormat: |
|
1382 |
@see dateFromString: |
|
1383 |
@see stringFromDate: |
|
1384 |
@see storeableDateFormat: |
|
1385 |
*/ |
|
1386 |
|
|
1387 |
- (BOOL)hasDateFormatter; |
|
1388 |
|
|
1389 |
/** Set to a date formatter to use string dates with sqlite instead of the default UNIX timestamps. |
|
1390 |
|
09e73a
|
1391 |
@param format Set to nil to use UNIX timestamps. Defaults to nil. Should be set using a formatter generated using @c FMDatabase:storeableDateFormat . |
6e1425
|
1392 |
|
H |
1393 |
@see hasDateFormatter |
|
1394 |
@see setDateFormat: |
|
1395 |
@see dateFromString: |
|
1396 |
@see stringFromDate: |
|
1397 |
@see storeableDateFormat: |
|
1398 |
|
09e73a
|
1399 |
@warning Note there is no direct getter for the @c NSDateFormatter , and you should not use the formatter you pass to FMDB for other purposes, as @c NSDateFormatter is not thread-safe. |
6e1425
|
1400 |
*/ |
H |
1401 |
|
09e73a
|
1402 |
- (void)setDateFormat:(NSDateFormatter * _Nullable)format; |
6e1425
|
1403 |
|
H |
1404 |
/** Convert the supplied NSString to NSDate, using the current database formatter. |
|
1405 |
|
09e73a
|
1406 |
@param s @c NSString to convert to @c NSDate . |
6e1425
|
1407 |
|
09e73a
|
1408 |
@return The @c NSDate object; or @c nil if no formatter is set. |
6e1425
|
1409 |
|
H |
1410 |
@see hasDateFormatter |
|
1411 |
@see setDateFormat: |
|
1412 |
@see dateFromString: |
|
1413 |
@see stringFromDate: |
|
1414 |
@see storeableDateFormat: |
|
1415 |
*/ |
|
1416 |
|
09e73a
|
1417 |
- (NSDate * _Nullable)dateFromString:(NSString *)s; |
6e1425
|
1418 |
|
H |
1419 |
/** Convert the supplied NSDate to NSString, using the current database formatter. |
|
1420 |
|
09e73a
|
1421 |
@param date @c NSDate of date to convert to @c NSString . |
6e1425
|
1422 |
|
09e73a
|
1423 |
@return The @c NSString representation of the date; @c nil if no formatter is set. |
6e1425
|
1424 |
|
H |
1425 |
@see hasDateFormatter |
|
1426 |
@see setDateFormat: |
|
1427 |
@see dateFromString: |
|
1428 |
@see stringFromDate: |
|
1429 |
@see storeableDateFormat: |
|
1430 |
*/ |
|
1431 |
|
09e73a
|
1432 |
- (NSString * _Nullable)stringFromDate:(NSDate *)date; |
6e1425
|
1433 |
|
H |
1434 |
@end |
|
1435 |
|
|
1436 |
|
09e73a
|
1437 |
/** Objective-C wrapper for @c sqlite3_stmt |
6e1425
|
1438 |
|
09e73a
|
1439 |
This is a wrapper for a SQLite @c sqlite3_stmt . Generally when using FMDB you will not need to interact directly with `FMStatement`, but rather with @c FMDatabase and @c FMResultSet only. |
6e1425
|
1440 |
|
09e73a
|
1441 |
See also |
6e1425
|
1442 |
|
09e73a
|
1443 |
- @c FMDatabase |
L |
1444 |
- @c FMResultSet |
|
1445 |
- [@c sqlite3_stmt ](https://sqlite.org/c3ref/stmt.html) |
6e1425
|
1446 |
*/ |
H |
1447 |
|
|
1448 |
@interface FMStatement : NSObject { |
|
1449 |
void *_statement; |
|
1450 |
NSString *_query; |
|
1451 |
long _useCount; |
|
1452 |
BOOL _inUse; |
|
1453 |
} |
|
1454 |
|
|
1455 |
///----------------- |
|
1456 |
/// @name Properties |
|
1457 |
///----------------- |
|
1458 |
|
|
1459 |
/** Usage count */ |
|
1460 |
|
|
1461 |
@property (atomic, assign) long useCount; |
|
1462 |
|
|
1463 |
/** SQL statement */ |
|
1464 |
|
|
1465 |
@property (atomic, retain) NSString *query; |
|
1466 |
|
|
1467 |
/** SQLite sqlite3_stmt |
|
1468 |
|
09e73a
|
1469 |
@see [@c sqlite3_stmt ](https://sqlite.org/c3ref/stmt.html) |
6e1425
|
1470 |
*/ |
H |
1471 |
|
|
1472 |
@property (atomic, assign) void *statement; |
|
1473 |
|
|
1474 |
/** Indication of whether the statement is in use */ |
|
1475 |
|
|
1476 |
@property (atomic, assign) BOOL inUse; |
|
1477 |
|
|
1478 |
///---------------------------- |
|
1479 |
/// @name Closing and Resetting |
|
1480 |
///---------------------------- |
|
1481 |
|
|
1482 |
/** Close statement */ |
|
1483 |
|
|
1484 |
- (void)close; |
|
1485 |
|
|
1486 |
/** Reset statement */ |
|
1487 |
|
|
1488 |
- (void)reset; |
|
1489 |
|
|
1490 |
@end |
|
1491 |
|
|
1492 |
#pragma clang diagnostic pop |
|
1493 |
|
09e73a
|
1494 |
NS_ASSUME_NONNULL_END |