Skip to content

Commit

Permalink
Fixed CORE-2265 - Grouping by function doesn't work properly
Browse files Browse the repository at this point in the history
(This is related to CORE-1246 changes)
  • Loading branch information
asfernandes committed Jan 4, 2009
1 parent 9bb42cf commit 53f18ba
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/dsql/make.cpp
Expand Up @@ -93,12 +93,13 @@ static void make_parameter_names(dsql_par*, const dsql_nod*);
static const char* DB_KEY_NAME = "DB_KEY";


dsql_nod* MAKE_const_slong(SLONG value)
dsql_nod* MAKE_const_slong(SLONG value, bool special)
{
thread_db* tdbb = JRD_get_thread_data();

dsql_nod* node = FB_NEW_RPT(*tdbb->getDefaultPool(), 1) dsql_nod;
node->nod_type = nod_constant;
node->nod_flags = special ? NOD_CONST_SPECIAL : 0;
node->nod_desc.dsc_dtype = dtype_long;
node->nod_desc.dsc_length = sizeof(SLONG);
node->nod_desc.dsc_scale = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/dsql/make_proto.h
Expand Up @@ -56,7 +56,7 @@ namespace Jrd {
}


Jrd::dsql_nod* MAKE_const_slong(SLONG);
Jrd::dsql_nod* MAKE_const_slong(SLONG, bool special = false);
Jrd::dsql_nod* MAKE_constant(Jrd::dsql_str*, Jrd::dsql_constant_type);
Jrd::dsql_nod* MAKE_str_constant(Jrd::dsql_str*, SSHORT);
Jrd::dsql_str* MAKE_cstring(const char*);
Expand Down
4 changes: 3 additions & 1 deletion src/dsql/node.h
Expand Up @@ -1105,7 +1105,9 @@ enum nod_flags_vals {
NOD_TRAN_AUTONOMOUS = 1, // nod_exec_stmt
NOD_TRAN_COMMON = 2,
NOD_TRAN_2PC = 3,
NOD_TRAN_DEFAULT = NOD_TRAN_COMMON
NOD_TRAN_DEFAULT = NOD_TRAN_COMMON,

NOD_CONST_SPECIAL = 1 // nod_constant
};

} // namespace
Expand Down
48 changes: 24 additions & 24 deletions src/dsql/parse.y
Expand Up @@ -4384,19 +4384,19 @@ current_role : CURRENT_ROLE

internal_info : CURRENT_CONNECTION
{ $$ = make_node (nod_internal_info, (int) e_internal_info_count,
MAKE_const_slong (internal_connection_id)); }
MAKE_const_slong (internal_connection_id, true)); }
| CURRENT_TRANSACTION
{ $$ = make_node (nod_internal_info, (int) e_internal_info_count,
MAKE_const_slong (internal_transaction_id)); }
MAKE_const_slong (internal_transaction_id, true)); }
| GDSCODE
{ $$ = make_node (nod_internal_info, (int) e_internal_info_count,
MAKE_const_slong (internal_gdscode)); }
MAKE_const_slong (internal_gdscode, true)); }
| SQLCODE
{ $$ = make_node (nod_internal_info, (int) e_internal_info_count,
MAKE_const_slong (internal_sqlcode)); }
MAKE_const_slong (internal_sqlcode, true)); }
| ROW_COUNT
{ $$ = make_node (nod_internal_info, (int) e_internal_info_count,
MAKE_const_slong (internal_rows_affected)); }
MAKE_const_slong (internal_rows_affected, true)); }
;

sql_string : STRING /* string in current charset */
Expand Down Expand Up @@ -4538,20 +4538,20 @@ length_expression : bit_length_expression

bit_length_expression : BIT_LENGTH '(' value ')'
{ $$ = make_node(nod_strlen, (int) e_strlen_count,
MAKE_const_slong(blr_strlen_bit), $3); }
MAKE_const_slong(blr_strlen_bit, true), $3); }
;

char_length_expression : CHAR_LENGTH '(' value ')'
{ $$ = make_node(nod_strlen, (int) e_strlen_count,
MAKE_const_slong(blr_strlen_char), $3); }
MAKE_const_slong(blr_strlen_char, true), $3); }
| CHARACTER_LENGTH '(' value ')'
{ $$ = make_node(nod_strlen, (int) e_strlen_count,
MAKE_const_slong(blr_strlen_char), $3); }
MAKE_const_slong(blr_strlen_char, true), $3); }
;

octet_length_expression : OCTET_LENGTH '(' value ')'
{ $$ = make_node(nod_strlen, (int) e_strlen_count,
MAKE_const_slong(blr_strlen_octet), $3); }
MAKE_const_slong(blr_strlen_octet, true), $3); }
;

system_function_expression
Expand Down Expand Up @@ -4675,20 +4675,20 @@ trim_function : TRIM '(' trim_specification value FROM value ')'
{ $$ = make_node (nod_trim, (int) e_trim_count, $3, $4, $6); }
| TRIM '(' value FROM value ')'
{ $$ = make_node (nod_trim, (int) e_trim_count,
MAKE_const_slong (blr_trim_both), $3, $5); }
MAKE_const_slong (blr_trim_both, true), $3, $5); }
| TRIM '(' trim_specification FROM value ')'
{ $$ = make_node (nod_trim, (int) e_trim_count, $3, NULL, $5); }
| TRIM '(' value ')'
{ $$ = make_node (nod_trim, (int) e_trim_count,
MAKE_const_slong (blr_trim_both), NULL, $3); }
MAKE_const_slong (blr_trim_both, true), NULL, $3); }
;

trim_specification : BOTH
{ $$ = MAKE_const_slong (blr_trim_both); }
{ $$ = MAKE_const_slong (blr_trim_both, true); }
| TRAILING
{ $$ = MAKE_const_slong (blr_trim_trailing); }
{ $$ = MAKE_const_slong (blr_trim_trailing, true); }
| LEADING
{ $$ = MAKE_const_slong (blr_trim_leading); }
{ $$ = MAKE_const_slong (blr_trim_leading, true); }
;

udf : symbol_UDF_call_name '(' value_list ')'
Expand Down Expand Up @@ -4788,25 +4788,25 @@ next_value_expression : NEXT KW_VALUE FOR symbol_generator_name


timestamp_part : YEAR
{ $$ = MAKE_const_slong (blr_extract_year); }
{ $$ = MAKE_const_slong (blr_extract_year, true); }
| MONTH
{ $$ = MAKE_const_slong (blr_extract_month); }
{ $$ = MAKE_const_slong (blr_extract_month, true); }
| DAY
{ $$ = MAKE_const_slong (blr_extract_day); }
{ $$ = MAKE_const_slong (blr_extract_day, true); }
| HOUR
{ $$ = MAKE_const_slong (blr_extract_hour); }
{ $$ = MAKE_const_slong (blr_extract_hour, true); }
| MINUTE
{ $$ = MAKE_const_slong (blr_extract_minute); }
{ $$ = MAKE_const_slong (blr_extract_minute, true); }
| SECOND
{ $$ = MAKE_const_slong (blr_extract_second); }
{ $$ = MAKE_const_slong (blr_extract_second, true); }
| MILLISECOND
{ $$ = MAKE_const_slong (blr_extract_millisecond); }
{ $$ = MAKE_const_slong (blr_extract_millisecond, true); }
| WEEK
{ $$ = MAKE_const_slong (blr_extract_week); }
{ $$ = MAKE_const_slong (blr_extract_week, true); }
| WEEKDAY
{ $$ = MAKE_const_slong (blr_extract_weekday); }
{ $$ = MAKE_const_slong (blr_extract_weekday, true); }
| YEARDAY
{ $$ = MAKE_const_slong (blr_extract_yearday); }
{ $$ = MAKE_const_slong (blr_extract_yearday, true); }
;

all_noise : ALL
Expand Down
3 changes: 3 additions & 0 deletions src/dsql/pass1.cpp
Expand Up @@ -10100,6 +10100,9 @@ static dsql_nod* remap_field(CompiledStatement* statement, dsql_nod* field,
return field;

case nod_constant:
// ASF: Do not remap non-user constants - CORE-2265.
return (field->nod_flags & NOD_CONST_SPECIAL) ? field : post_map(field, context);

case nod_dbkey:
return post_map(field, context);

Expand Down

0 comments on commit 53f18ba

Please sign in to comment.