diff options
author | rowanbeentje <rowan@beent.je> | 2008-12-12 00:56:03 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2008-12-12 00:56:03 +0000 |
commit | c3d1f88f78b79751cb97cec8e11284c3503b1af9 (patch) | |
tree | d0bab2fc9e12543b0a3b4168294e7180263fb9aa /Source/TableDump.m | |
parent | a291848bceeb1dc59a1ae803148b8988d94ace54 (diff) | |
download | sequelpro-c3d1f88f78b79751cb97cec8e11284c3503b1af9.tar.gz sequelpro-c3d1f88f78b79751cb97cec8e11284c3503b1af9.tar.bz2 sequelpro-c3d1f88f78b79751cb97cec8e11284c3503b1af9.zip |
Provide a partial fix for Issue #117 by adding leading-zero tests to the NSScanner numeric checks, and clarifying comments to make it clearer that NSScanner should be replaced when possible.
Diffstat (limited to 'Source/TableDump.m')
-rw-r--r-- | Source/TableDump.m | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Source/TableDump.m b/Source/TableDump.m index 7460d982..48ff5b04 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -848,14 +848,15 @@ } else { - // Test whether this cell contains a number + // Until we have access to field types, test whether this cell contains a + // number via use of an NSScanner and a check of the first couple of + // characters. If it is a number, add the number directly. sqlNumericTester = [NSScanner scannerWithString:cellValue]; - - // If it does contain a number, add the number directly - if ([sqlNumericTester scanFloat:nil] && [sqlNumericTester isAtEnd]) { + if ([sqlNumericTester scanFloat:nil] && [sqlNumericTester isAtEnd] && + ([cellValue characterAtIndex:0] != '0' || [cellValue characterAtIndex:1] == '.')) { [sqlString appendString:cellValue]; - // Otherwise add a quoted string with special characters escaped + // Otherwise add a quoted string with special characters escaped } else { [sqlString appendString:@"'"]; [sqlString appendString:[mySQLConnection prepareString:cellValue]]; @@ -1056,12 +1057,14 @@ } else { - // Test whether this cell contains a number + // Until we have access to field types, test whether this cell contains a number via use of an + // NSScanner and a check of the first couple of characters. if ([[csvRow objectAtIndex:j] isKindOfClass:[NSData class]]) { csvCellIsNumeric = FALSE; } else { csvNumericTester = [NSScanner scannerWithString:csvCell]; - csvCellIsNumeric = [csvNumericTester scanFloat:nil] && [csvNumericTester isAtEnd]; + csvCellIsNumeric = [csvNumericTester scanFloat:nil] && [csvNumericTester isAtEnd] && + ([csvCell characterAtIndex:0] != '0' || [csvCell characterAtIndex:1] == '.'); } // Escape any occurrences of the escaping character |