aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-08-26 00:46:24 +0000
committerrowanbeentje <rowan@beent.je>2009-08-26 00:46:24 +0000
commit7de1a9a8517c2004e6a97543fbb1462d9c32f4d1 (patch)
treee5fe038f9dc6d55652e4e109adca542e468b2073 /Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
parentd4294235a11548d4712cf3174b0887eea50a5e4c (diff)
downloadsequelpro-7de1a9a8517c2004e6a97543fbb1462d9c32f4d1.tar.gz
sequelpro-7de1a9a8517c2004e6a97543fbb1462d9c32f4d1.tar.bz2
sequelpro-7de1a9a8517c2004e6a97543fbb1462d9c32f4d1.zip
Alter CustomQuery to use StreamingResult to download and process result sets:
- Significantly improve memory usage - Minor speedup (1.1x faster?) to overall query/display times - Improvements to MCPStreamingResult and MCPConnection to accurately report affected row count
Diffstat (limited to 'Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m48
1 files changed, 46 insertions, 2 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
index 3f3e2073..c63a9f0b 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
@@ -285,13 +285,57 @@
return returnArray;
}
+/*
+ * Ensure the result set is fully processed and freed without any processing
+ */
+- (void) cancelResultLoad
+{
+ MYSQL_ROW theRow;
+
+ // Loop through all the rows and ensure the rows are fetched.
+ // If fully streaming, loop through the rows directly
+ if (fullyStreaming) {
+ while (1) {
+ theRow = mysql_fetch_row(mResult);
+
+ // If no data was returned, we're at the end of the result set - return.
+ if (theRow == NULL) return;
+ }
+
+ // If in cached-streaming/fast download mode, loop until all data is fetched and freed
+ } else {
+
+ while (1) {
+
+ // Check to see whether we need to wait for the data to be availabe
+ // - if so, wait 1ms before checking again
+ while (!dataDownloaded && processedRowCount == downloadedRowCount) usleep(1000);
+
+ // If all rows have been processed, we're at the end of the result set - return
+ // once all memory has been freed
+ if (processedRowCount == downloadedRowCount) {
+ while (!dataFreed) usleep(1000);
+ [parentConnection unlockConnection];
+ connectionUnlocked = YES;
+ return;
+ }
+ processedRowCount++;
+ }
+ }
+}
+
#pragma mark -
#pragma mark Overrides for safety
+/**
+ * If numOfRows is used before the data is fully downloaded, -1 will be returned;
+ * otherwise the number of rows is returned.
+ */
- (my_ulonglong)numOfRows
{
- NSLog(@"numOfRows cannot be used with streaming results");
- return 0;
+ if (!dataDownloaded) return -1;
+
+ return downloadedRowCount;
}
- (void)dataSeek:(my_ulonglong) row