From ef60b2022d50b99e6de78cc301bf71e8b336ae0e Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 13 Aug 2013 23:49:31 +0000 Subject: Rework table content and custom query data loading and storage for speed increases and lower memory usage: - Add a new SPMySQLStreamingResultStore class to SPMySQL.framework. This class acts as both a result set and a data store for the accompanying data, storing the row information in a custom format in a custom malloc zone. - Amend SPDataStorage to wrap the new class, so original result information is stored in the one location in the custom format. Any edited information is handled by SPDataStorage for clean separation - Rework table content and custom query data data stores to use the new class. This significantly speeds up data loading, resulting in faster data loads if they weren't previously network constrained, or lower CPU usage otherwise. The memory usage is also lowered, with the memory overhead for many small cells being enormously reduced. --- .../Source/SPMySQLConnection Categories/Encoding.m | 2 +- .../Querying & Preparation.h | 1 + .../Querying & Preparation.m | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories') diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Encoding.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Encoding.m index 38eb104f..ca052d48 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Encoding.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Encoding.m @@ -269,7 +269,7 @@ } else if (!strcmp(mysqlCharset, "cp1251")) { return NSWindowsCP1251StringEncoding; } else if (!strcmp(mysqlCharset, "utf16")) { - return NSUnicodeStringEncoding; + return NSUTF16BigEndianStringEncoding; } else if (!strcmp(mysqlCharset, "utf16le")) { return NSUTF16LittleEndianStringEncoding; } else if (!strcmp(mysqlCharset, "cp1256")) { diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h index 0f086a89..e80a197f 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h @@ -43,6 +43,7 @@ - (SPMySQLResult *)queryString:(NSString *)theQueryString; - (SPMySQLFastStreamingResult *)streamingQueryString:(NSString *)theQueryString; - (id)streamingQueryString:(NSString *)theQueryString useLowMemoryBlockingStreaming:(BOOL)fullStreaming; +- (SPMySQLStreamingResultStore *)resultStoreFromQueryString:(NSString *)theQueryString; - (id)queryString:(NSString *)theQueryString usingEncoding:(NSStringEncoding)theEncoding withResultType:(SPMySQLResultType)theReturnType; // Query convenience functions diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m index f437ca87..7ccd0175 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m @@ -191,7 +191,17 @@ { return SPMySQLConnectionQueryString(self, theQueryString, stringEncoding, SPMySQLResultAsFastStreamingResult); } - + +/** + * Run a query, provided as a string, on the active connection in the current connection + * encoding. Returns the result as a result set which also handles data storage. Note + * that the donwloading of results will not occur until -[resultSet startDownload] is called. + */ +- (SPMySQLStreamingResultStore *)resultStoreFromQueryString:(NSString *)theQueryString +{ + return SPMySQLConnectionQueryString(self, theQueryString, stringEncoding, SPMySQLResultAsStreamingResultStore); +} + /** * Run a query, provided as a string, on the active connection in the current connection * encoding. Returns the result as a streaming query set, where not all the results may @@ -346,6 +356,12 @@ mysqlResult = mysql_use_result(mySQLConnection); theResult = [[SPMySQLFastStreamingResult alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding connection:self]; break; + + // Also set up the result for streaming result data stores, but note the data download does not start yet + case SPMySQLResultAsStreamingResultStore: + mysqlResult = mysql_use_result(mySQLConnection); + theResult = [[SPMySQLStreamingResultStore alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding connection:self]; + break; } // Update the error message, if appropriate, to reflect result store errors or overall success -- cgit v1.2.3