aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPCustomQuery.h1
-rw-r--r--Source/SPCustomQuery.m41
2 files changed, 18 insertions, 24 deletions
diff --git a/Source/SPCustomQuery.h b/Source/SPCustomQuery.h
index b63de32f..fe31be6d 100644
--- a/Source/SPCustomQuery.h
+++ b/Source/SPCustomQuery.h
@@ -160,7 +160,6 @@
SPDataStorage *resultData;
pthread_mutex_t resultDataLock;
- NSInteger resultDataCount;
NSArray *cqColumnDefinition;
NSString *lastExecutedQuery;
NSInteger editedRow;
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index 38c593d1..3cbd6a4d 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -61,6 +61,7 @@
#import "SPAppController.h"
#import "SPBundleHTMLOutputController.h"
#endif
+#import "SPFunctions.h"
#import <pthread.h>
#import <SPMySQL/SPMySQL.h>
@@ -884,7 +885,7 @@
(long)totalAffectedRows
];
}
- if(resultDataCount) {
+ if([resultData count]) {
// we were running a query that returns a result set (ie. SELECT).
// TODO: mysql_query() returns as soon as the first result row is found (which might be pretty soon when using indexes / not doing aggregations)
// and that makes our query time measurement pretty useless (see #264)
@@ -905,7 +906,7 @@
#endif
// If no results were returned, redraw the empty table and post notifications before returning.
- if ( !resultDataCount ) {
+ if ( ![resultData count] ) {
[customQueryView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
// Notify any listeners that the query has completed
@@ -931,8 +932,6 @@
return;
}
- [[customQueryView onMainThread] reloadData];
-
// Restore the result view origin if appropriate
if (!NSEqualRects(selectionViewportToRestore, NSZeroRect)) {
@@ -976,12 +975,12 @@
*/
- (void)updateResultStore:(SPMySQLStreamingResultStore *)theResultStore
{
-
- // Remove all items from the table
- resultDataCount = 0;
- [customQueryView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES];
pthread_mutex_lock(&resultDataLock);
- [resultData removeAllRows];
+ // Remove all items from the table
+ SPMainQSync(^{
+ [resultData removeAllRows];
+ [customQueryView noteNumberOfRowsChanged];
+ });
// Add the new store
[resultData setDataStorage:theResultStore updatingExisting:NO];
@@ -994,11 +993,8 @@
[[self onMainThread] initQueryLoadTimer];
[resultData awaitDataDownloaded];
-
- // If the final column autoresize wasn't performed, perform it
- if (queryLoadLastRowCount < 200) [[self onMainThread] autosizeColumns];
-
- [customQueryView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:NO];
+
+ // Any further UI updates are the responsibility of the timer callback
}
/**
@@ -1488,8 +1484,8 @@
*/
- (void) queryLoadUpdate:(NSTimer *)theTimer
{
- resultDataCount = [resultData count];
-
+ NSUInteger resultDataCount = [resultData count];
+
if (queryLoadTimerTicksSinceLastUpdate < queryLoadInterfaceUpdateInterval) {
queryLoadTimerTicksSinceLastUpdate++;
return;
@@ -1501,7 +1497,7 @@
// Check whether a table update is required, based on whether new rows are
// available to display.
- if (resultDataCount == (NSInteger)queryLoadLastRowCount) {
+ if (resultDataCount == queryLoadLastRowCount) {
return;
}
@@ -1548,7 +1544,7 @@
*/
- (NSUInteger)currentResultRowCount
{
- return resultDataCount;
+ return [resultData count];
}
/**
@@ -2077,7 +2073,7 @@
*/
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
- return (aTableView == customQueryView) ? (resultData == nil) ? 0 : resultDataCount : 0;
+ return (aTableView == customQueryView) ? (resultData == nil) ? 0 : [resultData count] : 0;
}
/**
@@ -2102,7 +2098,7 @@
if (isWorking) {
pthread_mutex_lock(&resultDataLock);
- if (rowIndex < resultDataCount && columnIndex < [resultData columnCount]) {
+ if (SPIntS2U(rowIndex) < [resultData count] && columnIndex < [resultData columnCount]) {
showCellAsGray = [resultData cellIsNullOrUnloadedAtRow:rowIndex column:columnIndex];
} else {
showCellAsGray = YES;
@@ -2403,7 +2399,7 @@
// cases.
if (isWorking) {
pthread_mutex_lock(&resultDataLock);
- if (row < resultDataCount && (NSUInteger)[[aTableColumn identifier] integerValue] < [resultData columnCount]) {
+ if (SPIntS2U(row) < [resultData count] && (NSUInteger)[[aTableColumn identifier] integerValue] < [resultData columnCount]) {
theValue = [[SPDataStorageObjectAtRowAndColumn(resultData, row, [[aTableColumn identifier] integerValue]) copy] autorelease];
}
pthread_mutex_unlock(&resultDataLock);
@@ -3769,7 +3765,6 @@
#endif
// init tableView's data source
- resultDataCount = 0;
resultData = [[SPDataStorage alloc] init];
editedRow = -1;
@@ -4022,7 +4017,7 @@
if (isWorking) {
pthread_mutex_lock(&resultDataLock);
- if (row < resultDataCount && column < [resultData columnCount]) {
+ if (SPIntS2U(row) < [resultData count] && column < [resultData columnCount]) {
value = SPDataStoragePreviewAtRowAndColumn(resultData, row, column, 150);
}