From ff4bc59185ba43ca31aca8b2091c82d018e2cab5 Mon Sep 17 00:00:00 2001 From: Mark Rotteveel Date: Tue, 17 Feb 2026 10:16:59 +0100 Subject: [PATCH 1/2] Support VARCHAR without explicit length --- src/dsql/parse.y | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/dsql/parse.y b/src/dsql/parse.y index 8fcbd7ec57a..558ffd59748 100644 --- a/src/dsql/parse.y +++ b/src/dsql/parse.y @@ -5462,6 +5462,13 @@ national_character_type $$->charLength = (USHORT) $4; $$->flags |= (FLD_national | FLD_has_len); } + | national_character_keyword VARYING + { + $$ = newNode(); + $$->dtype = dtype_varying; + $$->charLength = 255; + $$->flags |= FLD_national; + } ; %type binary_character_type @@ -5499,6 +5506,17 @@ binary_character_type $$->subType = fb_text_subtype_binary; $$->flags |= (FLD_has_len | FLD_has_chset); } + | varbinary_character_keyword + { + $$ = newNode(); + $$->dtype = dtype_varying; + $$->charLength = 255; + $$->length = 255 + sizeof(USHORT); + $$->textType = ttype_binary; + $$->charSetId = CS_BINARY; + $$->subType = fb_text_subtype_binary; + $$->flags |= FLD_has_chset; + } ; %type character_type @@ -5523,6 +5541,12 @@ character_type $$->charLength = (USHORT) $3; $$->flags |= FLD_has_len; } + | varying_keyword + { + $$ = newNode(); + $$->dtype = dtype_varying; + $$->charLength = 255; + } ; varying_keyword @@ -5902,7 +5926,7 @@ set_bind %type set_bind_from set_bind_from - : bind_type + : non_array_type | TIME ZONE { $$ = newNode(); @@ -5911,20 +5935,9 @@ set_bind_from } ; -%type bind_type -bind_type - : non_array_type - | varying_keyword - { - $$ = newNode(); - $$->dtype = dtype_varying; - $$->charLength = 0; - } - ; - %type set_bind_to set_bind_to - : bind_type + : non_array_type { $$ = $1; } From 17282ab6ca8a066ed5d953a8671ef9e2bebbc840 Mon Sep 17 00:00:00 2001 From: Mark Rotteveel Date: Tue, 17 Feb 2026 10:59:49 +0100 Subject: [PATCH 2/2] Add constants for default lengths --- src/dsql/parse.y | 16 ++++++++-------- src/jrd/constants.h | 8 ++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/dsql/parse.y b/src/dsql/parse.y index 558ffd59748..364be68de06 100644 --- a/src/dsql/parse.y +++ b/src/dsql/parse.y @@ -5452,7 +5452,7 @@ national_character_type { $$ = newNode(); $$->dtype = dtype_text; - $$->charLength = 1; + $$->charLength = DEFAULT_CHAR_LENGTH; $$->flags |= FLD_national; } | national_character_keyword VARYING '(' pos_short_integer ')' @@ -5466,7 +5466,7 @@ national_character_type { $$ = newNode(); $$->dtype = dtype_varying; - $$->charLength = 255; + $$->charLength = DEFAULT_VARCHAR_LENGTH; $$->flags |= FLD_national; } ; @@ -5488,8 +5488,8 @@ binary_character_type { $$ = newNode(); $$->dtype = dtype_text; - $$->charLength = 1; - $$->length = 1; + $$->charLength = DEFAULT_BINARY_LENGTH; + $$->length = DEFAULT_BINARY_LENGTH; $$->textType = ttype_binary; $$->charSetId = CS_BINARY; $$->subType = fb_text_subtype_binary; @@ -5510,8 +5510,8 @@ binary_character_type { $$ = newNode(); $$->dtype = dtype_varying; - $$->charLength = 255; - $$->length = 255 + sizeof(USHORT); + $$->charLength = DEFAULT_VARBINARY_LENGTH; + $$->length = DEFAULT_VARBINARY_LENGTH + sizeof(USHORT); $$->textType = ttype_binary; $$->charSetId = CS_BINARY; $$->subType = fb_text_subtype_binary; @@ -5532,7 +5532,7 @@ character_type { $$ = newNode(); $$->dtype = dtype_text; - $$->charLength = 1; + $$->charLength = DEFAULT_CHAR_LENGTH; } | varying_keyword '(' pos_short_integer ')' { @@ -5545,7 +5545,7 @@ character_type { $$ = newNode(); $$->dtype = dtype_varying; - $$->charLength = 255; + $$->charLength = DEFAULT_VARCHAR_LENGTH; } ; diff --git a/src/jrd/constants.h b/src/jrd/constants.h index b173267e3e7..36b6f2ea041 100644 --- a/src/jrd/constants.h +++ b/src/jrd/constants.h @@ -220,6 +220,14 @@ inline constexpr size_t DEFAULT_TIME_PRECISION = 0; // Should be 6 as per SQL spec inline constexpr size_t DEFAULT_TIMESTAMP_PRECISION = 3; +// SQL spec requires an implementation-specific default (6.1 , syntax rules 6 (VARBINARY) and 7 (VARCHAR)) +inline constexpr size_t DEFAULT_VARCHAR_LENGTH = 255; +inline constexpr size_t DEFAULT_VARBINARY_LENGTH = 255; + +// SQL spec requires a default length of 1 (6.1 , syntax rule 5) +inline constexpr size_t DEFAULT_CHAR_LENGTH = 1; +inline constexpr size_t DEFAULT_BINARY_LENGTH = 1; + inline constexpr size_t MAX_ARRAY_DIMENSIONS = 16; inline constexpr size_t MAX_SORT_ITEMS = 255; // ORDER BY f1,...,f255