aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFieldEditorController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPFieldEditorController.m')
-rw-r--r--Source/SPFieldEditorController.m26
1 files changed, 23 insertions, 3 deletions
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index a32f32dc..19668d74 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -37,6 +37,7 @@
#include <objc/objc-runtime.h>
#import "SPCustomQuery.h"
#import "SPTableContent.h"
+#import "SPJSONFormatter.h"
#import <SPMySQL/SPMySQL.h>
@@ -237,6 +238,7 @@ typedef enum {
callerInstance = sender;
_isGeometry = ([[fieldType uppercaseString] isEqualToString:@"GEOMETRY"]) ? YES : NO;
+ _isJSON = ([[fieldType uppercaseString] isEqualToString:SPMySQLJsonType]);
// Set field label
NSMutableString *label = [NSMutableString string];
@@ -250,7 +252,7 @@ typedef enum {
[label appendString:fieldType];
//skip length for JSON type since it's a constant and MySQL doesn't display it either
- if (maxTextLength > 0 && ![[fieldType uppercaseString] isEqualToString:SPMySQLJsonType])
+ if (maxTextLength > 0 && !_isJSON)
[label appendFormat:@"(%lld) ", maxTextLength];
if (!_allowNULL)
@@ -353,7 +355,8 @@ typedef enum {
encoding = anEncoding;
- _isBlob = isFieldBlob;
+ // we don't want the hex/image controls for JSON
+ _isBlob = (!_isJSON && isFieldBlob);
BOOL isBinary = ([[fieldType uppercaseString] isEqualToString:@"BINARY"] || [[fieldType uppercaseString] isEqualToString:@"VARBINARY"]);
@@ -443,7 +446,18 @@ typedef enum {
[editTextScrollView setHidden:NO];
}
else {
- stringValue = [sheetEditData retain];
+ // If the input is a JSON type column we can format it.
+ // Since MySQL internally stores JSON in binary, it does not retain any formatting
+ do {
+ if(_isJSON) {
+ NSString *formatted = [SPJSONFormatter stringByFormattingString:sheetEditData];
+ if(formatted) {
+ stringValue = [formatted retain];
+ break;
+ }
+ }
+ stringValue = [sheetEditData retain];
+ } while(0);
[hexTextView setString:@""];
@@ -652,6 +666,12 @@ typedef enum {
if(callerInstance) {
id returnData = ( editSheetReturnCode && _isEditable ) ? (_isGeometry) ? [editTextView string] : sheetEditData : nil;
+ //for MySQLs JSON type remove the formatting again, since it won't be stored anyway
+ if(_isJSON) {
+ NSString *unformatted = [SPJSONFormatter stringByUnformattingString:returnData];
+ if(unformatted) returnData = unformatted;
+ }
+
#ifdef SP_CODA /* patch */
if ( [callerInstance isKindOfClass:[SPCustomQuery class]] )
[(SPCustomQuery*)callerInstance processFieldEditorResult:returnData contextInfo:contextInfo];