aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-11-24 22:41:54 +0000
committerstuconnolly <stuart02@gmail.com>2009-11-24 22:41:54 +0000
commitdeb85b3ecd20ecbae8c3a8dc5ebd08dfbce8b57d (patch)
treea62796a34e85d10e363f4c6ea78b761988eb6524
parentc8f01e3d2c987166dab31cc46d4f9827a7dc5f4d (diff)
downloadsequelpro-deb85b3ecd20ecbae8c3a8dc5ebd08dfbce8b57d.tar.gz
sequelpro-deb85b3ecd20ecbae8c3a8dc5ebd08dfbce8b57d.tar.bz2
sequelpro-deb85b3ecd20ecbae8c3a8dc5ebd08dfbce8b57d.zip
Fix an occasional crasher by checking the size of the custom query result set is not zero before attempting to get an object from it. As far as I'm aware this crash only seemed to occur when executing the second out of 2 queries that both contained multiple OUTER JOINS.
-rw-r--r--Source/CustomQuery.m72
1 files changed, 36 insertions, 36 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 43c3a0a9..826258cd 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -1322,73 +1322,73 @@
return fieldIDQueryStr;
}
-
#pragma mark -
#pragma mark TableView datasource methods
-- (int)numberOfRowsInTableView:(NSTableView *)aTableView
+/**
+ * Returns the number of rows in the result set table view.
+ */
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
- if ( aTableView == customQueryView ) {
- if ( nil == fullResult ) {
- return 0;
- } else {
- return fullResultCount;
- }
- } else {
+ if (aTableView == customQueryView) {
+ return (fullResult == nil) ? 0 : fullResultCount;
+ }
+ else {
return 0;
}
}
/**
- * This function changes the text color of text/blob fields whose content is NULL
+ * This function changes the text color of text/blob fields whose content is NULL.
*/
-- (void)tableView:(CMCopyTable *)aTableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)aTableColumn row:(int)row
+- (void)tableView:(CMCopyTable *)aTableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)aTableColumn row:(NSInteger)rowIndex
{
- if ( aTableView == customQueryView ) {
- if (row > fullResultCount) return;
-
+ if (aTableView == customQueryView) {
+
+ // Perform various result set checks to prevent crashes
+ if ((fullResultCount == 0) || (rowIndex > fullResultCount)) return;
+
// For NULL cell's display the user's NULL value placeholder in grey to easily distinguish it from other values
if ([cell respondsToSelector:@selector(setTextColor:)]) {
- id theValue = NSArrayObjectAtIndex(NSArrayObjectAtIndex(fullResult, row), [[aTableColumn identifier] intValue]);
- [cell setTextColor:[theValue isNSNull] ? [NSColor lightGrayColor] : [NSColor blackColor]];
+ id value = NSArrayObjectAtIndex(NSArrayObjectAtIndex(fullResult, rowIndex), [[aTableColumn identifier] intValue]);
+
+ [cell setTextColor:[value isNSNull] ? [NSColor lightGrayColor] : [NSColor blackColor]];
}
}
-
}
-- (id)tableView:(NSTableView *)aTableView
- objectValueForTableColumn:(NSTableColumn *)aTableColumn
- row:(int)rowIndex
+/**
+ * Returns the object for the requested column and row index.
+ */
+- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
+ if (aTableView == customQueryView) {
+
+ // Perform various result set checks to prevent crashes
+ if ((fullResultCount == 0) || (rowIndex > fullResultCount)) return nil;
+
+ id value = NSArrayObjectAtIndex(NSArrayObjectAtIndex(fullResult, rowIndex), [[aTableColumn identifier] intValue]);
+
+ if ([value isKindOfClass:[NSData class]])
+ return [value shortStringRepresentationUsingEncoding:[mySQLConnection encoding]];
- if ( aTableView == customQueryView ) {
- if (rowIndex > fullResultCount) return nil;
-
- id theValue = NSArrayObjectAtIndex(NSArrayObjectAtIndex(fullResult, rowIndex), [[aTableColumn identifier] intValue]);
-
- if ( [theValue isKindOfClass:[NSData class]] )
- return [theValue shortStringRepresentationUsingEncoding:[mySQLConnection encoding]];
-
- if ( [theValue isNSNull] )
+ if ([value isNSNull])
return [prefs objectForKey:SPNullValue];
- return theValue;
-
+ return value;
}
else {
return @"";
}
}
-- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
- forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
+- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
- if ( aTableView == customQueryView ) {
+ if (aTableView == customQueryView) {
// Field editing
-
- if(fieldIDQueryString == nil) return;
+ if (fieldIDQueryString == nil) return;
NSDictionary *columnDefinition;