aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-09-16 12:09:35 +0000
committerBibiko <bibiko@eva.mpg.de>2010-09-16 12:09:35 +0000
commit902695800b7a760c138bc84ae982d5c5b826a437 (patch)
tree121268fec3959566785809c4e095a3b94fea8c53 /Source
parent11f9f5a153ca055e4f104dc6494745e1c4f38518 (diff)
downloadsequelpro-902695800b7a760c138bc84ae982d5c5b826a437.tar.gz
sequelpro-902695800b7a760c138bc84ae982d5c5b826a437.tar.bz2
sequelpro-902695800b7a760c138bc84ae982d5c5b826a437.zip
• BIT Field Sheet Editor now can handle NULL values
• Field Editor Sheet field name label also displays NOT NULL if set
Diffstat (limited to 'Source')
-rw-r--r--Source/SPCustomQuery.m5
-rw-r--r--Source/SPFieldEditorController.h4
-rw-r--r--Source/SPFieldEditorController.m65
-rw-r--r--Source/SPTableContent.m5
4 files changed, 75 insertions, 4 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index 2a805da2..ae1b01c0 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -2262,16 +2262,21 @@
NSString *fieldType = nil;
NSUInteger *fieldLength = 0;
NSString *fieldEncoding = nil;
+ BOOL allowNULL = YES;
+
// 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"];
+ if([columnDefinition objectForKey:@"null"])
+ allowNULL = (![[columnDefinition objectForKey:@"null"] integerValue]);
[fieldEditor setTextMaxLength:fieldLength];
[fieldEditor setFieldType:(fieldType==nil) ? @"" : fieldType];
[fieldEditor setFieldEncoding:(fieldEncoding==nil) ? @"" : fieldEncoding];
+ [fieldEditor setAllowNULL:allowNULL];
id originalData = [resultData cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]];
if ([originalData isNSNull]) originalData = [prefs objectForKey:SPNullValue];
diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h
index ba44469e..7c5c6c9a 100644
--- a/Source/SPFieldEditorController.h
+++ b/Source/SPFieldEditorController.h
@@ -48,6 +48,7 @@
IBOutlet NSTextField *bitSheetOctalTextField;
IBOutlet NSButton *bitSheetOkButton;
IBOutlet NSButton *bitSheetCloseButton;
+ IBOutlet NSButton *bitSheetNULLButton;
IBOutlet NSButton *bitSheetBitButton0;
IBOutlet NSButton *bitSheetBitButton1;
IBOutlet NSButton *bitSheetBitButton2;
@@ -125,6 +126,7 @@
BOOL editSheetWillBeInitialized;
BOOL _isBlob;
BOOL _isEditable;
+ BOOL _allowNULL;
NSInteger quickLookCloseMarker;
NSStringEncoding encoding;
NSString *fieldType;
@@ -161,6 +163,7 @@
- (IBAction)bitSheetSelectBit0:(id)sender;
- (IBAction)bitSheetBitButtonWasClicked:(id)sender;
- (IBAction)bitSheetOperatorButtonWasClicked:(id)sender;
+- (IBAction)setToNull:(id)sender;
- (void)updateBitSheet;
- (id)editWithObject:(id)data fieldName:(NSString*)fieldName usingEncoding:(NSStringEncoding)anEncoding
@@ -169,6 +172,7 @@
- (void)setTextMaxLength:(unsigned long long)length;
- (void)setFieldType:(NSString*)aType;
- (void)setFieldEncoding:(NSString*)aEncoding;
+- (void)setAllowNULL:(BOOL)allowNULL;
- (void)processPasteImageData;
- (void)processUpdatedImageData:(NSData *)data;
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index fc3f6eec..b8959ec8 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -46,6 +46,7 @@
stringValue = nil;
_isEditable = NO;
_isBlob = NO;
+ _allowNULL = YES;
prefs = [NSUserDefaults standardUserDefaults];
@@ -146,6 +147,11 @@
fieldEncoding = aEncoding;
}
+- (void)setAllowNULL:(BOOL)allowNULL
+{
+ _allowNULL = allowNULL;
+}
+
- (id)editWithObject:(id)data fieldName:(NSString*)fieldName usingEncoding:(NSStringEncoding)anEncoding
isObjectBlob:(BOOL)isFieldBlob isEditable:(BOOL)isEditable withWindow:(NSWindow *)theWindow
{
@@ -157,12 +163,14 @@
// Set field label
NSMutableString *label = [NSMutableString string];
[label appendFormat:@"“%@”", fieldName];
- if([fieldType length] || maxTextLength > 0 || [fieldEncoding length])
+ if([fieldType length] || maxTextLength > 0 || [fieldEncoding length] || !_allowNULL)
[label appendString:@" – "];
if([fieldType length])
[label appendString:fieldType];
if(maxTextLength > 0)
[label appendFormat:@"(%ld) ", maxTextLength];
+ if(!_allowNULL)
+ [label appendString:@"NOT NULL "];
if([fieldEncoding length])
[label appendString:fieldEncoding];
@@ -170,14 +178,25 @@
sheetEditData = [(NSString*)data retain];
+ [bitSheetNULLButton setEnabled:_allowNULL];
+
+ // Check for NULL
+ if([sheetEditData isEqualToString:[prefs objectForKey:SPNullValue]]) {
+ [bitSheetNULLButton setState:NSOnState];
+ [self setToNull:bitSheetNULLButton];
+ } else {
+ [bitSheetNULLButton setState:NSOffState];
+ }
+
[bitSheetFieldName setStringValue:label];
// Init according bit check boxes
NSInteger i = 0;
NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength;
- for(i=0; i<maxBit; i++)
- [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]]
- setState:([sheetEditData characterAtIndex:(maxBit-i-1)] == '1') ? NSOnState : NSOffState];
+ if([bitSheetNULLButton state] == NSOffState)
+ for(i=0; i<maxBit; i++)
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]]
+ setState:([sheetEditData characterAtIndex:(maxBit-i-1)] == '1') ? NSOnState : NSOffState];
for(i=maxBit; i<64; i++)
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setEnabled:NO];
@@ -909,6 +928,20 @@
NSInteger i = 0;
NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength;
+
+ if([bitSheetNULLButton state] == NSOnState) {
+ if ( sheetEditData != nil ) {
+ [sheetEditData release];
+ }
+
+ NSString *nullString = [prefs objectForKey:SPNullValue];
+ sheetEditData = [[NSString stringWithString:nullString] retain];
+ [bitSheetIntegerTextField setStringValue:nullString];
+ [bitSheetHexTextField setStringValue:nullString];
+ [bitSheetOctalTextField setStringValue:nullString];
+ return;
+ }
+
NSMutableString *bitString = [NSMutableString string];
[bitString setString:@""];
for(i=0; i<maxBit; i++) [bitString appendString:@"0"];
@@ -1005,6 +1038,30 @@
[[self window] makeFirstResponder:[self valueForKeyPath:@"bitSheetBitButton0"]];
}
+- (IBAction)setToNull:(id)sender
+{
+
+ NSInteger i;
+ NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength;
+
+ if([sender state] == NSOnState) {
+ for(i=0; i<maxBit; i++)
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setEnabled:NO];
+ [bitSheetHexTextField setEnabled:NO];
+ [bitSheetIntegerTextField setEnabled:NO];
+ [bitSheetOctalTextField setEnabled:NO];
+ } else {
+ for(i=0; i<maxBit; i++)
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setEnabled:YES];
+ [bitSheetHexTextField setEnabled:YES];
+ [bitSheetIntegerTextField setEnabled:YES];
+ [bitSheetOctalTextField setEnabled:YES];
+ }
+
+ [self updateBitSheet];
+
+}
+
- (IBAction)bitSheetBitButtonWasClicked:(id)sender
{
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 99e34af1..cff8a675 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -3522,12 +3522,16 @@
NSString *fieldType = nil;
NSUInteger *fieldLength = 0;
NSString *fieldEncoding = nil;
+ BOOL allowNULL = YES;
+
// Retrieve the column defintion
for(id c in cqColumnDefinition) {
if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:[aTableColumn identifier]]) {
fieldType = [c objectForKey:@"type"];
if([c objectForKey:@"char_length"])
fieldLength = [[c objectForKey:@"char_length"] integerValue];
+ if([c objectForKey:@"null"])
+ allowNULL = (![[c objectForKey:@"null"] integerValue]);
if([c objectForKey:@"charset_name"] && ![[c objectForKey:@"charset_name"] isEqualToString:@"binary"])
fieldEncoding = [c objectForKey:@"charset_name"];
break;
@@ -3539,6 +3543,7 @@
[fieldEditor setTextMaxLength:fieldLength];
[fieldEditor setFieldType:(fieldType==nil) ? @"" : fieldType];
[fieldEditor setFieldEncoding:(fieldEncoding==nil) ? @"" : fieldEncoding];
+ [fieldEditor setAllowNULL:allowNULL];
id cellValue = [tableValues cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]];
if ([cellValue isNSNull]) cellValue = [NSString stringWithString:[prefs objectForKey:SPNullValue]];