From 15100feadc549801496c6d076931ba9b765ea069 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 11 Jan 2011 08:37:15 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20error=20handling=20while=20writi?= =?UTF-8?q?ng=20SP=5FBUNDLE=5FTABLE=5FMETA=5FDATA=20esp.=20while=20switchi?= =?UTF-8?q?ng=20databases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPCopyTable.m | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'Source/SPCopyTable.m') diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 31b1e6d4..d31ae09d 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -1238,30 +1238,32 @@ NSInteger kBlobAsImageFile = 4; if([[self delegate] isKindOfClass:[SPCustomQuery class]]) { [env setObject:@"query" forKey:SPBundleShellVariableDataTableSource]; NSArray *defs = [[self delegate] dataColumnDefinitions]; - for( c = 0; c < numColumns; c++ ) { - NSDictionary *col = NSArrayObjectAtIndex(defs, columnMappings[c]); - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]]; - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"typegrouping"]]; - [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"char_length"]) ? : @""]; - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"UNSIGNED_FLAG"]]; - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"AUTO_INCREMENT_FLAG"]]; - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"PRI_KEY_FLAG"]]; - [tableMetaData appendString:@"\n"]; - } + if(defs && [defs count] == numColumns) + for( c = 0; c < numColumns; c++ ) { + NSDictionary *col = NSArrayObjectAtIndex(defs, columnMappings[c]); + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]]; + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"typegrouping"]]; + [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"char_length"]) ? : @""]; + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"UNSIGNED_FLAG"]]; + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"AUTO_INCREMENT_FLAG"]]; + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"PRI_KEY_FLAG"]]; + [tableMetaData appendString:@"\n"]; + } } else if([[self delegate] isKindOfClass:[SPTableContent class]]) { [env setObject:@"content" forKey:SPBundleShellVariableDataTableSource]; NSArray *defs = [[self delegate] dataColumnDefinitions]; - for( c = 0; c < numColumns; c++ ) { - NSDictionary *col = NSArrayObjectAtIndex(defs, columnMappings[c]); - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]]; - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"typegrouping"]]; - [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"length"]) ? : @""]; - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"unsigned"]]; - [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"autoincrement"]]; - [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"isprimarykey"]) ? : @"0"]; - [tableMetaData appendFormat:@"%@\n", [col objectForKey:@"comment"]]; - } + if(defs && [defs count] == numColumns) + for( c = 0; c < numColumns; c++ ) { + NSDictionary *col = NSArrayObjectAtIndex(defs, columnMappings[c]); + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"type"]]; + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"typegrouping"]]; + [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"length"]) ? : @""]; + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"unsigned"]]; + [tableMetaData appendFormat:@"%@\t", [col objectForKey:@"autoincrement"]]; + [tableMetaData appendFormat:@"%@\t", ([col objectForKey:@"isprimarykey"]) ? : @"0"]; + [tableMetaData appendFormat:@"%@\n", [col objectForKey:@"comment"]]; + } } free(columnMappings); -- cgit v1.2.3