From 9a4fe782c03bc0c42030b9344fd4f54e494d88b4 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 25 Mar 2010 18:55:32 +0000 Subject: Suppress the connection structure query if there're more than 10000 items are listed in `information_schema`.`COLUMNS` for now which is a 'quick-fix' for i608. In the near future the gathering routine will do it db/table by db/table to minimize the traffic starting from the current selected db. --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 82772461..84fb6a5d 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -1926,8 +1926,8 @@ void performThreadedKeepAlive(void *ptr) NSStringEncoding theConnectionEncoding = [MCPConnection encodingForMySQLEncoding:mysql_character_set_name(structConnection)]; // Set connection to UTF-8 since the information_schema is encoded in UTF-8 - NSString *setNameString = @"SET NAMES 'utf8'"; - NSData *encodedSetNameData = NSStringDataUsingLossyEncoding(setNameString, theConnectionEncoding, 1); + NSString *query = @"SET NAMES 'utf8'"; + NSData *encodedSetNameData = NSStringDataUsingLossyEncoding(query, theConnectionEncoding, 1); const char *setNameCString = [encodedSetNameData bytes]; unsigned long setNameCStringLength = [encodedSetNameData length]; if (mysql_real_query(structConnection, setNameCString, setNameCStringLength) != 0) { @@ -1935,7 +1935,29 @@ void performThreadedKeepAlive(void *ptr) [queryPool release]; return; } + + NSUInteger numberOfItems = 20000; + query = @"SELECT COUNT(*) FROM `information_schema`.`COLUMNS`"; + encodedSetNameData = NSStringDataUsingLossyEncoding(query, theConnectionEncoding, 1); + setNameCString = [encodedSetNameData bytes]; + setNameCStringLength = [encodedSetNameData length]; + if (mysql_real_query(structConnection, setNameCString, setNameCStringLength) != 0) { + isQueryingDbStructure = NO; + [queryPool release]; + return; + } + theResult = mysql_use_result(structConnection); + row = mysql_fetch_row(theResult); + if(row) + numberOfItems = [[self stringWithUTF8CString:row[0]] longLongValue]; + mysql_free_result(theResult); + if(numberOfItems > 10000) { + isQueryingDbStructure = NO; + [queryPool release]; + return; + } + // Query the desired data NSString *queryDbString = @"" @"SELECT TABLE_SCHEMA AS `databases`, TABLE_NAME AS `tables`, COLUMN_NAME AS `fields`, COLUMN_TYPE AS `type`, CHARACTER_SET_NAME AS `charset`, '0' AS `structtype`, `COLUMN_KEY` AS `KEY`, `EXTRA` AS EXTRA, `PRIVILEGES` AS `PRIVILEGES`, `COLLATION_NAME` AS `collation`, `COLUMN_DEFAULT` AS `default`, `IS_NULLABLE` AS `is_nullable`, `COLUMN_COMMENT` AS `comment` FROM `information_schema`.`COLUMNS` " -- cgit v1.2.3