defined configuration for build variants

This commit is contained in:
Semyon Babushkin
2017-10-23 20:25:04 +03:00
parent b6b5acd823
commit b6ba66a283
38 changed files with 2563 additions and 1424 deletions

View File

@@ -2,7 +2,6 @@
#import "FMResultSet.h"
#import "FMDatabasePool.h"
NS_ASSUME_NONNULL_BEGIN
#if ! __has_feature(objc_arc)
#define FMDBAutorelease(__v) ([__v autorelease]);
@@ -71,7 +70,26 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
#pragma clang diagnostic ignored "-Wobjc-interface-ivars"
@interface FMDatabase : NSObject
@interface FMDatabase : NSObject {
void* _db;
NSString* _databasePath;
BOOL _logsErrors;
BOOL _crashOnErrors;
BOOL _traceExecution;
BOOL _checkedOut;
BOOL _shouldCacheStatements;
BOOL _isExecutingStatement;
BOOL _inTransaction;
NSTimeInterval _maxBusyRetryTimeInterval;
NSTimeInterval _startBusyRetryTime;
NSMutableDictionary *_cachedStatements;
NSMutableSet *_openResultSets;
NSMutableSet *_openFunctions;
NSDateFormatter *_dateFormat;
}
///-----------------
/// @name Properties
@@ -95,7 +113,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
/** Dictionary of cached statements */
@property (atomic, retain, nullable) NSMutableDictionary *cachedStatements;
@property (atomic, retain) NSMutableDictionary *cachedStatements;
///---------------------
/// @name Initialization
@@ -127,34 +145,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
+ (instancetype)databaseWithPath:(NSString * _Nullable)inPath;
/** Create a `FMDatabase` object.
An `FMDatabase` is created with a path to a SQLite database file. This path can be one of these three:
1. A file system URL. The file does not have to exist on disk. If it does not exist, it is created for you.
2. `nil`. An in-memory database is created. This database will be destroyed with the `FMDatabase` connection is closed.
For example, to create/open a database in your Mac OS X `tmp` folder:
FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
Or, in iOS, you might open a database in the app's `Documents` directory:
NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *dbPath = [docsPath stringByAppendingPathComponent:@"test.db"];
FMDatabase *db = [FMDatabase databaseWithPath:dbPath];
(For more information on temporary and in-memory databases, read the sqlite documentation on the subject: [http://www.sqlite.org/inmemorydb.html](http://www.sqlite.org/inmemorydb.html))
@param url The local file URL (not remote URL) of database file
@return `FMDatabase` object if successful; `nil` if failure.
*/
+ (instancetype)databaseWithURL:(NSURL * _Nullable)url;
+ (instancetype)databaseWithPath:(NSString*)inPath;
/** Initialize a `FMDatabase` object.
@@ -176,40 +167,14 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
(For more information on temporary and in-memory databases, read the sqlite documentation on the subject: [http://www.sqlite.org/inmemorydb.html](http://www.sqlite.org/inmemorydb.html))
@param path Path of database file.
@param inPath Path of database file
@return `FMDatabase` object if successful; `nil` if failure.
*/
- (instancetype)initWithPath:(NSString * _Nullable)path;
- (instancetype)initWithPath:(NSString*)inPath;
/** Initialize a `FMDatabase` object.
An `FMDatabase` is created with a local file URL to a SQLite database file. This path can be one of these three:
1. A file system URL. The file does not have to exist on disk. If it does not exist, it is created for you.
2. `nil`. An in-memory database is created. This database will be destroyed with the `FMDatabase` connection is closed.
For example, to create/open a database in your Mac OS X `tmp` folder:
FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
Or, in iOS, you might open a database in the app's `Documents` directory:
NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *dbPath = [docsPath stringByAppendingPathComponent:@"test.db"];
FMDatabase *db = [FMDatabase databaseWithPath:dbPath];
(For more information on temporary and in-memory databases, read the sqlite documentation on the subject: [http://www.sqlite.org/inmemorydb.html](http://www.sqlite.org/inmemorydb.html))
@param url The file `NSURL` of database file.
@return `FMDatabase` object if successful; `nil` if failure.
*/
- (instancetype)initWithURL:(NSURL * _Nullable)url;
///-----------------------------------
/// @name Opening and closing database
@@ -278,7 +243,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see close
*/
- (BOOL)openWithFlags:(int)flags vfs:(NSString * _Nullable)vfsName;
- (BOOL)openWithFlags:(int)flags vfs:(NSString *)vfsName;
/** Closing a database connection
@@ -301,7 +266,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@return `YES` if everything succeeds, `NO` on failure.
*/
@property (nonatomic, readonly) BOOL goodConnection;
- (BOOL)goodConnection;
///----------------------
@@ -328,7 +293,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see [`sqlite3_bind`](http://sqlite.org/c3ref/bind_blob.html)
*/
- (BOOL)executeUpdate:(NSString*)sql withErrorAndBindings:(NSError * _Nullable *)outErr, ...;
- (BOOL)executeUpdate:(NSString*)sql withErrorAndBindings:(NSError**)outErr, ...;
/** Execute single update statement
@@ -337,7 +302,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@warning **Deprecated**: Please use `<executeUpdate:withErrorAndBindings>` instead.
*/
- (BOOL)update:(NSString*)sql withErrorAndBindings:(NSError * _Nullable*)outErr, ... __deprecated_msg("Use executeUpdate:withErrorAndBindings: instead");;
- (BOOL)update:(NSString*)sql withErrorAndBindings:(NSError**)outErr, ... __attribute__ ((deprecated));
/** Execute single update statement
@@ -358,7 +323,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@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 `stringWithFormat` to manually build SQL statements, which can be problematic if the values happened to include any characters that needed to be quoted.
@note You cannot use this method from Swift due to incompatibilities between Swift and Objective-C variadic implementations. Consider using `<executeUpdate:values:>` instead.
@note If you want to use this from Swift, please note that you must include `FMDatabaseVariadic.swift` in your project. Without that, you cannot use this method directly, and instead have to use methods such as `<executeUpdate:withArgumentsInArray:>`.
*/
- (BOOL)executeUpdate:(NSString*)sql, ...;
@@ -419,9 +384,9 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
This is similar to `<executeUpdate:withArgumentsInArray:>`, except that this also accepts a pointer to a `NSError` pointer, so that errors can be returned.
In Swift, this throws errors, as if it were defined as follows:
In Swift 2, this throws errors, as if it were defined as follows:
`func executeUpdate(sql: String, values: [Any]?) throws -> Bool`
`func executeUpdate(sql: String!, values: [AnyObject]!) throws -> Bool`
@param sql The SQL to be performed, with optional `?` placeholders.
@@ -437,7 +402,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
- (BOOL)executeUpdate:(NSString*)sql values:(NSArray * _Nullable)values error:(NSError * _Nullable __autoreleasing *)error;
- (BOOL)executeUpdate:(NSString*)sql values:(NSArray *)values error:(NSError * __autoreleasing *)error;
/** Execute single update statement
@@ -511,7 +476,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
- (BOOL)executeStatements:(NSString *)sql withResultBlock:(__attribute__((noescape)) FMDBExecuteStatementsCallbackBlock _Nullable)block;
- (BOOL)executeStatements:(NSString *)sql withResultBlock:(FMDBExecuteStatementsCallbackBlock)block;
/** Last insert rowid
@@ -525,7 +490,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
@property (nonatomic, readonly) int64_t lastInsertRowId;
- (int64_t)lastInsertRowId;
/** The number of rows changed by prior SQL statement.
@@ -537,7 +502,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
@property (nonatomic, readonly) int changes;
- (int)changes;
///-------------------------
@@ -562,10 +527,10 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see [`FMResultSet next`](<[FMResultSet next]>)
@see [`sqlite3_bind`](http://sqlite.org/c3ref/bind_blob.html)
@note You cannot use this method from Swift due to incompatibilities between Swift and Objective-C variadic implementations. Consider using `<executeQuery:values:>` instead.
@note If you want to use this from Swift, please note that you must include `FMDatabaseVariadic.swift` in your project. Without that, you cannot use this method directly, and instead have to use methods such as `<executeQuery:withArgumentsInArray:>`.
*/
- (FMResultSet * _Nullable)executeQuery:(NSString*)sql, ...;
- (FMResultSet *)executeQuery:(NSString*)sql, ...;
/** Execute select statement
@@ -595,7 +560,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
- (FMResultSet * _Nullable)executeQueryWithFormat:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
- (FMResultSet *)executeQueryWithFormat:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
/** Execute select statement
@@ -614,7 +579,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see [`FMResultSet next`](<[FMResultSet next]>)
*/
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments;
- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments;
/** Execute select statement
@@ -624,9 +589,9 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
This is similar to `<executeQuery:withArgumentsInArray:>`, except that this also accepts a pointer to a `NSError` pointer, so that errors can be returned.
In Swift, this throws errors, as if it were defined as follows:
In Swift 2, this throws errors, as if it were defined as follows:
`func executeQuery(sql: String, values: [Any]?) throws -> FMResultSet!`
`func executeQuery(sql: String!, values: [AnyObject]!) throws -> FMResultSet!`
@param sql The SELECT statement to be performed, with optional `?` placeholders.
@@ -643,7 +608,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql values:(NSArray * _Nullable)values error:(NSError * _Nullable __autoreleasing *)error;
- (FMResultSet *)executeQuery:(NSString *)sql values:(NSArray *)values error:(NSError * __autoreleasing *)error;
/** Execute select statement
@@ -661,11 +626,11 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see [`FMResultSet next`](<[FMResultSet next]>)
*/
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql withParameterDictionary:(NSDictionary * _Nullable)arguments;
- (FMResultSet *)executeQuery:(NSString *)sql withParameterDictionary:(NSDictionary *)arguments;
// Documentation forthcoming.
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql withVAList:(va_list)args;
- (FMResultSet *)executeQuery:(NSString*)sql withVAList: (va_list)args;
///-------------------
/// @name Transactions
@@ -678,7 +643,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see commit
@see rollback
@see beginDeferredTransaction
@see isInTransaction
@see inTransaction
*/
- (BOOL)beginTransaction;
@@ -690,7 +655,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see commit
@see rollback
@see beginTransaction
@see isInTransaction
@see inTransaction
*/
- (BOOL)beginDeferredTransaction;
@@ -704,7 +669,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see beginTransaction
@see beginDeferredTransaction
@see rollback
@see isInTransaction
@see inTransaction
*/
- (BOOL)commit;
@@ -718,22 +683,22 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see beginTransaction
@see beginDeferredTransaction
@see commit
@see isInTransaction
@see inTransaction
*/
- (BOOL)rollback;
/** Identify whether currently in a transaction or not
@return `YES` if currently within transaction; `NO` if not.
@see beginTransaction
@see beginDeferredTransaction
@see commit
@see rollback
*/
@property (nonatomic, readonly) BOOL isInTransaction;
- (BOOL)inTransaction __deprecated_msg("Use isInTransaction property instead");
- (BOOL)inTransaction;
///----------------------------------------
@@ -753,22 +718,22 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@return `YES` if there are open result sets; `NO` if not.
*/
@property (nonatomic, readonly) BOOL hasOpenResultSets;
- (BOOL)hasOpenResultSets;
/** Whether should cache statements or not
*/
@property (nonatomic) BOOL shouldCacheStatements;
/** Interupt pending database operation
This method causes any pending database operation to abort and return at its earliest opportunity
@return `YES` on success; `NO` on failure. If failed, you can call `<lastError>`, `<lastErrorCode>`, or `<lastErrorMessage>` for diagnostic information regarding the failure.
/** Return whether should cache statements or not
@return `YES` if should cache statements; `NO` if not.
*/
- (BOOL)interrupt;
- (BOOL)shouldCacheStatements;
/** Set whether should cache statements or not
@param value `YES` if should cache statements; `NO` if not.
*/
- (void)setShouldCacheStatements:(BOOL)value;
///-------------------------
/// @name Encryption methods
@@ -832,14 +797,12 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
///------------------------------
/** The path of the database file
@return path of database.
*/
@property (nonatomic, readonly, nullable) NSString *databasePath;
/** The file URL of the database file.
*/
@property (nonatomic, readonly, nullable) NSURL *databaseURL;
- (NSString *)databasePath;
/** The underlying SQLite handle
@@ -847,7 +810,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
@property (nonatomic, readonly) void *sqliteHandle;
- (void*)sqliteHandle;
///-----------------------------
@@ -871,33 +834,17 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
/** Last error code
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.
@return Integer value of the last error code.
@see [sqlite3_errcode()](http://sqlite.org/c3ref/errcode.html)
@see lastErrorMessage
@see lastError
*/
- (int)lastErrorCode;
/** Last extended error code
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.
@return Integer value of the last extended error code.
@see [sqlite3_errcode()](http://sqlite.org/c3ref/errcode.html)
@see [2. Primary Result Codes versus Extended Result Codes](http://sqlite.org/rescode.html#primary_result_codes_versus_extended_result_codes)
@see [5. Extended Result Code List](http://sqlite.org/rescode.html#extrc)
@see lastErrorMessage
@see lastError
*/
- (int)lastExtendedErrorCode;
/** Had error
@return `YES` if there was an error, `NO` if no error.
@@ -919,11 +866,12 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
- (NSError *)lastError;
- (NSError*)lastError;
// description forthcoming
@property (nonatomic) NSTimeInterval maxBusyRetryTimeInterval;
- (void)setMaxBusyRetryTimeInterval:(NSTimeInterval)timeoutInSeconds;
- (NSTimeInterval)maxBusyRetryTimeInterval;
///------------------
@@ -942,7 +890,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
@see rollbackToSavePointWithName:error:
*/
- (BOOL)startSavePointWithName:(NSString*)name error:(NSError * _Nullable *)outErr;
- (BOOL)startSavePointWithName:(NSString*)name error:(NSError**)outErr;
/** Release save point
@@ -957,7 +905,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
- (BOOL)releaseSavePointWithName:(NSString*)name error:(NSError * _Nullable *)outErr;
- (BOOL)releaseSavePointWithName:(NSString*)name error:(NSError**)outErr;
/** Roll back to save point
@@ -971,7 +919,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
- (BOOL)rollbackToSavePointWithName:(NSString*)name error:(NSError * _Nullable *)outErr;
- (BOOL)rollbackToSavePointWithName:(NSString*)name error:(NSError**)outErr;
/** Start save point
@@ -985,7 +933,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
*/
- (NSError * _Nullable)inSavePoint:(__attribute__((noescape)) void (^)(BOOL *rollback))block;
- (NSError*)inSavePoint:(void (^)(BOOL *rollback))block;
///----------------------------
/// @name SQLite library status
@@ -1023,193 +971,48 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
For example:
[db makeFunctionNamed:@"RemoveDiacritics" arguments:1 block:^(void *context, int argc, void **argv) {
SqliteValueType type = [self.db valueType:argv[0]];
if (type == SqliteValueTypeNull) {
[self.db resultNullInContext:context];
return;
[queue inDatabase:^(FMDatabase *adb) {
[adb executeUpdate:@"create table ftest (foo text)"];
[adb executeUpdate:@"insert into ftest values ('hello')"];
[adb executeUpdate:@"insert into ftest values ('hi')"];
[adb executeUpdate:@"insert into ftest values ('not h!')"];
[adb executeUpdate:@"insert into ftest values ('definitely not h!')"];
[adb makeFunctionNamed:@"StringStartsWithH" maximumArguments:1 withBlock:^(sqlite3_context *context, int aargc, sqlite3_value **aargv) {
if (sqlite3_value_type(aargv[0]) == SQLITE_TEXT) {
@autoreleasepool {
const char *c = (const char *)sqlite3_value_text(aargv[0]);
NSString *s = [NSString stringWithUTF8String:c];
sqlite3_result_int(context, [s hasPrefix:@"h"]);
}
}
else {
NSLog(@"Unknown formart for StringStartsWithH (%d) %s:%d", sqlite3_value_type(aargv[0]), __FUNCTION__, __LINE__);
sqlite3_result_null(context);
}
}];
int rowCount = 0;
FMResultSet *ars = [adb executeQuery:@"select * from ftest where StringStartsWithH(foo)"];
while ([ars next]) {
rowCount++;
NSLog(@"Does %@ start with 'h'?", [rs stringForColumnIndex:0]);
}
if (type != SqliteValueTypeText) {
[self.db resultError:@"Expected text" context:context];
return;
}
NSString *string = [self.db valueString:argv[0]];
NSString *result = [string stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:nil];
[self.db resultString:result context:context];
FMDBQuickCheck(rowCount == 2);
}];
FMResultSet *rs = [db executeQuery:@"SELECT * FROM employees WHERE RemoveDiacritics(first_name) LIKE 'jose'"];
NSAssert(rs, @"Error %@", [db lastErrorMessage]);
@param name Name of function.
@param name Name of function
@param arguments Maximum number of parameters.
@param count Maximum number of parameters
@param block The block of code for the function.
@param block The block of code for the function
@see [sqlite3_create_function()](http://sqlite.org/c3ref/create_function.html)
*/
- (void)makeFunctionNamed:(NSString *)name arguments:(int)arguments block:(void (^)(void *context, int argc, void * _Nonnull * _Nonnull argv))block;
- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(void *context, int argc, void **argv))block;
- (void)makeFunctionNamed:(NSString *)name maximumArguments:(int)count withBlock:(void (^)(void *context, int argc, void * _Nonnull * _Nonnull argv))block __deprecated_msg("Use makeFunctionNamed:arguments:block:");
typedef NS_ENUM(int, SqliteValueType) {
SqliteValueTypeInteger = 1,
SqliteValueTypeFloat = 2,
SqliteValueTypeText = 3,
SqliteValueTypeBlob = 4,
SqliteValueTypeNull = 5
};
- (SqliteValueType)valueType:(void *)argv;
/**
Get integer value of parameter in custom function.
@param value The argument whose value to return.
@return The integer value.
@see makeFunctionNamed:arguments:block:
*/
- (int)valueInt:(void *)value;
/**
Get long value of parameter in custom function.
@param value The argument whose value to return.
@return The long value.
@see makeFunctionNamed:arguments:block:
*/
- (long long)valueLong:(void *)value;
/**
Get double value of parameter in custom function.
@param value The argument whose value to return.
@return The double value.
@see makeFunctionNamed:arguments:block:
*/
- (double)valueDouble:(void *)value;
/**
Get `NSData` value of parameter in custom function.
@param value The argument whose value to return.
@return The data object.
@see makeFunctionNamed:arguments:block:
*/
- (NSData * _Nullable)valueData:(void *)value;
/**
Get string value of parameter in custom function.
@param value The argument whose value to return.
@return The string value.
@see makeFunctionNamed:arguments:block:
*/
- (NSString * _Nullable)valueString:(void *)value;
/**
Return null value from custom function.
@param context The context to which the null value will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultNullInContext:(void *)context NS_SWIFT_NAME(resultNull(context:));
/**
Return integer value from custom function.
@param value The integer value to be returned.
@param context The context to which the value will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultInt:(int) value context:(void *)context;
/**
Return long value from custom function.
@param value The long value to be returned.
@param context The context to which the value will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultLong:(long long)value context:(void *)context;
/**
Return double value from custom function.
@param value The double value to be returned.
@param context The context to which the value will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultDouble:(double)value context:(void *)context;
/**
Return `NSData` object from custom function.
@param data The `NSData` object to be returned.
@param context The context to which the value will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultData:(NSData *)data context:(void *)context;
/**
Return string value from custom function.
@param value The string value to be returned.
@param context The context to which the value will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultString:(NSString *)value context:(void *)context;
/**
Return error string from custom function.
@param error The error string to be returned.
@param context The context to which the error will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultError:(NSString *)error context:(void *)context;
/**
Return error code from custom function.
@param errorCode The integer error code to be returned.
@param context The context to which the error will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultErrorCode:(int)errorCode context:(void *)context;
/**
Report memory error in custom function.
@param context The context to which the error will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultErrorNoMemoryInContext:(void *)context NS_SWIFT_NAME(resultErrorNoMemory(context:));
/**
Report that string or BLOB is too long to represent in custom function.
@param context The context to which the error will be returned.
@see makeFunctionNamed:arguments:block:
*/
- (void)resultErrorTooBigInContext:(void *)context NS_SWIFT_NAME(resultErrorTooBig(context:));
///---------------------
/// @name Date formatter
@@ -1280,7 +1083,7 @@ typedef NS_ENUM(int, SqliteValueType) {
@see storeableDateFormat:
*/
- (NSDate * _Nullable)dateFromString:(NSString *)s;
- (NSDate *)dateFromString:(NSString *)s;
/** Convert the supplied NSDate to NSString, using the current database formatter.
@@ -1357,4 +1160,3 @@ typedef NS_ENUM(int, SqliteValueType) {
#pragma clang diagnostic pop
NS_ASSUME_NONNULL_END

View File

@@ -8,61 +8,38 @@
#import <sqlite3.h>
#endif
@interface FMDatabase () {
void* _db;
BOOL _isExecutingStatement;
NSTimeInterval _startBusyRetryTime;
NSMutableSet *_openResultSets;
NSMutableSet *_openFunctions;
NSDateFormatter *_dateFormat;
}
@interface FMDatabase ()
NS_ASSUME_NONNULL_BEGIN
- (FMResultSet * _Nullable)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray * _Nullable)arrayArgs orDictionary:(NSDictionary * _Nullable)dictionaryArgs orVAList:(va_list)args;
- (BOOL)executeUpdate:(NSString *)sql error:(NSError * _Nullable *)outErr withArgumentsInArray:(NSArray * _Nullable)arrayArgs orDictionary:(NSDictionary * _Nullable)dictionaryArgs orVAList:(va_list)args;
NS_ASSUME_NONNULL_END
- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
- (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
@end
@implementation FMDatabase
// Because these two properties have all of their accessor methods implemented,
// we have to synthesize them to get the corresponding ivars. The rest of the
// properties have their ivars synthesized automatically for us.
@synthesize shouldCacheStatements = _shouldCacheStatements;
@synthesize maxBusyRetryTimeInterval = _maxBusyRetryTimeInterval;
@synthesize cachedStatements=_cachedStatements;
@synthesize logsErrors=_logsErrors;
@synthesize crashOnErrors=_crashOnErrors;
@synthesize checkedOut=_checkedOut;
@synthesize traceExecution=_traceExecution;
#pragma mark FMDatabase instantiation and deallocation
+ (instancetype)databaseWithPath:(NSString *)aPath {
+ (instancetype)databaseWithPath:(NSString*)aPath {
return FMDBReturnAutoreleased([[self alloc] initWithPath:aPath]);
}
+ (instancetype)databaseWithURL:(NSURL *)url {
return FMDBReturnAutoreleased([[self alloc] initWithURL:url]);
}
- (instancetype)init {
return [self initWithPath:nil];
}
- (instancetype)initWithURL:(NSURL *)url {
return [self initWithPath:url.path];
}
- (instancetype)initWithPath:(NSString *)path {
- (instancetype)initWithPath:(NSString*)aPath {
assert(sqlite3_threadsafe()); // whoa there big boy- gotta make sure sqlite it happy with what we're going to do.
self = [super init];
if (self) {
_databasePath = [path copy];
_databasePath = [aPath copy];
_openResultSets = [[NSMutableSet alloc] init];
_db = nil;
_logsErrors = YES;
@@ -73,12 +50,10 @@ NS_ASSUME_NONNULL_END
return self;
}
#if ! __has_feature(objc_arc)
- (void)finalize {
[self close];
[super finalize];
}
#endif
- (void)dealloc {
[self close];
@@ -93,12 +68,12 @@ NS_ASSUME_NONNULL_END
#endif
}
- (NSURL *)databaseURL {
return _databasePath ? [NSURL fileURLWithPath:_databasePath] : nil;
- (NSString *)databasePath {
return _databasePath;
}
+ (NSString*)FMDBUserVersion {
return @"2.7.2";
return @"2.6.2";
}
// returns 0x0240 for version 2.4. This makes it super easy to do things like:
@@ -346,9 +321,7 @@ static int FMDBDatabaseBusyHandler(void *f, int count) {
- (void)clearCachedStatements {
for (NSMutableSet *statements in [_cachedStatements objectEnumerator]) {
for (FMStatement *statement in [statements allObjects]) {
[statement close];
}
[statements makeObjectsPerformSelector:@selector(close)];
}
[_cachedStatements removeAllObjects];
@@ -512,7 +485,7 @@ static int FMDBDatabaseBusyHandler(void *f, int count) {
#pragma mark Error routines
- (NSString *)lastErrorMessage {
- (NSString*)lastErrorMessage {
return [NSString stringWithUTF8String:sqlite3_errmsg(_db)];
}
@@ -526,11 +499,7 @@ static int FMDBDatabaseBusyHandler(void *f, int count) {
return sqlite3_errcode(_db);
}
- (int)lastExtendedErrorCode {
return sqlite3_extended_errcode(_db);
}
- (NSError*)errorWithMessage:(NSString *)message {
- (NSError*)errorWithMessage:(NSString*)message {
NSDictionary* errorMessage = [NSDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];
return [NSError errorWithDomain:@"FMDatabase" code:sqlite3_errcode(_db) userInfo:errorMessage];
@@ -1106,12 +1075,6 @@ static int FMDBDatabaseBusyHandler(void *f, int count) {
if (SQLITE_DONE == rc) {
// all is well, let's return.
}
else if (SQLITE_INTERRUPT == rc) {
if (_logsErrors) {
NSLog(@"Error calling sqlite3_step. Query was interrupted (%d: %s) SQLITE_INTERRUPT", rc, sqlite3_errmsg(_db));
NSLog(@"DB Query: %@", sql);
}
}
else if (rc == SQLITE_ROW) {
NSString *message = [NSString stringWithFormat:@"A executeUpdate is being called with a query string '%@'", sql];
if (_logsErrors) {
@@ -1296,7 +1259,7 @@ int FMDBExecuteBulkSQLCallback(void *theBlockAsVoid, int columns, char **values,
BOOL b = [self executeUpdate:@"rollback transaction"];
if (b) {
_isInTransaction = NO;
_inTransaction = NO;
}
return b;
@@ -1306,7 +1269,7 @@ int FMDBExecuteBulkSQLCallback(void *theBlockAsVoid, int columns, char **values,
BOOL b = [self executeUpdate:@"commit transaction"];
if (b) {
_isInTransaction = NO;
_inTransaction = NO;
}
return b;
@@ -1316,7 +1279,7 @@ int FMDBExecuteBulkSQLCallback(void *theBlockAsVoid, int columns, char **values,
BOOL b = [self executeUpdate:@"begin deferred transaction"];
if (b) {
_isInTransaction = YES;
_inTransaction = YES;
}
return b;
@@ -1326,23 +1289,14 @@ int FMDBExecuteBulkSQLCallback(void *theBlockAsVoid, int columns, char **values,
BOOL b = [self executeUpdate:@"begin exclusive transaction"];
if (b) {
_isInTransaction = YES;
_inTransaction = YES;
}
return b;
}
- (BOOL)inTransaction {
return _isInTransaction;
}
- (BOOL)interrupt
{
if (_db) {
sqlite3_interrupt([self sqliteHandle]);
return YES;
}
return NO;
return _inTransaction;
}
static NSString *FMDBEscapeSavePointName(NSString *savepointName) {
@@ -1453,19 +1407,12 @@ void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3
void (^block)(sqlite3_context *context, int argc, sqlite3_value **argv) = (__bridge id)sqlite3_user_data(context);
#endif
if (block) {
@autoreleasepool {
block(context, argc, argv);
}
block(context, argc, argv);
}
}
// deprecated because "arguments" parameter is not maximum argument count, but actual argument count.
- (void)makeFunctionNamed:(NSString *)name maximumArguments:(int)arguments withBlock:(void (^)(void *context, int argc, void **argv))block {
[self makeFunctionNamed:name arguments:arguments block:block];
}
- (void)makeFunctionNamed:(NSString *)name arguments:(int)arguments block:(void (^)(void *context, int argc, void **argv))block {
- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(void *context, int argc, void **argv))block {
if (!_openFunctions) {
_openFunctions = [NSMutableSet new];
@@ -1477,91 +1424,26 @@ void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3
/* I tried adding custom functions to release the block when the connection is destroyed- but they seemed to never be called, so we use _openFunctions to store the values instead. */
#if ! __has_feature(objc_arc)
sqlite3_create_function([self sqliteHandle], [name UTF8String], arguments, SQLITE_UTF8, (void*)b, &FMDBBlockSQLiteCallBackFunction, 0x00, 0x00);
sqlite3_create_function([self sqliteHandle], [name UTF8String], count, SQLITE_UTF8, (void*)b, &FMDBBlockSQLiteCallBackFunction, 0x00, 0x00);
#else
sqlite3_create_function([self sqliteHandle], [name UTF8String], arguments, SQLITE_UTF8, (__bridge void*)b, &FMDBBlockSQLiteCallBackFunction, 0x00, 0x00);
sqlite3_create_function([self sqliteHandle], [name UTF8String], count, SQLITE_UTF8, (__bridge void*)b, &FMDBBlockSQLiteCallBackFunction, 0x00, 0x00);
#endif
}
- (SqliteValueType)valueType:(void *)value {
return sqlite3_value_type(value);
}
- (int)valueInt:(void *)value {
return sqlite3_value_int(value);
}
- (long long)valueLong:(void *)value {
return sqlite3_value_int64(value);
}
- (double)valueDouble:(void *)value {
return sqlite3_value_double(value);
}
- (NSData *)valueData:(void *)value {
const void *bytes = sqlite3_value_blob(value);
int length = sqlite3_value_bytes(value);
return bytes ? [NSData dataWithBytes:bytes length:length] : nil;
}
- (NSString *)valueString:(void *)value {
const char *cString = (const char *)sqlite3_value_text(value);
return cString ? [NSString stringWithUTF8String:cString] : nil;
}
- (void)resultNullInContext:(void *)context {
sqlite3_result_null(context);
}
- (void)resultInt:(int) value context:(void *)context {
sqlite3_result_int(context, value);
}
- (void)resultLong:(long long)value context:(void *)context {
sqlite3_result_int64(context, value);
}
- (void)resultDouble:(double)value context:(void *)context {
sqlite3_result_double(context, value);
}
- (void)resultData:(NSData *)data context:(void *)context {
sqlite3_result_blob(context, data.bytes, (int)data.length, SQLITE_TRANSIENT);
}
- (void)resultString:(NSString *)value context:(void *)context {
sqlite3_result_text(context, [value UTF8String], -1, SQLITE_TRANSIENT);
}
- (void)resultError:(NSString *)error context:(void *)context {
sqlite3_result_error(context, [error UTF8String], -1);
}
- (void)resultErrorCode:(int)errorCode context:(void *)context {
sqlite3_result_error_code(context, errorCode);
}
- (void)resultErrorNoMemoryInContext:(void *)context {
sqlite3_result_error_nomem(context);
}
- (void)resultErrorTooBigInContext:(void *)context {
sqlite3_result_error_toobig(context);
}
@end
@implementation FMStatement
@synthesize statement=_statement;
@synthesize query=_query;
@synthesize useCount=_useCount;
@synthesize inUse=_inUse;
#if ! __has_feature(objc_arc)
- (void)finalize {
[self close];
[super finalize];
}
#endif
- (void)dealloc {
[self close];
@@ -1592,5 +1474,6 @@ void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3
return [NSString stringWithFormat:@"%@ %ld hit(s) for query %@", [super description], _useCount, _query];
}
@end

View File

@@ -9,7 +9,6 @@
#import <Foundation/Foundation.h>
#import "FMDatabase.h"
NS_ASSUME_NONNULL_BEGIN
/** Category of additions for `<FMDatabase>` class.
@@ -31,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
@return `int` value.
@note This is not available from Swift.
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project.
*/
- (int)intForQuery:(NSString*)query, ...;
@@ -43,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
@return `long` value.
@note This is not available from Swift.
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project.
*/
- (long)longForQuery:(NSString*)query, ...;
@@ -55,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
@return `BOOL` value.
@note This is not available from Swift.
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project.
*/
- (BOOL)boolForQuery:(NSString*)query, ...;
@@ -67,7 +66,7 @@ NS_ASSUME_NONNULL_BEGIN
@return `double` value.
@note This is not available from Swift.
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project.
*/
- (double)doubleForQuery:(NSString*)query, ...;
@@ -79,10 +78,10 @@ NS_ASSUME_NONNULL_BEGIN
@return `NSString` value.
@note This is not available from Swift.
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project.
*/
- (NSString * _Nullable)stringForQuery:(NSString*)query, ...;
- (NSString*)stringForQuery:(NSString*)query, ...;
/** Return `NSData` value for query
@@ -91,10 +90,10 @@ NS_ASSUME_NONNULL_BEGIN
@return `NSData` value.
@note This is not available from Swift.
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project.
*/
- (NSData * _Nullable)dataForQuery:(NSString*)query, ...;
- (NSData*)dataForQuery:(NSString*)query, ...;
/** Return `NSDate` value for query
@@ -103,10 +102,10 @@ NS_ASSUME_NONNULL_BEGIN
@return `NSDate` value.
@note This is not available from Swift.
@note To use this method from Swift, you must include `FMDatabaseAdditionsVariadic.swift` in your project.
*/
- (NSDate * _Nullable)dateForQuery:(NSString*)query, ...;
- (NSDate*)dateForQuery:(NSString*)query, ...;
// Notice that there's no dataNoCopyForQuery:.
@@ -142,7 +141,7 @@ NS_ASSUME_NONNULL_BEGIN
@see [SQLite File Format](http://www.sqlite.org/fileformat.html)
*/
- (FMResultSet *)getSchema;
- (FMResultSet*)getSchema;
/** The schema of the database.
@@ -192,7 +191,7 @@ NS_ASSUME_NONNULL_BEGIN
@warning Deprecated - use `<columnExists:inTableWithName:>` instead.
*/
- (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __deprecated_msg("Use columnExists:inTableWithName: instead");
- (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __attribute__ ((deprecated));
/** Validate SQL statement
@@ -207,7 +206,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (BOOL)validateSQL:(NSString*)sql error:(NSError * _Nullable *)error;
- (BOOL)validateSQL:(NSString*)sql error:(NSError**)error;
///-----------------------------------
@@ -221,16 +220,36 @@ NS_ASSUME_NONNULL_BEGIN
@see setApplicationID:
*/
@property (nonatomic) uint32_t applicationID;
- (uint32_t)applicationID;
/** Set the application ID
@param appID The `uint32_t` numeric value of the application ID.
@see applicationID
*/
- (void)setApplicationID:(uint32_t)appID;
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
/** Retrieve application ID string
@return The `NSString` value of the application ID.
@see setApplicationIDString:
*/
@property (nonatomic, retain) NSString *applicationIDString;
- (NSString*)applicationIDString;
/** Set the application ID string
@param string The `NSString` value of the application ID.
@see applicationIDString
*/
- (void)setApplicationIDString:(NSString*)string;
#endif
@@ -240,11 +259,20 @@ NS_ASSUME_NONNULL_BEGIN
/** Retrieve user version
@return The `uint32_t` numeric value of the user version.
@see setUserVersion:
*/
@property (nonatomic) uint32_t userVersion;
- (uint32_t)userVersion;
/** Set the user-version
@param version The `uint32_t` numeric value of the user version.
@see userVersion
*/
- (void)setUserVersion:(uint32_t)version;
@end
NS_ASSUME_NONNULL_END

View File

@@ -17,7 +17,7 @@
#endif
@interface FMDatabase (PrivateStuff)
- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray * _Nullable)arrayArgs orDictionary:(NSDictionary * _Nullable)dictionaryArgs orVAList:(va_list)args;
- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
@end
@implementation FMDatabase (FMDatabaseAdditions)
@@ -34,7 +34,7 @@ type ret = [resultSet sel:0]; \
return ret;
- (NSString *)stringForQuery:(NSString*)query, ... {
- (NSString*)stringForQuery:(NSString*)query, ... {
RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(NSString *, stringForColumnIndex);
}
@@ -222,11 +222,12 @@ return ret;
#pragma clang diagnostic pop
- (BOOL)validateSQL:(NSString*)sql error:(NSError**)error {
sqlite3_stmt *pStmt = NULL;
BOOL validationSucceeded = YES;
int rc = sqlite3_prepare_v2([self sqliteHandle], [sql UTF8String], -1, &pStmt, 0);
int rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0);
if (rc != SQLITE_OK) {
validationSucceeded = NO;
if (error) {

140
ios/Pods/FMDB/src/fmdb/FMDatabasePool.h generated Executable file → Normal file
View File

@@ -8,8 +8,6 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class FMDatabase;
/** Pool of `<FMDatabase>` objects.
@@ -30,15 +28,27 @@ NS_ASSUME_NONNULL_BEGIN
in the main.m file.
*/
@interface FMDatabasePool : NSObject
@interface FMDatabasePool : NSObject {
NSString *_path;
dispatch_queue_t _lockQueue;
NSMutableArray *_databaseInPool;
NSMutableArray *_databaseOutPool;
__unsafe_unretained id _delegate;
NSUInteger _maximumNumberOfDatabasesToCreate;
int _openFlags;
}
/** Database path */
@property (atomic, copy, nullable) NSString *path;
@property (atomic, retain) NSString *path;
/** Delegate object */
@property (atomic, assign, nullable) id delegate;
@property (atomic, assign) id delegate;
/** Maximum number of databases to create */
@@ -48,140 +58,73 @@ NS_ASSUME_NONNULL_BEGIN
@property (atomic, readonly) int openFlags;
/** Custom virtual file system name */
@property (atomic, copy, nullable) NSString *vfsName;
///---------------------
/// @name Initialization
///---------------------
/** Create pool using path.
@param aPath The file path of the database.
@return The `FMDatabasePool` object. `nil` on error.
*/
+ (instancetype)databasePoolWithPath:(NSString * _Nullable)aPath;
/** Create pool using file URL.
@param url The file `NSURL` of the database.
@return The `FMDatabasePool` object. `nil` on error.
*/
+ (instancetype)databasePoolWithURL:(NSURL * _Nullable)url;
+ (instancetype)databasePoolWithPath:(NSString*)aPath;
/** Create pool using path and specified flags
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `FMDatabasePool` object. `nil` on error.
*/
+ (instancetype)databasePoolWithPath:(NSString * _Nullable)aPath flags:(int)openFlags;
/** Create pool using file URL and specified flags
@param url The file `NSURL` of the database.
@param openFlags Flags passed to the openWithFlags method of the database.
@return The `FMDatabasePool` object. `nil` on error.
*/
+ (instancetype)databasePoolWithURL:(NSURL * _Nullable)url flags:(int)openFlags;
+ (instancetype)databasePoolWithPath:(NSString*)aPath flags:(int)openFlags;
/** Create pool using path.
@param aPath The file path of the database.
@return The `FMDatabasePool` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString * _Nullable)aPath;
/** Create pool using file URL.
@param url The file `NSURL of the database.
@return The `FMDatabasePool` object. `nil` on error.
*/
- (instancetype)initWithURL:(NSURL * _Nullable)url;
- (instancetype)initWithPath:(NSString*)aPath;
/** Create pool using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `FMDatabasePool` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString * _Nullable)aPath flags:(int)openFlags;
/** Create pool using file URL and specified flags.
@param url The file `NSURL` of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `FMDatabasePool` object. `nil` on error.
*/
- (instancetype)initWithURL:(NSURL * _Nullable)url flags:(int)openFlags;
/** Create pool using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@param vfsName The name of a custom virtual file system
@return The `FMDatabasePool` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString * _Nullable)aPath flags:(int)openFlags vfs:(NSString * _Nullable)vfsName;
/** Create pool using file URL and specified flags.
@param url The file `NSURL` of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@param vfsName The name of a custom virtual file system
@return The `FMDatabasePool` object. `nil` on error.
*/
- (instancetype)initWithURL:(NSURL * _Nullable)url flags:(int)openFlags vfs:(NSString * _Nullable)vfsName;
/** Returns the Class of 'FMDatabase' subclass, that will be used to instantiate database object.
Subclasses can override this method to return specified Class of 'FMDatabase' subclass.
@return The Class of 'FMDatabase' subclass, that will be used to instantiate database object.
*/
+ (Class)databaseClass;
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags;
///------------------------------------------------
/// @name Keeping track of checked in/out databases
///------------------------------------------------
/** Number of checked-in databases in pool
@returns Number of databases
*/
@property (nonatomic, readonly) NSUInteger countOfCheckedInDatabases;
- (NSUInteger)countOfCheckedInDatabases;
/** Number of checked-out databases in pool
@returns Number of databases
*/
@property (nonatomic, readonly) NSUInteger countOfCheckedOutDatabases;
- (NSUInteger)countOfCheckedOutDatabases;
/** Total number of databases in pool
@returns Number of databases
*/
@property (nonatomic, readonly) NSUInteger countOfOpenDatabases;
- (NSUInteger)countOfOpenDatabases;
/** Release all databases in pool */
@@ -196,21 +139,21 @@ NS_ASSUME_NONNULL_BEGIN
@param block The code to be run on the `FMDatabasePool` pool.
*/
- (void)inDatabase:(__attribute__((noescape)) void (^)(FMDatabase *db))block;
- (void)inDatabase:(void (^)(FMDatabase *db))block;
/** Synchronously perform database operations in pool using transaction.
@param block The code to be run on the `FMDatabasePool` pool.
*/
- (void)inTransaction:(__attribute__((noescape)) void (^)(FMDatabase *db, BOOL *rollback))block;
- (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
/** Synchronously perform database operations in pool using deferred transaction.
@param block The code to be run on the `FMDatabasePool` pool.
*/
- (void)inDeferredTransaction:(__attribute__((noescape)) void (^)(FMDatabase *db, BOOL *rollback))block;
- (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
/** Synchronously perform database operations in pool using save point.
@@ -221,7 +164,7 @@ NS_ASSUME_NONNULL_BEGIN
@warning You can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock. If you need to nest, use `<[FMDatabase startSavePointWithName:error:]>` instead.
*/
- (NSError * _Nullable)inSavePoint:(__attribute__((noescape)) void (^)(FMDatabase *db, BOOL *rollback))block;
- (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
@end
@@ -255,4 +198,3 @@ NS_ASSUME_NONNULL_BEGIN
@end
NS_ASSUME_NONNULL_END

49
ios/Pods/FMDB/src/fmdb/FMDatabasePool.m generated Executable file → Normal file
View File

@@ -15,12 +15,7 @@
#import "FMDatabasePool.h"
#import "FMDatabase.h"
@interface FMDatabasePool () {
dispatch_queue_t _lockQueue;
NSMutableArray *_databaseInPool;
NSMutableArray *_databaseOutPool;
}
@interface FMDatabasePool()
- (void)pushDatabaseBackInPool:(FMDatabase*)db;
- (FMDatabase*)db;
@@ -35,27 +30,15 @@
@synthesize openFlags=_openFlags;
+ (instancetype)databasePoolWithPath:(NSString *)aPath {
+ (instancetype)databasePoolWithPath:(NSString*)aPath {
return FMDBReturnAutoreleased([[self alloc] initWithPath:aPath]);
}
+ (instancetype)databasePoolWithURL:(NSURL *)url {
return FMDBReturnAutoreleased([[self alloc] initWithPath:url.path]);
}
+ (instancetype)databasePoolWithPath:(NSString *)aPath flags:(int)openFlags {
+ (instancetype)databasePoolWithPath:(NSString*)aPath flags:(int)openFlags {
return FMDBReturnAutoreleased([[self alloc] initWithPath:aPath flags:openFlags]);
}
+ (instancetype)databasePoolWithURL:(NSURL *)url flags:(int)openFlags {
return FMDBReturnAutoreleased([[self alloc] initWithPath:url.path flags:openFlags]);
}
- (instancetype)initWithURL:(NSURL *)url flags:(int)openFlags vfs:(NSString *)vfsName {
return [self initWithPath:url.path flags:openFlags vfs:vfsName];
}
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName {
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags {
self = [super init];
@@ -65,36 +48,21 @@
_databaseInPool = FMDBReturnRetained([NSMutableArray array]);
_databaseOutPool = FMDBReturnRetained([NSMutableArray array]);
_openFlags = openFlags;
_vfsName = [vfsName copy];
}
return self;
}
- (instancetype)initWithPath:(NSString *)aPath flags:(int)openFlags {
return [self initWithPath:aPath flags:openFlags vfs:nil];
}
- (instancetype)initWithURL:(NSURL *)url flags:(int)openFlags {
return [self initWithPath:url.path flags:openFlags vfs:nil];
}
- (instancetype)initWithPath:(NSString*)aPath {
- (instancetype)initWithPath:(NSString*)aPath
{
// default flags for sqlite3_open
return [self initWithPath:aPath flags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE];
}
- (instancetype)initWithURL:(NSURL *)url {
return [self initWithPath:url.path];
}
- (instancetype)init {
return [self initWithPath:nil];
}
+ (Class)databaseClass {
return [FMDatabase class];
}
- (void)dealloc {
@@ -102,7 +70,6 @@
FMDBRelease(_path);
FMDBRelease(_databaseInPool);
FMDBRelease(_databaseOutPool);
FMDBRelease(_vfsName);
if (_lockQueue) {
FMDBDispatchQueueRelease(_lockQueue);
@@ -161,13 +128,13 @@
}
}
db = [[[self class] databaseClass] databaseWithPath:self->_path];
db = [FMDatabase databaseWithPath:self->_path];
shouldNotifyDelegate = YES;
}
//This ensures that the db is opened before returning
#if SQLITE_VERSION_NUMBER >= 3005000
BOOL success = [db openWithFlags:self->_openFlags vfs:self->_vfsName];
BOOL success = [db openWithFlags:self->_openFlags];
#else
BOOL success = [db open];
#endif

95
ios/Pods/FMDB/src/fmdb/FMDatabaseQueue.h generated Executable file → Normal file
View File

@@ -8,8 +8,6 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class FMDatabase;
/** To perform queries and updates on multiple threads, you'll want to use `FMDatabaseQueue`.
@@ -62,19 +60,21 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface FMDatabaseQueue : NSObject
@interface FMDatabaseQueue : NSObject {
NSString *_path;
dispatch_queue_t _queue;
FMDatabase *_db;
int _openFlags;
}
/** Path of database */
@property (atomic, retain, nullable) NSString *path;
@property (atomic, retain) NSString *path;
/** Open flags */
@property (atomic, readonly) int openFlags;
/** Custom virtual file system name */
@property (atomic, copy, nullable) NSString *vfsName;
///----------------------------------------------------
/// @name Initialization, opening, and closing of queue
///----------------------------------------------------
@@ -86,72 +86,35 @@ NS_ASSUME_NONNULL_BEGIN
@return The `FMDatabaseQueue` object. `nil` on error.
*/
+ (instancetype)databaseQueueWithPath:(NSString * _Nullable)aPath;
/** Create queue using file URL.
@param url The file `NSURL` of the database.
@return The `FMDatabaseQueue` object. `nil` on error.
*/
+ (instancetype)databaseQueueWithURL:(NSURL * _Nullable)url;
+ (instancetype)databaseQueueWithPath:(NSString*)aPath;
/** Create queue using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `FMDatabaseQueue` object. `nil` on error.
*/
+ (instancetype)databaseQueueWithPath:(NSString * _Nullable)aPath flags:(int)openFlags;
/** Create queue using file URL and specified flags.
@param url The file `NSURL` of the database.
@param openFlags Flags passed to the openWithFlags method of the database.
@return The `FMDatabaseQueue` object. `nil` on error.
*/
+ (instancetype)databaseQueueWithURL:(NSURL * _Nullable)url flags:(int)openFlags;
+ (instancetype)databaseQueueWithPath:(NSString*)aPath flags:(int)openFlags;
/** Create queue using path.
@param aPath The file path of the database.
@return The `FMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString * _Nullable)aPath;
/** Create queue using file URL.
@param url The file `NSURL of the database.
@return The `FMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithURL:(NSURL * _Nullable)url;
- (instancetype)initWithPath:(NSString*)aPath;
/** Create queue using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `FMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString * _Nullable)aPath flags:(int)openFlags;
/** Create queue using file URL and specified flags.
@param url The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database.
@return The `FMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithURL:(NSURL * _Nullable)url flags:(int)openFlags;
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags;
/** Create queue using path and specified flags.
@@ -162,18 +125,7 @@ NS_ASSUME_NONNULL_BEGIN
@return The `FMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString * _Nullable)aPath flags:(int)openFlags vfs:(NSString * _Nullable)vfsName;
/** Create queue using file URL and specified flags.
@param url The file `NSURL of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@param vfsName The name of a custom virtual file system
@return The `FMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithURL:(NSURL * _Nullable)url flags:(int)openFlags vfs:(NSString * _Nullable)vfsName;
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName;
/** Returns the Class of 'FMDatabase' subclass, that will be used to instantiate database object.
@@ -188,10 +140,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)close;
/** Interupt pending database operation. */
- (void)interrupt;
///-----------------------------------------------
/// @name Dispatching database operations to queue
///-----------------------------------------------
@@ -201,21 +149,21 @@ NS_ASSUME_NONNULL_BEGIN
@param block The code to be run on the queue of `FMDatabaseQueue`
*/
- (void)inDatabase:(__attribute__((noescape)) void (^)(FMDatabase *db))block;
- (void)inDatabase:(void (^)(FMDatabase *db))block;
/** Synchronously perform database operations on queue, using transactions.
@param block The code to be run on the queue of `FMDatabaseQueue`
*/
- (void)inTransaction:(__attribute__((noescape)) void (^)(FMDatabase *db, BOOL *rollback))block;
- (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
/** Synchronously perform database operations on queue, using deferred transactions.
@param block The code to be run on the queue of `FMDatabaseQueue`
*/
- (void)inDeferredTransaction:(__attribute__((noescape)) void (^)(FMDatabase *db, BOOL *rollback))block;
- (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
///-----------------------------------------------
/// @name Dispatching database operations to queue
@@ -228,8 +176,7 @@ NS_ASSUME_NONNULL_BEGIN
// NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
// If you need to nest, use FMDatabase's startSavePointWithName:error: instead.
- (NSError * _Nullable)inSavePoint:(__attribute__((noescape)) void (^)(FMDatabase *db, BOOL *rollback))block;
- (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
@end
NS_ASSUME_NONNULL_END

57
ios/Pods/FMDB/src/fmdb/FMDatabaseQueue.m generated Executable file → Normal file
View File

@@ -29,16 +29,14 @@
* the queue's dispatch queue, which should not happen and causes a deadlock.
*/
static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey;
@interface FMDatabaseQueue () {
dispatch_queue_t _queue;
FMDatabase *_db;
}
@end
@implementation FMDatabaseQueue
+ (instancetype)databaseQueueWithPath:(NSString *)aPath {
@synthesize path = _path;
@synthesize openFlags = _openFlags;
+ (instancetype)databaseQueueWithPath:(NSString*)aPath {
FMDatabaseQueue *q = [[self alloc] initWithPath:aPath];
FMDBAutorelease(q);
@@ -46,11 +44,8 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey
return q;
}
+ (instancetype)databaseQueueWithURL:(NSURL *)url {
return [self databaseQueueWithPath:url.path];
}
+ (instancetype)databaseQueueWithPath:(NSString *)aPath flags:(int)openFlags {
+ (instancetype)databaseQueueWithPath:(NSString*)aPath flags:(int)openFlags {
FMDatabaseQueue *q = [[self alloc] initWithPath:aPath flags:openFlags];
FMDBAutorelease(q);
@@ -58,19 +53,12 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey
return q;
}
+ (instancetype)databaseQueueWithURL:(NSURL *)url flags:(int)openFlags {
return [self databaseQueueWithPath:url.path flags:openFlags];
}
+ (Class)databaseClass {
return [FMDatabase class];
}
- (instancetype)initWithURL:(NSURL *)url flags:(int)openFlags vfs:(NSString *)vfsName {
return [self initWithPath:url.path flags:openFlags vfs:vfsName];
}
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName {
self = [super init];
if (self != nil) {
@@ -94,25 +82,17 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey
_queue = dispatch_queue_create([[NSString stringWithFormat:@"fmdb.%@", self] UTF8String], NULL);
dispatch_queue_set_specific(_queue, kDispatchQueueSpecificKey, (__bridge void *)self, NULL);
_openFlags = openFlags;
_vfsName = [vfsName copy];
}
return self;
}
- (instancetype)initWithPath:(NSString *)aPath flags:(int)openFlags {
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags {
return [self initWithPath:aPath flags:openFlags vfs:nil];
}
- (instancetype)initWithURL:(NSURL *)url flags:(int)openFlags {
return [self initWithPath:url.path flags:openFlags vfs:nil];
}
- (instancetype)initWithURL:(NSURL *)url {
return [self initWithPath:url.path];
}
- (instancetype)initWithPath:(NSString *)aPath {
- (instancetype)initWithPath:(NSString*)aPath {
// default flags for sqlite3_open
return [self initWithPath:aPath flags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE vfs:nil];
}
@@ -123,9 +103,9 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey
- (void)dealloc {
FMDBRelease(_db);
FMDBRelease(_path);
FMDBRelease(_vfsName);
if (_queue) {
FMDBDispatchQueueRelease(_queue);
@@ -146,16 +126,12 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey
FMDBRelease(self);
}
- (void)interrupt {
[[self database] interrupt];
}
- (FMDatabase*)database {
if (!_db) {
_db = FMDBReturnRetained([[[self class] databaseClass] databaseWithPath:_path]);
_db = FMDBReturnRetained([FMDatabase databaseWithPath:_path]);
#if SQLITE_VERSION_NUMBER >= 3005000
BOOL success = [_db openWithFlags:_openFlags vfs:_vfsName];
BOOL success = [_db openWithFlags:_openFlags];
#else
BOOL success = [_db open];
#endif
@@ -171,12 +147,10 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey
}
- (void)inDatabase:(void (^)(FMDatabase *db))block {
#ifndef NDEBUG
/* Get the currently executing queue (which should probably be nil, but in theory could be another DB queue
* and then check it against self to make sure we're not about to deadlock. */
FMDatabaseQueue *currentSyncQueue = (__bridge id)dispatch_get_specific(kDispatchQueueSpecificKey);
assert(currentSyncQueue != self && "inDatabase: was called reentrantly on the same queue, which would lead to a deadlock");
#endif
FMDBRetain(self);
@@ -201,6 +175,7 @@ static const void * const kDispatchQueueSpecificKey = &kDispatchQueueSpecificKey
FMDBRelease(self);
}
- (void)beginTransaction:(BOOL)useDeferred withBlock:(void (^)(FMDatabase *db, BOOL *rollback))block {
FMDBRetain(self);
dispatch_sync(_queue, ^() {

View File

@@ -1,7 +1,5 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
#ifndef __has_feature // Optional.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
@@ -24,9 +22,13 @@ NS_ASSUME_NONNULL_BEGIN
- `<FMDatabase>`
*/
@interface FMResultSet : NSObject
@property (nonatomic, retain, nullable) FMDatabase *parentDB;
@interface FMResultSet : NSObject {
FMDatabase *_parentDB;
FMStatement *_statement;
NSString *_query;
NSMutableDictionary *_columnNameToIndexMap;
}
///-----------------
/// @name Properties
@@ -34,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
/** Executed query */
@property (atomic, retain, nullable) NSString *query;
@property (atomic, retain) NSString *query;
/** `NSMutableDictionary` mapping column names to numeric index */
@@ -42,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
/** `FMStatement` used by result set. */
@property (atomic, retain, nullable) FMStatement *statement;
@property (atomic, retain) FMStatement *statement;
///------------------------------------
/// @name Creating and closing database
@@ -63,6 +65,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)close;
- (void)setParentDB:(FMDatabase *)newDb;
///---------------------------------------
/// @name Iterating through the result set
///---------------------------------------
@@ -89,7 +93,7 @@ NS_ASSUME_NONNULL_BEGIN
@see hasAnotherRow
*/
- (BOOL)nextWithError:(NSError * _Nullable *)outErr;
- (BOOL)nextWithError:(NSError **)outErr;
/** Did the last call to `<next>` succeed in retrieving another row?
@@ -111,7 +115,7 @@ NS_ASSUME_NONNULL_BEGIN
@return Integer value of the number of columns.
*/
@property (nonatomic, readonly) int columnCount;
- (int)columnCount;
/** Column index for column name
@@ -129,7 +133,7 @@ NS_ASSUME_NONNULL_BEGIN
@return columnName `NSString` value of the name of the column.
*/
- (NSString * _Nullable)columnNameForIndex:(int)columnIdx;
- (NSString*)columnNameForIndex:(int)columnIdx;
/** Result set integer value for column.
@@ -245,39 +249,39 @@ NS_ASSUME_NONNULL_BEGIN
@param columnName `NSString` value of the name of the column.
@return String value of the result set's column.
@return `NSString` value of the result set's column.
*/
- (NSString * _Nullable)stringForColumn:(NSString*)columnName;
- (NSString*)stringForColumn:(NSString*)columnName;
/** Result set `NSString` value for column.
@param columnIdx Zero-based index for column.
@return String value of the result set's column.
@return `NSString` value of the result set's column.
*/
- (NSString * _Nullable)stringForColumnIndex:(int)columnIdx;
- (NSString*)stringForColumnIndex:(int)columnIdx;
/** Result set `NSDate` value for column.
@param columnName `NSString` value of the name of the column.
@return Date value of the result set's column.
@return `NSDate` value of the result set's column.
*/
- (NSDate * _Nullable)dateForColumn:(NSString*)columnName;
- (NSDate*)dateForColumn:(NSString*)columnName;
/** Result set `NSDate` value for column.
@param columnIdx Zero-based index for column.
@return Date value of the result set's column.
@return `NSDate` value of the result set's column.
*/
- (NSDate * _Nullable)dateForColumnIndex:(int)columnIdx;
- (NSDate*)dateForColumnIndex:(int)columnIdx;
/** Result set `NSData` value for column.
@@ -285,20 +289,20 @@ NS_ASSUME_NONNULL_BEGIN
@param columnName `NSString` value of the name of the column.
@return Data value of the result set's column.
@return `NSData` value of the result set's column.
*/
- (NSData * _Nullable)dataForColumn:(NSString*)columnName;
- (NSData*)dataForColumn:(NSString*)columnName;
/** Result set `NSData` value for column.
@param columnIdx Zero-based index for column.
@return Data value of the result set's column.
@return `NSData` value of the result set's column.
*/
- (NSData * _Nullable)dataForColumnIndex:(int)columnIdx;
- (NSData*)dataForColumnIndex:(int)columnIdx;
/** Result set `(const unsigned char *)` value for column.
@@ -307,9 +311,7 @@ NS_ASSUME_NONNULL_BEGIN
@return `(const unsigned char *)` value of the result set's column.
*/
- (const unsigned char * _Nullable)UTF8StringForColumn:(NSString*)columnName;
- (const unsigned char * _Nullable)UTF8StringForColumnName:(NSString*)columnName __deprecated_msg("Use UTF8StringForColumn instead");
- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName;
/** Result set `(const unsigned char *)` value for column.
@@ -318,20 +320,18 @@ NS_ASSUME_NONNULL_BEGIN
@return `(const unsigned char *)` value of the result set's column.
*/
- (const unsigned char * _Nullable)UTF8StringForColumnIndex:(int)columnIdx;
- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx;
/** Result set object for column.
@param columnName Name of the column.
@param columnName `NSString` value of the name of the column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
@see objectForKeyedSubscript:
*/
- (id _Nullable)objectForColumn:(NSString*)columnName;
- (id _Nullable)objectForColumnName:(NSString*)columnName __deprecated_msg("Use objectForColumn instead");
- (id)objectForColumnName:(NSString*)columnName;
/** Result set object for column.
@@ -342,7 +342,7 @@ NS_ASSUME_NONNULL_BEGIN
@see objectAtIndexedSubscript:
*/
- (id _Nullable)objectForColumnIndex:(int)columnIdx;
- (id)objectForColumnIndex:(int)columnIdx;
/** Result set object for column.
@@ -363,7 +363,7 @@ NS_ASSUME_NONNULL_BEGIN
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
*/
- (id _Nullable)objectForKeyedSubscript:(NSString *)columnName;
- (id)objectForKeyedSubscript:(NSString *)columnName;
/** Result set object for column.
@@ -384,13 +384,13 @@ NS_ASSUME_NONNULL_BEGIN
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
*/
- (id _Nullable)objectAtIndexedSubscript:(int)columnIdx;
- (id)objectAtIndexedSubscript:(int)columnIdx;
/** Result set `NSData` value for column.
@param columnName `NSString` value of the name of the column.
@return Data value of the result set's column.
@return `NSData` value of the result set's column.
@warning If you are going to use this data after you iterate over the next row, or after you close the
result set, make sure to make a copy of the data first (or just use `<dataForColumn:>`/`<dataForColumnIndex:>`)
@@ -398,13 +398,13 @@ If you don't, you're going to be in a world of hurt when you try and use the dat
*/
- (NSData * _Nullable)dataNoCopyForColumn:(NSString *)columnName NS_RETURNS_NOT_RETAINED;
- (NSData*)dataNoCopyForColumn:(NSString*)columnName NS_RETURNS_NOT_RETAINED;
/** Result set `NSData` value for column.
@param columnIdx Zero-based index for column.
@return Data value of the result set's column.
@return `NSData` value of the result set's column.
@warning If you are going to use this data after you iterate over the next row, or after you close the
result set, make sure to make a copy of the data first (or just use `<dataForColumn:>`/`<dataForColumnIndex:>`)
@@ -412,7 +412,7 @@ If you don't, you're going to be in a world of hurt when you try and use the dat
*/
- (NSData * _Nullable)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED;
- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED;
/** Is the column `NULL`?
@@ -435,10 +435,12 @@ If you don't, you're going to be in a world of hurt when you try and use the dat
/** Returns a dictionary of the row results mapped to case sensitive keys of the column names.
@returns `NSDictionary` of the row results.
@warning The keys to the dictionary are case sensitive of the column names.
*/
@property (nonatomic, readonly, nullable) NSDictionary *resultDictionary;
- (NSDictionary*)resultDictionary;
/** Returns a dictionary of the row results
@@ -447,7 +449,7 @@ If you don't, you're going to be in a world of hurt when you try and use the dat
@warning **Deprecated**: Please use `<resultDictionary>` instead. Also, beware that `<resultDictionary>` is case sensitive!
*/
- (NSDictionary * _Nullable)resultDict __deprecated_msg("Use resultDictionary instead");
- (NSDictionary*)resultDict __attribute__ ((deprecated));
///-----------------------------
/// @name Key value coding magic
@@ -464,4 +466,3 @@ If you don't, you're going to be in a world of hurt when you try and use the dat
@end
NS_ASSUME_NONNULL_END

View File

@@ -12,12 +12,10 @@
- (void)resultSetDidClose:(FMResultSet *)resultSet;
@end
@interface FMResultSet () {
NSMutableDictionary *_columnNameToIndexMap;
}
@end
@implementation FMResultSet
@synthesize query=_query;
@synthesize statement=_statement;
+ (instancetype)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB {
@@ -32,12 +30,10 @@
return FMDBReturnAutoreleased(rs);
}
#if ! __has_feature(objc_arc)
- (void)finalize {
[self close];
[super finalize];
}
#endif
- (void)dealloc {
[self close];
@@ -102,7 +98,7 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (NSDictionary *)resultDict {
- (NSDictionary*)resultDict {
NSUInteger num_cols = (NSUInteger)sqlite3_data_count([_statement statement]);
@@ -221,7 +217,7 @@
NSNumber *n = [[self columnNameToIndexMap] objectForKey:columnName];
if (n != nil) {
if (n) {
return [n intValue];
}
@@ -230,6 +226,8 @@
return -1;
}
- (int)intForColumn:(NSString*)columnName {
return [self intForColumnIndex:[self columnIndexForName:columnName]];
}
@@ -278,9 +276,9 @@
return sqlite3_column_double([_statement statement], columnIdx);
}
- (NSString *)stringForColumnIndex:(int)columnIdx {
- (NSString*)stringForColumnIndex:(int)columnIdx {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0) || columnIdx >= sqlite3_column_count([_statement statement])) {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
return nil;
}
@@ -304,7 +302,7 @@
- (NSDate*)dateForColumnIndex:(int)columnIdx {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0) || columnIdx >= sqlite3_column_count([_statement statement])) {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
return nil;
}
@@ -318,7 +316,7 @@
- (NSData*)dataForColumnIndex:(int)columnIdx {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0) || columnIdx >= sqlite3_column_count([_statement statement])) {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
return nil;
}
@@ -339,7 +337,7 @@
- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0) || columnIdx >= sqlite3_column_count([_statement statement])) {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
return nil;
}
@@ -362,26 +360,18 @@
- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0) || columnIdx >= sqlite3_column_count([_statement statement])) {
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
return nil;
}
return sqlite3_column_text([_statement statement], columnIdx);
}
- (const unsigned char *)UTF8StringForColumn:(NSString*)columnName {
- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName {
return [self UTF8StringForColumnIndex:[self columnIndexForName:columnName]];
}
- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName {
return [self UTF8StringForColumn:columnName];
}
- (id)objectForColumnIndex:(int)columnIdx {
if (columnIdx < 0 || columnIdx >= sqlite3_column_count([_statement statement])) {
return nil;
}
int columnType = sqlite3_column_type([_statement statement], columnIdx);
id returnValue = nil;
@@ -408,10 +398,6 @@
}
- (id)objectForColumnName:(NSString*)columnName {
return [self objectForColumn:columnName];
}
- (id)objectForColumn:(NSString*)columnName {
return [self objectForColumnIndex:[self columnIndexForName:columnName]];
}
@@ -420,12 +406,16 @@
return [NSString stringWithUTF8String: sqlite3_column_name([_statement statement], columnIdx)];
}
- (void)setParentDB:(FMDatabase *)newDb {
_parentDB = newDb;
}
- (id)objectAtIndexedSubscript:(int)columnIdx {
return [self objectForColumnIndex:columnIdx];
}
- (id)objectForKeyedSubscript:(NSString *)columnName {
return [self objectForColumn:columnName];
return [self objectForColumnName:columnName];
}