Skip to content

Commit

Permalink
Return empty array when the rows are nil in FLEXSQLResult
Browse files Browse the repository at this point in the history
  • Loading branch information
matrush committed Jul 23, 2020
1 parent a7a65c4 commit b2a84e0
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,25 @@ - (NSInteger)lastRowID {
}

- (NSArray<NSString *> *)queryAllTables {
return [[self executeStatement:QUERY_TABLENAMES].rows flex_mapped:^id(NSArray *table, NSUInteger idx) {
NSArray<NSArray<NSString *> *> *rows = [self executeStatement:QUERY_TABLENAMES].rows;
return rows ? [rows flex_mapped:^id(NSArray *table, NSUInteger idx) {
return table.firstObject;
}];
}] : @[];
}

- (NSArray<NSString *> *)queryAllColumnsOfTable:(NSString *)tableName {
NSString *sql = [NSString stringWithFormat:@"PRAGMA table_info('%@')",tableName];
FLEXSQLResult *results = [self executeStatement:sql];
return [results.keyedRows flex_mapped:^id(NSDictionary *column, NSUInteger idx) {

return results.keyedRows ? [results.keyedRows flex_mapped:^id(NSDictionary *column, NSUInteger idx) {
return column[@"name"];
}];
}] : @[];
}

- (NSArray<NSArray *> *)queryAllDataInTable:(NSString *)tableName {
return [self executeStatement:[@"SELECT * FROM "
stringByAppendingString:tableName
]].rows;
]].rows ?: @[];
}

- (FLEXSQLResult *)executeStatement:(NSString *)sql {
Expand Down

0 comments on commit b2a84e0

Please sign in to comment.