aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableContentDataSource.m
diff options
context:
space:
mode:
authorMichael Heins <michael.heins@joltup.com>2017-05-18 08:29:53 -0600
committerMax Lohrmann <dmoagx@users.noreply.github.com>2017-05-19 02:15:30 +0200
commit0116bcecf0b1ebb66be0179a1a8e73670814dee1 (patch)
tree9a85e00a795b1d375a366183503dbd7705fca394 /Source/SPTableContentDataSource.m
parent43926b0d48a341335538bb7b368c3fa4a73ddadb (diff)
downloadsequelpro-0116bcecf0b1ebb66be0179a1a8e73670814dee1.tar.gz
sequelpro-0116bcecf0b1ebb66be0179a1a8e73670814dee1.tar.bz2
sequelpro-0116bcecf0b1ebb66be0179a1a8e73670814dee1.zip
Hex edit for binary columns
Implement the ability to edit binary columns as hex data. Check input string for valid hex values; if invalid input, open alert sheet.
Diffstat (limited to 'Source/SPTableContentDataSource.m')
-rw-r--r--Source/SPTableContentDataSource.m29
1 files changed, 28 insertions, 1 deletions
diff --git a/Source/SPTableContentDataSource.m b/Source/SPTableContentDataSource.m
index 56e8df71..a005cdce 100644
--- a/Source/SPTableContentDataSource.m
+++ b/Source/SPTableContentDataSource.m
@@ -33,6 +33,7 @@
#import "SPDataStorage.h"
#import "SPCopyTable.h"
#import "SPTablesList.h"
+#import "SPAlertSheets.h"
#import <pthread.h>
#import <SPMySQL/SPMySQL.h>
@@ -177,6 +178,11 @@
return;
}
+ NSInteger columnIndex = [[tableColumn identifier] integerValue];
+ NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex];
+
+ NSString *columnType = [columnDefinition objectForKey:@"typegrouping"];
+
// Catch editing events in the row and if the row isn't currently being edited,
// start an edit. This allows edits including enum changes to save correctly.
if (isEditingRow && [tableContentView selectedRow] != currentlyEditingRow) {
@@ -192,7 +198,28 @@
NSDictionary *column = NSArrayObjectAtIndex(dataColumns, [[tableColumn identifier] integerValue]);
- if (object) {
+ if ([columnType isEqualToString:@"binary"] && [object isKindOfClass: [NSString class]]) {
+ //
+ // This is a binary object being edited as a hex string. (Is there a better
+ // way to detect this case?)
+ // Convert the string back to binary, checking for errors.
+ //
+ NSData *data = [NSData dataWithHexString: object];
+ if (data) {
+ object = data;
+ [tableValues replaceObjectInRow:rowIndex column:[[tableColumn identifier] integerValue] withObject:object];
+ }
+ else {
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Error", @"error"),
+ [tableDocumentInstance parentWindow],
+ NSLocalizedString(@"Bad hexadecimal data input.", @"Bad hexadecimal data input.")
+ );
+ return;
+
+ }
+ }
+ else if (object) {
// Restore NULLs if necessary
if ([object isEqualToString:[prefs objectForKey:SPNullValue]] && [[column objectForKey:@"null"] boolValue]) {
object = [NSNull null];