aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2014-08-01 01:18:44 +0200
committerMax <post@wickenrode.com>2014-08-01 01:18:44 +0200
commit2570a91dd1e1d7b88b908db33494baeaa5001e74 (patch)
treec48635205db38479c7ef05b05c394169317271bc
parentb2e63fad01ca76b9090c1a0adbd999990d817846 (diff)
downloadsequelpro-2570a91dd1e1d7b88b908db33494baeaa5001e74.tar.gz
sequelpro-2570a91dd1e1d7b88b908db33494baeaa5001e74.tar.bz2
sequelpro-2570a91dd1e1d7b88b908db33494baeaa5001e74.zip
Fix for exception on export (#1968)
This fixes an exception that would happen if three conditions were met: 1) No database was selected or it was empty 2) A custom export filename was set 3) You tried to export the result of a custom query
-rw-r--r--Source/SPArrayAdditions.h10
-rw-r--r--Source/SPArrayAdditions.m7
-rw-r--r--Source/SPExportFilenameUtilities.m4
3 files changed, 20 insertions, 1 deletions
diff --git a/Source/SPArrayAdditions.h b/Source/SPArrayAdditions.h
index 565e0393..cf3673d5 100644
--- a/Source/SPArrayAdditions.h
+++ b/Source/SPArrayAdditions.h
@@ -86,4 +86,14 @@ static inline void NSMutableArrayReplaceObject(NSArray *self, CFIndex idx, id an
- (NSArray *)subarrayWithIndexes:(NSIndexSet *)indexes;
+/**
+ * Variant of objectAtIndex: that avoids the "index out of bounds" exception by
+ * just returning nil instead.
+ *
+ * @warning This method is NOT thread-safe.
+ * @param index An index
+ * @return The object located at index or nil.
+ */
+- (id)objectOrNilAtIndex:(NSUInteger)index;
+
@end
diff --git a/Source/SPArrayAdditions.m b/Source/SPArrayAdditions.m
index 91af56e4..0fe75483 100644
--- a/Source/SPArrayAdditions.m
+++ b/Source/SPArrayAdditions.m
@@ -145,4 +145,11 @@
return subArray;
}
+- (id)objectOrNilAtIndex:(NSUInteger)index
+{
+ if([self count] <= index)
+ return nil;
+ return [self objectAtIndex:index];
+}
+
@end
diff --git a/Source/SPExportFilenameUtilities.m b/Source/SPExportFilenameUtilities.m
index d9637e4d..71422b28 100644
--- a/Source/SPExportFilenameUtilities.m
+++ b/Source/SPExportFilenameUtilities.m
@@ -47,7 +47,8 @@
// Get the current export file extension
NSString *extension = [self currentDefaultExportFileExtension];
- filename = [self expandCustomFilenameFormatUsingTableName:[[tablesListInstance tables] objectAtIndex:1]];
+ //note that there will be no tableName if the export is done from a query result without a database selected (or empty).
+ filename = [self expandCustomFilenameFormatUsingTableName:[[tablesListInstance tables] objectOrNilAtIndex:1]];
if (![[filename pathExtension] length] && [extension length] > 0) filename = [filename stringByAppendingPathExtension:extension];
}
@@ -319,6 +320,7 @@
* Uses the current custom filename field as a data source.
*
* @param table A table name to be used within the expanded filename.
+ * Can be nil.
*
* @return The expanded filename.
*/