From 0bf8e6ff980425d16c4411f4b375a809940ae49b Mon Sep 17 00:00:00 2001 From: bamse16 Date: Mon, 2 Mar 2009 18:48:31 +0000 Subject: Better error handling of dump reading (checking for NSError object instead of content of read string) Raising error when trying to import empty CSV file. --- Source/CMMCPConnection.m | 9 +++++++++ Source/TableDump.m | 22 ++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'Source') diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 11f60b97..31efb4a1 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -328,6 +328,8 @@ WARNING : incomplete implementation. Please, send your fixes. if (delegate && [delegate respondsToSelector:@selector(willQueryString:)]) { [delegate willQueryString:query]; } + + NSDate *startQueryDate = [NSDate date]; if (0 == (theQueryCode = mysql_query(mConnection, theCQuery))) { if (mysql_field_count(mConnection) != 0) { @@ -346,6 +348,13 @@ WARNING : incomplete implementation. Please, send your fixes. return nil; } + + //Log how long the query took + if (delegate && [delegate respondsToSelector:@selector(willQueryString:)]) { + NSString *timedQuery = [NSString stringWithFormat:@"%@ /* %.2f */", query, [[NSDate date] timeIntervalSinceDate:startQueryDate]]; + [delegate willQueryString:timedQuery]; + } + [self startKeepAliveTimerResettingState:YES]; diff --git a/Source/TableDump.m b/Source/TableDump.m index 7d035830..0b134bf3 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -372,19 +372,21 @@ NSError *errorStr = nil; NSMutableString *errors = [NSMutableString string]; NSString *fileType = [[importFormatPopup selectedItem] title]; - + //load file into string dumpFile = [SPSQLParser stringWithContentsOfFile:filename encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]] error:&errorStr]; - - if (!dumpFile) { + + if (errorStr) { NSBeginAlertSheet(NSLocalizedString(@"Error", @"Title of error alert"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - NSLocalizedString(@"Couldn't open file. Be sure that the path is correct and that you have the necessary privileges.", @"Message of panel when file cannot be opened")); + [errorStr localizedDescription] + ); + [pool release]; return; } @@ -493,6 +495,18 @@ [singleProgressBar setUsesThreadedAnimation:NO]; [singleProgressBar setIndeterminate:NO]; + if([importArray count] == 0){ + NSBeginAlertSheet(NSLocalizedString(@"Error", @"Title of error alert"), + NSLocalizedString(@"OK", @"OK button"), + nil, nil, + tableWindow, self, + nil, nil, nil, + NSLocalizedString(@"Could not parse file as CSV", @"Error when we can't parse/split file as CSV") + ); + [pool release]; + return; + } + if (progressCancelled) { progressCancelled = NO; [pool release]; -- cgit v1.2.3