Skip to content

Commit a3f624c

Browse files
committed
addition multi-character trim function
1 parent eef85b8 commit a3f624c

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

doc/sql.extensions/README.trim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Format:
1818
<trim character> ::=
1919
<value expression>
2020

21+
<multi-character trim function> ::=
22+
{ BTRIM | LTRIM | RTRIM } <left paren> <trim source> [ <comma> <trim character> ] <right paren>
23+
2124
Syntax Rules:
2225
1) If <trim specification> is not specified, BOTH is assumed.
2326
2) If <trim character> is not specified, ' ' is assumed.
@@ -36,3 +39,9 @@ B)
3639
trim(rdb$relation_name) || ' is a system table'
3740
from rdb$relations
3841
where rdb$system_flag = 1;
42+
43+
C)
44+
select
45+
ltrim(rdb$relation_name, 'RDB$')
46+
from rdb$relations
47+
where rdb$relation_name starting with 'RDB$';

src/common/keywords.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ static const TOK tokens[] =
505505
{TOK_TRAPS, "TRAPS", true},
506506
{TOK_TRIGGER, "TRIGGER", false},
507507
{TOK_TRIM, "TRIM", false},
508+
{TOK_BTRIM, "BTRIM", false},
509+
{TOK_LTRIM, "LTRIM", false},
510+
{TOK_RTRIM, "RTRIM", false},
508511
{TOK_TRUE, "TRUE", false},
509512
{TOK_TRUNC, "TRUNC", true},
510513
{TOK_TRUSTED, "TRUSTED", true},

src/dsql/ExprNodes.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12446,7 +12446,19 @@ ValueExprNode* TrimNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
1244612446

1244712447
void TrimNode::setParameterName(dsql_par* parameter) const
1244812448
{
12449-
parameter->par_name = parameter->par_alias = "TRIM";
12449+
switch (where) {
12450+
case blr_trim_both:
12451+
parameter->par_name = parameter->par_alias = "TRIM";
12452+
break;
12453+
case blr_trim_leading:
12454+
parameter->par_name = parameter->par_alias = "LTRIM";
12455+
break;
12456+
case blr_trim_trailing:
12457+
parameter->par_name = parameter->par_alias = "RTRIM";
12458+
break;
12459+
default:
12460+
break;
12461+
}
1245012462
}
1245112463

1245212464
bool TrimNode::setParameterType(DsqlCompilerScratch* dsqlScratch,

src/dsql/parse.y

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,12 @@ using namespace Firebird;
694694
%token <metaNamePtr> UNICODE_CHAR
695695
%token <metaNamePtr> UNICODE_VAL
696696

697+
// tokens added for Firebird 6.0
698+
699+
%token <metaNamePtr> BTRIM
700+
%token <metaNamePtr> RTRIM
701+
%token <metaNamePtr> LTRIM
702+
697703
// precedence declarations for expression evaluation
698704

699705
%left OR
@@ -4332,6 +4338,9 @@ keyword_or_column
43324338
| VARBINARY
43334339
| WINDOW
43344340
| WITHOUT
4341+
| BTRIM // added in FB 6.0
4342+
| LTRIM
4343+
| RTRIM
43354344
;
43364345

43374346
col_opt
@@ -8465,6 +8474,9 @@ of_first_last_day_part
84658474
string_value_function
84668475
: substring_function
84678476
| trim_function
8477+
| btrim_function
8478+
| ltrim_function
8479+
| rtrim_function
84688480
| UPPER '(' value ')'
84698481
{ $$ = newNode<StrCaseNode>(blr_upcase, $3); }
84708482
| LOWER '(' value ')'
@@ -8505,6 +8517,34 @@ trim_function
85058517
{ $$ = newNode<TrimNode>(blr_trim_both, $3); }
85068518
;
85078519

8520+
8521+
%type <valueExprNode> btrim_function
8522+
btrim_function
8523+
: BTRIM '(' value ',' value ')'
8524+
{ $$ = newNode<TrimNode>(blr_trim_both, $3, $5); }
8525+
| BTRIM '(' value ')'
8526+
{ $$ = newNode<TrimNode>(blr_trim_both, $3); }
8527+
;
8528+
8529+
8530+
%type <valueExprNode> ltrim_function
8531+
ltrim_function
8532+
: LTRIM '(' value ',' value ')'
8533+
{ $$ = newNode<TrimNode>(blr_trim_leading, $3, $5); }
8534+
| LTRIM '(' value ')'
8535+
{ $$ = newNode<TrimNode>(blr_trim_leading, $3); }
8536+
;
8537+
8538+
8539+
%type <valueExprNode> rtrim_function
8540+
rtrim_function
8541+
: RTRIM '(' value ',' value ')'
8542+
{ $$ = newNode<TrimNode>(blr_trim_trailing, $3, $5); }
8543+
| RTRIM '(' value ')'
8544+
{ $$ = newNode<TrimNode>(blr_trim_trailing, $3); }
8545+
;
8546+
8547+
85088548
%type <blrOp> trim_specification
85098549
trim_specification
85108550
: BOTH { $$ = blr_trim_both; }

0 commit comments

Comments
 (0)