Skip to content

Commit 0a22284

Browse files
committed
Fix some threading issues during print output generation (#3025)
1 parent 5a531bc commit 0a22284

File tree

1 file changed

+91
-91
lines changed

1 file changed

+91
-91
lines changed

Source/SPDatabaseDocument.m

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7414,130 +7414,130 @@ - (void)generateHTMLForPrinting
74147414
{
74157415
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
74167416

7417-
// Set up template engine with your chosen matcher
7418-
MGTemplateEngine *engine = [MGTemplateEngine templateEngine];
7419-
7420-
[engine setMatcher:[ICUTemplateMatcher matcherWithTemplateEngine:engine]];
7417+
NSMutableDictionary *connection = [NSMutableDictionary dictionary];
7418+
NSMutableDictionary *printData = [NSMutableDictionary dictionary];
74217419

7422-
NSMutableDictionary *connection = [self connectionInformation];
7420+
SPMainQSync(^{
7421+
[connection setDictionary:[self connectionInformation]];
7422+
[printData setObject:[self columnNames] forKey:@"columns"];
7423+
SPTableViewType view = [self currentlySelectedView];
74237424

7424-
NSString *heading = @"";
7425-
NSArray *rows, *indexes, *indexColumns = nil;
7425+
NSString *heading = @"";
74267426

7427-
NSArray *columns = [self columnNames];
7427+
// Table source view
7428+
if (view == SPTableViewStructure) {
74287429

7429-
NSMutableDictionary *printData = [NSMutableDictionary dictionary];
7430+
NSDictionary *tableSource = [tableSourceInstance tableSourceForPrinting];
74307431

7431-
SPTableViewType view = [self currentlySelectedView];
7432+
NSInteger tableType = [tablesListInstance tableType];
74327433

7433-
// Table source view
7434-
if (view == SPTableViewStructure) {
7434+
switch (tableType) {
7435+
case SPTableTypeTable:
7436+
heading = NSLocalizedString(@"Table Structure", @"table structure print heading");
7437+
break;
7438+
case SPTableTypeView:
7439+
heading = NSLocalizedString(@"View Structure", @"view structure print heading");
7440+
break;
7441+
}
74357442

7436-
NSDictionary *tableSource = [tableSourceInstance tableSourceForPrinting];
7443+
NSArray *rows = [[NSArray alloc] initWithArray:
7444+
[[tableSource objectForKey:@"structure"] objectsAtIndexes:
7445+
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSource objectForKey:@"structure"] count] - 1)]]
7446+
];
74377447

7438-
NSInteger tableType = [tablesListInstance tableType];
7448+
NSArray *indexes = [[NSArray alloc] initWithArray:
7449+
[[tableSource objectForKey:@"indexes"] objectsAtIndexes:
7450+
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSource objectForKey:@"indexes"] count] - 1)]]
7451+
];
74397452

7440-
switch (tableType) {
7441-
case SPTableTypeTable:
7442-
heading = NSLocalizedString(@"Table Structure", @"table structure print heading");
7443-
break;
7444-
case SPTableTypeView:
7445-
heading = NSLocalizedString(@"View Structure", @"view structure print heading");
7446-
break;
7447-
}
7453+
NSArray *indexColumns = [[tableSource objectForKey:@"indexes"] objectAtIndex:0];
74487454

7449-
rows = [[NSArray alloc] initWithArray:
7450-
[[tableSource objectForKey:@"structure"] objectsAtIndexes:
7451-
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSource objectForKey:@"structure"] count] - 1)]]
7452-
];
7455+
[printData setObject:rows forKey:@"rows"];
7456+
[printData setObject:indexes forKey:@"indexes"];
7457+
[printData setObject:indexColumns forKey:@"indexColumns"];
74537458

7454-
indexes = [[NSArray alloc] initWithArray:
7455-
[[tableSource objectForKey:@"indexes"] objectsAtIndexes:
7456-
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSource objectForKey:@"indexes"] count] - 1)]]
7457-
];
7459+
if ([indexes count]) [printData setObject:@1 forKey:@"hasIndexes"];
74587460

7459-
indexColumns = [[tableSource objectForKey:@"indexes"] objectAtIndex:0];
7461+
[rows release];
7462+
[indexes release];
7463+
}
7464+
// Table content view
7465+
else if (view == SPTableViewContent) {
74607466

7461-
[printData setObject:rows forKey:@"rows"];
7462-
[printData setObject:indexes forKey:@"indexes"];
7463-
[printData setObject:indexColumns forKey:@"indexColumns"];
7467+
NSArray *data = [tableContentInstance currentDataResultWithNULLs:NO hideBLOBs:YES];
74647468

7465-
if ([indexes count]) [printData setObject:@1 forKey:@"hasIndexes"];
7469+
heading = NSLocalizedString(@"Table Content", @"table content print heading");
74667470

7467-
[rows release];
7468-
[indexes release];
7469-
}
7470-
// Table content view
7471-
else if (view == SPTableViewContent) {
7471+
NSArray *rows = [[NSArray alloc] initWithArray:
7472+
[data objectsAtIndexes:
7473+
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]]
7474+
];
74727475

7473-
NSArray *data = [tableContentInstance currentDataResultWithNULLs:NO hideBLOBs:YES];
7476+
[printData setObject:rows forKey:@"rows"];
7477+
[connection setValue:[tableContentInstance usedQuery] forKey:@"query"];
74747478

7475-
heading = NSLocalizedString(@"Table Content", @"table content print heading");
7479+
[rows release];
7480+
}
7481+
// Custom query view
7482+
else if (view == SPTableViewCustomQuery) {
74767483

7477-
rows = [[NSArray alloc] initWithArray:
7478-
[data objectsAtIndexes:
7479-
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]]
7480-
];
7484+
NSArray *data = [customQueryInstance currentResult];
74817485

7482-
[printData setObject:rows forKey:@"rows"];
7483-
[connection setValue:[tableContentInstance usedQuery] forKey:@"query"];
7486+
heading = NSLocalizedString(@"Query Result", @"query result print heading");
74847487

7485-
[rows release];
7486-
}
7487-
// Custom query view
7488-
else if (view == SPTableViewCustomQuery) {
7488+
NSArray *rows = [[NSArray alloc] initWithArray:
7489+
[data objectsAtIndexes:
7490+
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]]
7491+
];
74897492

7490-
NSArray *data = [customQueryInstance currentResult];
7493+
[printData setObject:rows forKey:@"rows"];
7494+
[connection setValue:[customQueryInstance usedQuery] forKey:@"query"];
74917495

7492-
heading = NSLocalizedString(@"Query Result", @"query result print heading");
7496+
[rows release];
7497+
}
7498+
// Table relations view
7499+
else if (view == SPTableViewRelations) {
74937500

7494-
rows = [[NSArray alloc] initWithArray:
7495-
[data objectsAtIndexes:
7496-
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]]
7497-
];
7501+
NSArray *data = [tableRelationsInstance relationDataForPrinting];
74987502

7499-
[printData setObject:rows forKey:@"rows"];
7500-
[connection setValue:[customQueryInstance usedQuery] forKey:@"query"];
7503+
heading = NSLocalizedString(@"Table Relations", @"toolbar item label for switching to the Table Relations tab");
75017504

7502-
[rows release];
7503-
}
7504-
// Table relations view
7505-
else if (view == SPTableViewRelations) {
7505+
NSArray *rows = [[NSArray alloc] initWithArray:
7506+
[data objectsAtIndexes:
7507+
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]]
7508+
];
75067509

7507-
NSArray *data = [tableRelationsInstance relationDataForPrinting];
7510+
[printData setObject:rows forKey:@"rows"];
75087511

7509-
heading = NSLocalizedString(@"Table Relations", @"toolbar item label for switching to the Table Relations tab");
7512+
[rows release];
7513+
}
7514+
// Table triggers view
7515+
else if (view == SPTableViewTriggers) {
75107516

7511-
rows = [[NSArray alloc] initWithArray:
7512-
[data objectsAtIndexes:
7513-
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]]
7514-
];
7517+
NSArray *data = [tableTriggersInstance triggerDataForPrinting];
75157518

7516-
[printData setObject:rows forKey:@"rows"];
7519+
heading = NSLocalizedString(@"Table Triggers", @"toolbar item label for switching to the Table Triggers tab");
75177520

7518-
[rows release];
7519-
}
7520-
// Table triggers view
7521-
else if (view == SPTableViewTriggers) {
7521+
NSArray *rows = [[NSArray alloc] initWithArray:
7522+
[data objectsAtIndexes:
7523+
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]]
7524+
];
75227525

7523-
NSArray *data = [tableTriggersInstance triggerDataForPrinting];
7526+
[printData setObject:rows forKey:@"rows"];
75247527

7525-
heading = NSLocalizedString(@"Table Triggers", @"toolbar item label for switching to the Table Triggers tab");
7528+
[rows release];
7529+
}
75267530

7527-
rows = [[NSArray alloc] initWithArray:
7528-
[data objectsAtIndexes:
7529-
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]]
7530-
];
7531+
[printData setObject:heading forKey:@"heading"];
7532+
});
75317533

7532-
[printData setObject:rows forKey:@"rows"];
7534+
// Set up template engine with your chosen matcher
7535+
MGTemplateEngine *engine = [MGTemplateEngine templateEngine];
75337536

7534-
[rows release];
7535-
}
7537+
[engine setMatcher:[ICUTemplateMatcher matcherWithTemplateEngine:engine]];
75367538

75377539
[engine setObject:connection forKey:@"c"];
75387540

7539-
[printData setObject:heading forKey:@"heading"];
7540-
[printData setObject:columns forKey:@"columns"];
75417541
[printData setObject:([prefs boolForKey:SPUseMonospacedFonts]) ? SPDefaultMonospacedFontName : @"Lucida Grande" forKey:@"font"];
75427542
[printData setObject:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? @"1px solid #CCCCCC" : @"none" forKey:@"gridlines"];
75437543

@@ -7643,12 +7643,12 @@ - (NSArray *)columnNames
76437643
*/
76447644
- (NSMutableDictionary *)connectionInformation
76457645
{
7646+
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
76467647
NSString *versionForPrint = [NSString stringWithFormat:@"%@ %@ (%@ %@)",
7647-
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"],
7648-
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],
7649-
NSLocalizedString(@"build", @"build label"),
7650-
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
7651-
];
7648+
[infoDict objectForKey:@"CFBundleName"],
7649+
[infoDict objectForKey:@"CFBundleShortVersionString"],
7650+
NSLocalizedString(@"build", @"build label"),
7651+
[infoDict objectForKey:@"CFBundleVersion"]];
76527652

76537653
NSMutableDictionary *connection = [NSMutableDictionary dictionary];
76547654

0 commit comments

Comments
 (0)