61
61
#import "SPAppController.h"
62
62
#import "SPBundleHTMLOutputController.h"
63
63
#endif
64
+ #import "SPFunctions.h"
64
65
65
66
#import <pthread.h>
66
67
#import <SPMySQL/SPMySQL.h>
@@ -884,7 +885,7 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
884
885
(long)totalAffectedRows
885
886
];
886
887
}
887
- if(resultDataCount ) {
888
+ if([resultData count] ) {
888
889
// we were running a query that returns a result set (ie. SELECT).
889
890
// TODO: mysql_query() returns as soon as the first result row is found (which might be pretty soon when using indexes / not doing aggregations)
890
891
// and that makes our query time measurement pretty useless (see #264)
@@ -905,7 +906,7 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
905
906
#endif
906
907
907
908
// If no results were returned, redraw the empty table and post notifications before returning.
908
- if ( !resultDataCount ) {
909
+ if ( ![resultData count] ) {
909
910
[customQueryView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
910
911
911
912
// Notify any listeners that the query has completed
@@ -931,8 +932,6 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
931
932
return;
932
933
}
933
934
934
- [[customQueryView onMainThread] reloadData];
935
-
936
935
// Restore the result view origin if appropriate
937
936
if (!NSEqualRects(selectionViewportToRestore, NSZeroRect)) {
938
937
@@ -976,12 +975,12 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
976
975
*/
977
976
- (void)updateResultStore:(SPMySQLStreamingResultStore *)theResultStore
978
977
{
979
-
980
- // Remove all items from the table
981
- resultDataCount = 0;
982
- [customQueryView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES];
983
978
pthread_mutex_lock(&resultDataLock);
984
- [resultData removeAllRows];
979
+ // Remove all items from the table
980
+ SPMainQSync(^{
981
+ [resultData removeAllRows];
982
+ [customQueryView noteNumberOfRowsChanged];
983
+ });
985
984
986
985
// Add the new store
987
986
[resultData setDataStorage:theResultStore updatingExisting:NO];
@@ -994,11 +993,8 @@ - (void)updateResultStore:(SPMySQLStreamingResultStore *)theResultStore
994
993
[[self onMainThread] initQueryLoadTimer];
995
994
996
995
[resultData awaitDataDownloaded];
997
-
998
- // If the final column autoresize wasn't performed, perform it
999
- if (queryLoadLastRowCount < 200) [[self onMainThread] autosizeColumns];
1000
-
1001
- [customQueryView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:NO];
996
+
997
+ // Any further UI updates are the responsibility of the timer callback
1002
998
}
1003
999
1004
1000
/**
@@ -1488,8 +1484,8 @@ - (void) clearQueryLoadTimer
1488
1484
*/
1489
1485
- (void) queryLoadUpdate:(NSTimer *)theTimer
1490
1486
{
1491
- resultDataCount = [resultData count];
1492
-
1487
+ NSUInteger resultDataCount = [resultData count];
1488
+
1493
1489
if (queryLoadTimerTicksSinceLastUpdate < queryLoadInterfaceUpdateInterval) {
1494
1490
queryLoadTimerTicksSinceLastUpdate++;
1495
1491
return;
@@ -1501,7 +1497,7 @@ - (void) queryLoadUpdate:(NSTimer *)theTimer
1501
1497
1502
1498
// Check whether a table update is required, based on whether new rows are
1503
1499
// available to display.
1504
- if (resultDataCount == (NSInteger) queryLoadLastRowCount) {
1500
+ if (resultDataCount == queryLoadLastRowCount) {
1505
1501
return;
1506
1502
}
1507
1503
@@ -1548,7 +1544,7 @@ - (NSArray *)currentResult
1548
1544
*/
1549
1545
- (NSUInteger)currentResultRowCount
1550
1546
{
1551
- return resultDataCount ;
1547
+ return [resultData count] ;
1552
1548
}
1553
1549
1554
1550
/**
@@ -2077,7 +2073,7 @@ - (void)saveCellValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn
2077
2073
*/
2078
2074
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
2079
2075
{
2080
- return (aTableView == customQueryView) ? (resultData == nil) ? 0 : resultDataCount : 0;
2076
+ return (aTableView == customQueryView) ? (resultData == nil) ? 0 : [resultData count] : 0;
2081
2077
}
2082
2078
2083
2079
/**
@@ -2102,7 +2098,7 @@ - (void)tableView:(SPCopyTable *)aTableView willDisplayCell:(id)cell forTableCol
2102
2098
if (isWorking) {
2103
2099
pthread_mutex_lock(&resultDataLock);
2104
2100
2105
- if (rowIndex < resultDataCount && columnIndex < [resultData columnCount]) {
2101
+ if (SPIntS2U( rowIndex) < [resultData count] && columnIndex < [resultData columnCount]) {
2106
2102
showCellAsGray = [resultData cellIsNullOrUnloadedAtRow:rowIndex column:columnIndex];
2107
2103
} else {
2108
2104
showCellAsGray = YES;
@@ -2403,7 +2399,7 @@ - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(SPTextAndLinkC
2403
2399
// cases.
2404
2400
if (isWorking) {
2405
2401
pthread_mutex_lock(&resultDataLock);
2406
- if (row < resultDataCount && (NSUInteger)[[aTableColumn identifier] integerValue] < [resultData columnCount]) {
2402
+ if (SPIntS2U( row) < [resultData count] && (NSUInteger)[[aTableColumn identifier] integerValue] < [resultData columnCount]) {
2407
2403
theValue = [[SPDataStorageObjectAtRowAndColumn(resultData, row, [[aTableColumn identifier] integerValue]) copy] autorelease];
2408
2404
}
2409
2405
pthread_mutex_unlock(&resultDataLock);
@@ -3769,7 +3765,6 @@ - (id)init
3769
3765
#endif
3770
3766
3771
3767
// init tableView's data source
3772
- resultDataCount = 0;
3773
3768
resultData = [[SPDataStorage alloc] init];
3774
3769
editedRow = -1;
3775
3770
@@ -4022,7 +4017,7 @@ - (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column preserv
4022
4017
if (isWorking) {
4023
4018
pthread_mutex_lock(&resultDataLock);
4024
4019
4025
- if (row < resultDataCount && column < [resultData columnCount]) {
4020
+ if (SPIntS2U( row) < [resultData count] && column < [resultData columnCount]) {
4026
4021
value = SPDataStoragePreviewAtRowAndColumn(resultData, row, column, 150);
4027
4022
}
4028
4023
0 commit comments