diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-09-15 16:44:36 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-09-15 16:44:36 +0000 |
commit | 82421b6cacb94aa3d9aaea785e8f333d0a0c82aa (patch) | |
tree | 60cac4eb84d15fcecf9fc83eac318380c997f217 | |
parent | 42b58dcdda0c82473bfed4df8211c6f0f343c6fc (diff) | |
download | sequelpro-82421b6cacb94aa3d9aaea785e8f333d0a0c82aa.tar.gz sequelpro-82421b6cacb94aa3d9aaea785e8f333d0a0c82aa.tar.bz2 sequelpro-82421b6cacb94aa3d9aaea785e8f333d0a0c82aa.zip |
• added validation for BIT fields while in-cell-editing; only 1 or 0 are allowed to type in
• enabled max length and BIT field validation for CustomQuery
-rw-r--r-- | Source/SPCustomQuery.m | 27 | ||||
-rw-r--r-- | Source/SPDataCellFormatter.m | 12 |
2 files changed, 27 insertions, 12 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 6818dd7f..2a805da2 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -1480,6 +1480,16 @@ [dataCell setFont:tableFont]; [dataCell setLineBreakMode:NSLineBreakByTruncatingTail]; + [dataCell setFormatter:[[SPDataCellFormatter new] autorelease]]; + + // Set field length limit if field is a varchar to match varchar length + if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"] + || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"bit"]) { + [[dataCell formatter] setTextLimit:[[columnDefinition objectForKey:@"char_length"] integerValue]]; + } + + // Set field type for validations + [[dataCell formatter] setFieldType:[columnDefinition objectForKey:@"type"]]; [theCol setDataCell:dataCell]; [[theCol headerCell] setStringValue:[columnDefinition objectForKey:@"name"]]; @@ -2249,10 +2259,19 @@ NSArray *editStatus = [self fieldEditStatusForRow:rowIndex andColumn:[aTableColumn identifier]]; isFieldEditable = ([[editStatus objectAtIndex:0] integerValue] == 1) ? YES : NO; - // Set max text length - if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"] - && [columnDefinition valueForKey:@"char_length"]) - [fieldEditor setTextMaxLength:[[columnDefinition valueForKey:@"char_length"] integerValue]]; + NSString *fieldType = nil; + NSUInteger *fieldLength = 0; + NSString *fieldEncoding = nil; + // Retrieve the column defintion + fieldType = [columnDefinition objectForKey:@"type"]; + if([columnDefinition objectForKey:@"char_length"]) + fieldLength = [[columnDefinition objectForKey:@"char_length"] integerValue]; + if([columnDefinition objectForKey:@"charset_name"] && ![[columnDefinition objectForKey:@"charset_name"] isEqualToString:@"binary"]) + fieldEncoding = [columnDefinition objectForKey:@"charset_name"]; + + [fieldEditor setTextMaxLength:fieldLength]; + [fieldEditor setFieldType:(fieldType==nil) ? @"" : fieldType]; + [fieldEditor setFieldEncoding:(fieldEncoding==nil) ? @"" : fieldEncoding]; id originalData = [resultData cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]]; if ([originalData isNSNull]) originalData = [prefs objectForKey:SPNullValue]; diff --git a/Source/SPDataCellFormatter.m b/Source/SPDataCellFormatter.m index 9e7944f8..f82bad1e 100644 --- a/Source/SPDataCellFormatter.m +++ b/Source/SPDataCellFormatter.m @@ -94,18 +94,14 @@ // Check for BIT fields whether 1 or 0 are typed if(fieldType && [fieldType length] && [[fieldType uppercaseString] isEqualToString:@"BIT"]) { - if(partialString == nil || ![partialString length]) return YES; + if([partialString rangeOfCharacterFromSet:[[NSCharacterSet characterSetWithCharactersInString:@"01"] invertedSet]].location != NSNotFound) { + [SPTooltip showWithObject:NSLocalizedString(@"For BIT fields only “1” or “0” are allowed.", @"For BIT fields only “1” or “0” are allowed.")]; + return NO; + } - // TODO HansJB return YES; - // if() { - // [SPTooltip showWithObject:NSLocalizedString(@"For BIT fields only “1” or “0” are allowed.", @"For BIT fields only “1” or “0” are allowed.")]; - // return NO; - // } - } - return YES; } |