Skip to content

Commit

Permalink
Add basic support for JSON type (part of #2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoagx committed Nov 15, 2015
1 parent 8d435db commit 1f7684a
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
MYSQL_TYPE_BIT,
MYSQL_TYPE_NEWDECIMAL=246,
MYSQL_TYPE_TIMESTAMP2,
MYSQL_TYPE_DATETIME2,
MYSQL_TYPE_TIME2,
MYSQL_TYPE_JSON=245,
MYSQL_TYPE_NEWDECIMAL=246,
MYSQL_TYPE_ENUM=247,
MYSQL_TYPE_SET=248,
MYSQL_TYPE_TINY_BLOB=249,
Expand Down
1 change: 1 addition & 0 deletions Frameworks/SPMySQLFramework/SPMySQLDataTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ extern NSString *SPMySQLMultiPointType;
extern NSString *SPMySQLMultiLineStringType;
extern NSString *SPMySQLMultiPolygonType;
extern NSString *SPMySQLGeometryCollectionType;
extern NSString *SPMySQLJsonType;
1 change: 1 addition & 0 deletions Frameworks/SPMySQLFramework/SPMySQLDataTypes.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@
NSString *SPMySQLMultiLineStringType = @"MULTILINESTRING";
NSString *SPMySQLMultiPolygonType = @"MULTIPOLYGON";
NSString *SPMySQLGeometryCollectionType = @"GEOMETRYCOLLECTION";
NSString *SPMySQLJsonType = @"JSON";
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ + (void)_initializeDataConversion
fieldProcessingMap[MYSQL_TYPE_NEWDATE] = SPMySQLResultFieldAsString;
fieldProcessingMap[MYSQL_TYPE_VARCHAR] = SPMySQLResultFieldAsString;
fieldProcessingMap[MYSQL_TYPE_BIT] = SPMySQLResultFieldAsBit;
fieldProcessingMap[MYSQL_TYPE_JSON] = SPMySQLResultFieldAsString;
fieldProcessingMap[MYSQL_TYPE_NEWDECIMAL] = SPMySQLResultFieldAsString;
fieldProcessingMap[MYSQL_TYPE_ENUM] = SPMySQLResultFieldAsString;
fieldProcessingMap[MYSQL_TYPE_SET] = SPMySQLResultFieldAsString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ - (NSString *)_mysqlTypeToStringForType:(NSUInteger)type withCharsetNr:(NSUInteg

switch (type) {

case FIELD_TYPE_BIT:
case MYSQL_TYPE_BIT:
return @"BIT";

case MYSQL_TYPE_DECIMAL:
Expand Down Expand Up @@ -475,6 +475,9 @@ - (NSString *)_mysqlTypeToStringForType:(NSUInteger)type withCharsetNr:(NSUInteg

case MYSQL_TYPE_GEOMETRY:
return @"GEOMETRY";

case MYSQL_TYPE_JSON:
return @"JSON";

default:
return @"UNKNOWN";
Expand Down
64 changes: 64 additions & 0 deletions Resources/Plists/CompletionTokens.plist
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
<string>ISSUER</string>
<string>ITERATE</string>
<string>JOIN</string>
<string>JSON</string>
<string>KEY</string>
<string>KEYS</string>
<string>KEY_BLOCK_SIZE</string>
Expand Down Expand Up @@ -834,6 +835,27 @@
<string>ISSIMPLE</string>
<string>IS_FREE_LOCK</string>
<string>IS_USED_LOCK</string>
<string>JSON_APPEND</string>
<string>JSON_ARRAY_APPEND</string>
<string>JSON_ARRAY_INSERT</string>
<string>JSON_ARRAY</string>
<string>JSON_CONTAINS_PATH</string>
<string>JSON_CONTAINS</string>
<string>JSON_DEPTH</string>
<string>JSON_EXTRACT</string>
<string>JSON_INSERT</string>
<string>JSON_KEYS</string>
<string>JSON_LENGTH</string>
<string>JSON_MERGE</string>
<string>JSON_OBJECT</string>
<string>JSON_QUOTE</string>
<string>JSON_REMOVE</string>
<string>JSON_REPLACE</string>
<string>JSON_SEARCH</string>
<string>JSON_SET</string>
<string>JSON_TYPE</string>
<string>JSON_UNQUOTE</string>
<string>JSON_VALID</string>
<string>LAST_DAY</string>
<string>LAST_INSERT_ID</string>
<string>LCASE</string>
Expand Down Expand Up @@ -1162,6 +1184,48 @@
<string>${1:bits}, ${2:str1}</string>
<key>FIND_IN_SET</key>
<string>${1:str}, ${2:strlist}</string>
<key>JSON_APPEND</key>
<string>${1:json_doc}, ${2:path}, ${3:val}${4:, ${5:path}, ${6:val}${7:, ${8:...}}}</string>
<key>JSON_ARRAY_APPEND</key>
<string>${1:json_doc}, ${2:path}, ${3:val}${4:, ${5:path}, ${6:val}${7:, ${8:...}}}</string>
<key>JSON_ARRAY_INSERT</key>
<string>${1:json_doc}, ${2:path}, ${3:val}${4:, ${5:path}, ${6:val}${7:, ${8:...}}}</string>
<key>JSON_ARRAY</key>
<string>${1:${2:val} ${3:, ${4:val}${5:, ${6:...}}}}</string>
<key>JSON_CONTAINS_PATH</key>
<string>${1:json_doc}, ${2:¦'one'¦'all'¦}, ${3:path}${4:, ${5:path}${6:, ${7:...}}}</string>
<key>JSON_CONTAINS</key>
<string>${1:json_doc}, ${2:val}${3:, ${4:path}}</string>
<key>JSON_DEPTH</key>
<string>${1:json_doc}</string>
<key>JSON_EXTRACT</key>
<string>${1:json_doc}, ${2:path}${3:, ${4:path}${5:, ${6:...}}}</string>
<key>JSON_INSERT</key>
<string>${1:json_doc}, ${2:path}, ${3:val}${4:, ${5:path}, ${6:val}${7:, ${8:...}}}</string>
<key>JSON_KEYS</key>
<string>${1:json_doc}${2:, ${3:path}}</string>
<key>JSON_LENGTH</key>
<string>${1:json_doc}${2:, ${3:path}}</string>
<key>JSON_MERGE</key>
<string>${1:json_doc}, ${2:json_doc}${3:, ${4:...}}</string>
<key>JSON_OBJECT</key>
<string>${1:${2:key}, ${3:val}${4:, ${5:key}, ${6:val}${7:, ${8:...}}}}</string>
<key>JSON_QUOTE</key>
<string>${1:json_val}</string>
<key>JSON_REMOVE</key>
<string>${1:json_doc}, ${2:path}${3:, ${4:path}${5:, ${6:...}}}</string>
<key>JSON_REPLACE</key>
<string>${1:json_doc}, ${2:path}, ${3:val}${4:, ${5:path}, ${6:val}${7:, ${8:...}}}</string>
<key>JSON_SEARCH</key>
<string>${1:json_doc}, ${2:¦'one'¦'all'¦}, ${3:search_str}${4:, ${5:escape_char}${6:, ${7:path${8:, ${9:...}}}}}</string>
<key>JSON_SET</key>
<string>${1:json_doc}, ${2:path}, ${3:val}${4:, ${5:path}, ${6:val}${7:, ${8:...}}}</string>
<key>JSON_TYPE</key>
<string>${1:json_val}</string>
<key>JSON_UNQUOTE</key>
<string>${1:val}</string>
<key>JSON_VALID</key>
<string>${1:val}</string>
</dict>
</dict>
</plist>
3 changes: 2 additions & 1 deletion Source/SPEditorTokens.l
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ numeric ([+-]?(([0-9]+\.[0-9]+)|([0-9]*\.[0-9]+)|([0-9]+))(e[+-]?[0-9]+)?)
ops "+"|"-"|"*"|"/"
word [a-z_\.0-9\x80-\xEF@]
variable @{1,2}[a-z_\.0-9\x80-\xEF$]+
keyworda (G(R(OUP{s}BY|ANT(S)?)|E(NERAL|T_FORMAT|OMETRY(COLLECTION)?)|LOBAL)|B(Y(TE)?|TREE|I(GINT|N(LOG|ARY)|T)|O(TH|OL(EAN)?)|E(GIN|TWEEN|FORE)|LOB|ACKUP{s}TABLE)|H(IGH_PRIORITY|O(ST(S)?|UR(_(MI(NUTE|CROSECOND)|SECOND))?)|ELP|A(SH|NDLER|VING))|C(R(OSS|EATE)|H(ECK(SUM)?|A(R(SET|ACTER)?|NGE(D)?|IN))|IPHER|O(M(M(IT(TED)?|ENT)|P(RESSED|LETION|ACT))|N(S(TRAINT(_(SCHEMA|NAME|CATALOG))?|ISTENT)|NECTION|CURRENT|T(RIBUTORS|INUE|AINS)|DITION|VERT)|DE|L(UMN(S|_(NAME|FORMAT))?|LATE)|ALESCE{s}PARTITION)|U(R(RENT_(TIME(STAMP)?|DATE|USER)|SOR(_NAME)?)|BE)|L(IENT|OSE|ASS_ORIGIN)|A(S(CADE(D)?|E)|CHE{s}INDEX|TALOG_NAME|LL))|I(GNORE(_SERVER_IDS)?|MPORT{s}TABLESPACE|S(SUER|OLATION)?|N(S(TALL({s}PLUGIN)?|E(RT(_METHOD)?|NSITIVE))|N(O(BASE|DB)|ER)|T(1|2|8|3|O({s}(DUMP|OUT)FILE)?|4|E(RVAL|GER))?|ITIAL_SIZE|OUT|DEX(ES)?|VOKER|FILE)?|TERATE|O_THREAD|DENTIFIED|F)|D(ROP|YNAMIC|I(RECTORY|S(CARD{s}TABLESPACE|TINCT(ROW)?|K|ABLE{s}KEYS)|V)|O(UBLE)?|U(MPFILE|PLICATE|AL)|E(S(C(RIBE)?|_KEY_FILE)|C(IMAL|LARE)?|TERMINISTIC|F(INER|AULT)|L(ETE|AY(_KEY_WRITE|ED))|ALLOCATE)|A(Y(_(MI(NUTE|CROSECOND)|SECOND|HOUR))?|T(E(TIME)?|A(BASE(S)?|FILE)?)))|JOIN|E(RRORS|X(TEN(T_SIZE|DED)|I(STS|T)|P(LAIN|ANSION)|ECUTE)|SCAPE(D{s}BY)?|N(GINE(S)?|CLOSED{s}BY|D(S)?|UM|ABLE{s}KEYS)|VE(RY|NT)|LSE(IF)?|ACH)|K(ILL({s}(CONNECTION|QUERY))?|EY(S|_BLOCK_SIZE)?)|F(R(OM|AC_SECOND)|I(RST|XED|LE)|O(R(CE|EIGN)?|UND)|U(NCTION|LL(TEXT)?)|ETCH|L(OAT(8|4)?|USH)|A(ST|LSE))|A(G(GREGATE|AINST)|S(C(II)?|ENSITIVE)?|N(Y|D|ALYZE)|C(CESSIBLE|TION)|T|DD|UT(HORS|O(_INCREMENT|EXTEND_SIZE))|VG(_ROW_LENGTH)?|FTER|L(GORITHM|TER|L)))
keyworda (G(R(OUP{s}BY|ANT(S)?)|E(NERAL|T_FORMAT|OMETRY(COLLECTION)?)|LOBAL)|B(Y(TE)?|TREE|I(GINT|N(LOG|ARY)|T)|O(TH|OL(EAN)?)|E(GIN|TWEEN|FORE)|LOB|ACKUP{s}TABLE)|H(IGH_PRIORITY|O(ST(S)?|UR(_(MI(NUTE|CROSECOND)|SECOND))?)|ELP|A(SH|NDLER|VING))|C(R(OSS|EATE)|H(ECK(SUM)?|A(R(SET|ACTER)?|NGE(D)?|IN))|IPHER|O(M(M(IT(TED)?|ENT)|P(RESSED|LETION|ACT))|N(S(TRAINT(_(SCHEMA|NAME|CATALOG))?|ISTENT)|NECTION|CURRENT|T(RIBUTORS|INUE|AINS)|DITION|VERT)|DE|L(UMN(S|_(NAME|FORMAT))?|LATE)|ALESCE{s}PARTITION)|U(R(RENT_(TIME(STAMP)?|DATE|USER)|SOR(_NAME)?)|BE)|L(IENT|OSE|ASS_ORIGIN)|A(S(CADE(D)?|E)|CHE{s}INDEX|TALOG_NAME|LL))|I(GNORE(_SERVER_IDS)?|MPORT{s}TABLESPACE|S(SUER|OLATION)?|N(S(TALL({s}PLUGIN)?|E(RT(_METHOD)?|NSITIVE))|N(O(BASE|DB)|ER)|T(1|2|8|3|O({s}(DUMP|OUT)FILE)?|4|E(RVAL|GER))?|ITIAL_SIZE|OUT|DEX(ES)?|VOKER|FILE)?|TERATE|O_THREAD|DENTIFIED|F)|D(ROP|YNAMIC|I(RECTORY|S(CARD{s}TABLESPACE|TINCT(ROW)?|K|ABLE{s}KEYS)|V)|O(UBLE)?|U(MPFILE|PLICATE|AL)|E(S(C(RIBE)?|_KEY_FILE)|C(IMAL|LARE)?|TERMINISTIC|F(INER|AULT)|L(ETE|AY(_KEY_WRITE|ED))|ALLOCATE)|A(Y(_(MI(NUTE|CROSECOND)|SECOND|HOUR))?|T(E(TIME)?|A(BASE(S)?|FILE)?)))|J(OI|SO)N|E(RRORS|X(TEN(T_SIZE|DED)|I(STS|T)|P(LAIN|ANSION)|ECUTE)|SCAPE(D{s}BY)?|N(GINE(S)?|CLOSED{s}BY|D(S)?|UM|ABLE{s}KEYS)|VE(RY|NT)|LSE(IF)?|ACH)|K(ILL({s}(CONNECTION|QUERY))?|EY(S|_BLOCK_SIZE)?)|F(R(OM|AC_SECOND)|I(RST|XED|LE)|O(R(CE|EIGN)?|UND)|U(NCTION|LL(TEXT)?)|ETCH|L(OAT(8|4)?|USH)|A(ST|LSE))|A(G(GREGATE|AINST)|S(C(II)?|ENSITIVE)?|N(Y|D|ALYZE)|C(CESSIBLE|TION)|T|DD|UT(HORS|O(_INCREMENT|EXTEND_SIZE))|VG(_ROW_LENGTH)?|FTER|L(GORITHM|TER|L)))
keywordl (R(TREE|IGHT|O(UTINE|W(S|_FORMAT)?|LL(BACK|UP))|E(GEXP|MOVE{s}PARTITIONING|BUILD{s}PARTITION|S(T(RICT|ORE{s}TABLE)|IGNAL|UME|ET)|NAME|COVER|TURN(S)?|ORGANIZE{s}PARTITION|D(O(_BUFFER_SIZE|FILE)|UNDANT)|P(EAT(ABLE)?|L(ICATION|ACE)|AIR)|VOKE|QUIRE|FERENCES|L(OAD|EASE|AY_(THREAD|LOG_(POS|FILE)))|A(D(S|_(ONLY|WRITE))?|L))|LIKE|ANGE)|M(YSQL_ERRNO|I(GRATE|N(_ROWS|UTE(_(MICROSECOND|SECOND))?)|CROSECOND|DDLEINT)|O(NTH|D(IF(Y|IES)|E)?)|U(TEX|LTI(PO(INT|LYGON)|LINESTRING))|E(RGE|MORY|SSAGE_TEXT|DIUM(BLOB|TEXT|INT)?)|A(X(_(ROWS|SIZE|CONNECTIONS_PER_HOUR|U(SER_CONNECTIONS|PDATES_PER_HOUR)|QUERIES_PER_HOUR)|VALUE)|STER(_(S(SL(_(C(IPHER|ERT|A(PATH)?)|VERIFY_SERVER_CERT|KEY))?|ERVER_ID)|H(OST|EARTBEAT_PERIOD)|CONNECT_RETRY|USER|P(ORT|ASSWORD)|LOG_(POS|FILE)))?|TCH))|N(CHAR|O(NE|_W(RITE_TO_BINLOG|AIT)|T|DEGROUP)?|DB(CLUSTER)?|U(MERIC|LL)|E(XT|W)|VARCHAR|A(ME(S)?|T(IONAL|URAL)))|O(R(DER{s}BY)?|N(({s}DUPLICATE{s}KEY{s}UPDATE)?|E(_SHOT)?|LINE)?|UT(ER|FILE)?|P(TI(MIZE|ON(S|ALLY)?)|EN)|FF(SET|LINE)|WNER|LD_PASSWORD)|P(R(I(MARY|VILEGES)|OCE(SS|DURE{s}(ANALYSE)?)|E(SERVE|CISION|PARE|V))|HASE|O(RT|INT|LYGON)|URGE|A(R(SER|TI(TION(S|ING)?|AL))|SSWORD|CK_KEYS))|QU(ICK|ERY|ARTER)|L(I(MIT|ST|NE(S(TRING)?|AR)|KE)|O(G(S|FILE({s}GROUP))|NG(BLOB|TEXT)?|C(K(S)?|AL(TIME(STAMP)?)?)|OP|W_PRIORITY|AD{s}(DATA|INDEX{s}INTO{s}CACHE|XML))|E(SS|VEL|FT|A(DING|VE(S)?))|A(ST|NGUAGE)))
keywords (X(OR|509|A)|S(MALLINT|SL|H(OW({s}(E(NGINE(S)?|RRORS)|M(ASTER|UTEX)|BINLOG|GRANTS|INNODB|P(RIVILEGES|ROFILE(S)?|ROCEDURE{s}CODE)|SLAVE{s}(HOSTS|STATUS)|TRIGGERS|VARIABLES|WARNINGS|(FULL{s})?PROCESSLIST|FIELDS|PLUGIN(S)?|STORAGE{s}ENGINES|TABLE{s}TYPES|CO(LUMNS|LLATION)|BINLOG{s}EVENTS))?|UTDOWN|ARE)|NAPSHOT|CHE(MA(S|_NAME)?|DULE(R)?)|T(R(ING|AIGHT_JOIN)|O(RAGE|P)|A(RT(S|ING{s}BY)?|TUS))|I(GN(ED|AL)|MPLE)|O(ME|NAME|CKET|UNDS)|U(B(CLASS_ORIGIN|JECT|PARTITION(S)?)|SPEND|PER)|P(ECIFIC|ATIAL)|E(R(IAL(IZABLE)?|VER)|SSION|NSITIVE|C(OND(_MICROSECOND)?|URITY)|T({s}(PASSWORD|NAMES|ONE_SHOT))?|PARATOR|LECT)|QL(STATE|_(MAX_JOIN_SIZE|B(IG_(RESULT|SELECTS|TABLES)|UFFER_RESULT)|S(MALL_RESULT|ELECT_LIMIT|LAVE_SKIP_COUNTER|AFE_UPDATES)|NO_CACHE|CA(CHE|LC_FOUND_ROWS)|T(SI_(M(INUTE|ONTH)|SECOND|HOUR|YEAR|DAY|QUARTER|FRAC_SECOND|WEEK)|HREAD)|QUOTE_SHOW_CREATE|WARNINGS|LO(G_(BIN|OFF|UPDATE)|W_PRIORITY_UPDATES)|AUTO_IS_NULL)|EXCEPTION|WARNING)?|L(OW|AVE)|AVEPOINT)|YEAR(_MONTH)?|T(R(IGGER(S)?|U(NCATE|E)|A(NSACTION|ILING))|H(EN|AN)|YPE|I(ME(STAMP(DIFF|ADD)?)?|NY(BLOB|TEXT|INT))|O|E(RMINATED{s}BY|XT|MP(TABLE|ORARY))|ABLE(S(PACE)?|_NAME)?)|ZEROFILL|U(S(ING|E(R(_RESOURCES)?|_FRM)?|AGE)|N(SIGNED|COMMITTED|TIL|I(NSTALL({s}PLUGIN)?|CODE|ON|QUE)|D(O(_BUFFER_SIZE|FILE)?|EFINED)|KNOWN|LOCK)|TC_(TIME(STAMP)?|DATE)|P(GRADE|DATE))|V(IEW|A(R(BINARY|YING|CHAR(ACTER)?|IABLES)|LUE(S)?))|W(R(ITE|APPER)|H(ILE|E(RE|N))|ITH({s}PARSER)?|ORK|EEK|A(RNINGS|IT)))

Expand Down Expand Up @@ -348,6 +348,7 @@ ISOLATION
ISSUER
ITERATE
JOIN
JSON
KEY
KEYS
KEY_BLOCK_SIZE
Expand Down
3 changes: 2 additions & 1 deletion Source/SPTableData.m
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,8 @@ - (NSDictionary *) parseFieldDefinitionStringParts:(NSArray *)definitionParts
} else if ([detailString isEqualToString:@"ENUM"] || [detailString isEqualToString:@"SET"]) {
[fieldDetails setObject:@"enum" forKey:@"typegrouping"];
} else if ([detailString isEqualToString:@"TINYTEXT"] || [detailString isEqualToString:@"TEXT"]
|| [detailString isEqualToString:@"MEDIUMTEXT"] || [detailString isEqualToString:@"LONGTEXT"]) {
|| [detailString isEqualToString:@"MEDIUMTEXT"] || [detailString isEqualToString:@"LONGTEXT"]
|| [detailString isEqualToString:@"JSON"]) { // JSON is seen as a text type by us, but works a bit different (e.g. encoding is always "utf8mb4")
[fieldDetails setObject:@"textdata" forKey:@"typegrouping"];
} else if ([detailString isEqualToString:@"POINT"] || [detailString isEqualToString:@"GEOMETRY"]
|| [detailString isEqualToString:@"LINESTRING"] || [detailString isEqualToString:@"POLYGON"]
Expand Down
27 changes: 19 additions & 8 deletions Source/SPTableStructure.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ - (void)awakeFromNib
SPMySQLLongBlobType,
SPMySQLBinaryType,
SPMySQLVarBinaryType,
SPMySQLJsonType,
SPMySQLEnumType,
SPMySQLSetType,
@"--------",
Expand Down Expand Up @@ -959,7 +960,10 @@ - (NSString *)_buildPartialColumnDefinitionString:(NSDictionary *)theRow
if(!specialFieldTypes) {


if ([fieldValidation isFieldTypeString:theRowType]) {
if ([theRowType isEqualToString:@"JSON"]) {
// we "see" JSON as a string, but it is not internally to MySQL and so doesn't allow CHARACTER SET/BINARY/COLLATE either.
}
else if ([fieldValidation isFieldTypeString:theRowType]) {
BOOL charsetSupport = [[tableDocumentInstance serverSupport] supportsPost41CharacterSetHandling];

// Add CHARSET
Expand Down Expand Up @@ -1002,16 +1006,17 @@ - (NSString *)_buildPartialColumnDefinitionString:(NSDictionary *)theRow
// Don't provide any defaults for auto-increment fields
if (![theRowExtra isEqualToString:@"AUTO_INCREMENT"]) {
NSArray *matches;
NSString *defaultValue = [theRow objectForKey:@"default"];
// If a NULL value has been specified, and NULL is allowed, specify DEFAULT NULL
if ([[theRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]])
if ([defaultValue isEqualToString:[prefs objectForKey:SPNullValue]])
{
if ([[theRow objectForKey:@"null"] integerValue] == 1) {
[queryString appendString:@"\n DEFAULT NULL"];
}
}
// Otherwise, if CURRENT_TIMESTAMP was specified for timestamps/datetimes, use that
else if ([theRowType isInArray:@[@"TIMESTAMP",@"DATETIME"]] &&
[(matches = [[[theRow objectForKey:@"default"] uppercaseString] captureComponentsMatchedByRegex:SPCurrentTimestampPattern]) count])
[(matches = [[defaultValue uppercaseString] captureComponentsMatchedByRegex:SPCurrentTimestampPattern]) count])
{
[queryString appendString:@"\n DEFAULT CURRENT_TIMESTAMP"];
NSString *userLen = [matches objectAtIndex:1];
Expand All @@ -1023,17 +1028,17 @@ - (NSString *)_buildPartialColumnDefinitionString:(NSDictionary *)theRow
}
// If the field is of type BIT, permit the use of single qoutes and also don't quote the default value.
// For example, use DEFAULT b'1' as opposed to DEFAULT 'b\'1\'' which results in an error.
else if ([(NSString *)[theRow objectForKey:@"default"] length] && [theRowType isEqualToString:@"BIT"]) {
[queryString appendFormat:@"\n DEFAULT %@", [theRow objectForKey:@"default"]];
else if ([defaultValue length] && [theRowType isEqualToString:@"BIT"]) {
[queryString appendFormat:@"\n DEFAULT %@", defaultValue];
}
// Suppress appending DEFAULT clause for any numerics, date, time fields if default is empty to avoid error messages;
// also don't specify a default for TEXT/BLOB or geometry fields to avoid strict mode errors
else if (![(NSString *)[theRow objectForKey:@"default"] length] && ([fieldValidation isFieldTypeNumeric:theRowType] || [fieldValidation isFieldTypeDate:theRowType] || [theRowType hasSuffix:@"TEXT"] || [theRowType hasSuffix:@"BLOB"] || [fieldValidation isFieldTypeGeometry:theRowType])) {
// also don't specify a default for TEXT/BLOB, JSON or geometry fields to avoid strict mode errors
else if (![defaultValue length] && ([fieldValidation isFieldTypeNumeric:theRowType] || [fieldValidation isFieldTypeDate:theRowType] || [theRowType hasSuffix:@"TEXT"] || [theRowType hasSuffix:@"BLOB"] || [theRowType isEqualToString:@"JSON"] || [fieldValidation isFieldTypeGeometry:theRowType])) {
;
}
// Otherwise, use the provided default
else {
[queryString appendFormat:@"\n DEFAULT %@", [mySQLConnection escapeAndQuoteString:[theRow objectForKey:@"default"]]];
[queryString appendFormat:@"\n DEFAULT %@", [mySQLConnection escapeAndQuoteString:defaultValue]];
}
}

Expand Down Expand Up @@ -1717,6 +1722,12 @@ + (SPFieldTypeHelp *)helpForFieldType:(NSString *)typeName
[NSString stringWithFormat:NSLocalizedString(@"M: %@ to %@ bytes", @"range for varbinary type"),FN(@0),FN(@(65535))],
NSLocalizedString(@"A byte array with variable length. The actual number of bytes is further limited by the values of other fields in the row.",@"description of varbinary")
),
MakeFieldTypeHelp(
SPMySQLJsonType,
@"JSON",
NSLocalizedString(@"Limited to @@max_allowed_packet", @"range for json type"),
NSLocalizedString(@"A data type that validates JSON data on INSERT and internally stores it in a binary format that is both, more compact and faster to access than textual JSON.\nAvailable from MySQL 5.7.8.", @"description of json")
),
MakeFieldTypeHelp(
SPMySQLEnumType,
@"ENUM('member',...)",
Expand Down

0 comments on commit 1f7684a

Please sign in to comment.