From d8a2b9b9e2b998e9bcf8b6ede19b4442cecf5ef8 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 14 Jul 2015 18:13:25 +0200 Subject: Fix an exception caused by empty column names in query results (fixes #2173) Issue likely introduced in 2b52f76e. --- .../Source/SPMySQLResult Categories/Field Definitions.m | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'Frameworks') diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Field Definitions.m b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Field Definitions.m index d0eac4a1..c61b9140 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Field Definitions.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Field Definitions.m @@ -232,28 +232,33 @@ const SPMySQLResultCharset SPMySQLCharsetMap[] = // Record the original column position within the result set [eachField setObject:[NSString stringWithFormat:@"%llu", (unsigned long long)i] forKey:@"datacolumnindex"]; + // mysqlField.name might point to an empty string or NULL (theoretically). + // _stringWithBytes:... will return @"" if either bytes is NULL or length is 0. + // For now let's interpret (bytes != NULL) as a valid string (possibly empty) + // and otherwise as 'value not set'. + // Record the column name, or alias if one is being used - if (mysqlField.name_length) { + if (mysqlField.name) { [eachField setObject:[self _lossyStringWithBytes:mysqlField.name length:mysqlField.name_length wasLossy:NULL] forKey:@"name"]; } // Record the original column name if using an alias - if (mysqlField.org_name_length) { + if (mysqlField.org_name) { [eachField setObject:[self _stringWithBytes:mysqlField.org_name length:mysqlField.org_name_length] forKey:@"org_name"]; } // If the column had an underlying table, record the table name, respecting aliases - if (mysqlField.table_length) { + if (mysqlField.table) { [eachField setObject:[self _stringWithBytes:mysqlField.table length:mysqlField.table_length] forKey:@"table"]; } // If the column had an underlying table, record the original table name, ignoring aliases - if (mysqlField.org_table_length) { + if (mysqlField.org_table) { [eachField setObject:[self _stringWithBytes:mysqlField.org_table length:mysqlField.org_table_length] forKey:@"org_table"]; } // If the column had an underlying database, record the database name - if (mysqlField.db_length) { + if (mysqlField.db) { [eachField setObject:[self _stringWithBytes:mysqlField.db length:mysqlField.db_length] forKey:@"db"]; } -- cgit v1.2.3