8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 08:40:39 +01:00

Feature #5959 - Add support for QUARTER to EXTRACT, FIRST_DAY and LAST_DAY [CORE5693] (#7564)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adriano dos Santos Fernandes 2023-05-06 13:16:03 -03:00 committed by GitHub
parent efb56ceb10
commit fec506f4de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 5 deletions

View File

@ -514,7 +514,7 @@ Function:
date/timestamp value.
Format:
FIRST_DAY( OF { YEAR | MONTH | WEEK } FROM <date_or_timestamp> )
FIRST_DAY( OF { YEAR | QUARTER | MONTH | WEEK } FROM <date_or_timestamp> )
Notes:
1) The first day of the week is considered as Sunday, per the same rules of EXTRACT with WEEKDAY.
@ -615,7 +615,7 @@ Function:
date/timestamp value.
Format:
LAST_DAY( OF { YEAR | MONTH | WEEK } FROM <date_or_timestamp> )
LAST_DAY( OF { YEAR | QUARTER | MONTH | WEEK } FROM <date_or_timestamp> )
Notes:
1) The last day of the week is considered as Saturday, per the same rules of EXTRACT with WEEKDAY.

View File

@ -379,6 +379,7 @@ static const TOK tokens[] =
{TOK_PROTECTED, "PROTECTED", true},
{TOK_PUBLICATION, "PUBLICATION", false},
{TOK_QUANTIZE, "QUANTIZE", true},
{TOK_QUARTER, "QUARTER", true},
{TOK_RAND, "RAND", true},
{TOK_RANGE, "RANGE", true},
{TOK_RANK, "RANK", true},

View File

@ -5276,6 +5276,7 @@ ValueExprNode* ExtractNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
switch (blrSubOp)
{
case blr_extract_year:
case blr_extract_quarter:
case blr_extract_month:
case blr_extract_day:
case blr_extract_weekday:
@ -5602,6 +5603,10 @@ dsc* ExtractNode::execute(thread_db* tdbb, Request* request) const
part = times.tm_year + 1900;
break;
case blr_extract_quarter:
part = times.tm_mon / 3 + 1;
break;
case blr_extract_month:
part = times.tm_mon + 1;
break;

View File

@ -689,6 +689,7 @@ using namespace Firebird;
// tokens added for Firebird 5.0
%token <metaNamePtr> LOCKED
%token <metaNamePtr> QUARTER
%token <metaNamePtr> TARGET
%token <metaNamePtr> TIMEZONE_NAME
%token <metaNamePtr> UNICODE_CHAR
@ -8457,6 +8458,7 @@ encrypt_decrypt
%type <blrOp> of_first_last_day_part
of_first_last_day_part
: OF YEAR { $$ = blr_extract_year; }
| OF QUARTER { $$ = blr_extract_quarter; }
| OF MONTH { $$ = blr_extract_month; }
| OF WEEK { $$ = blr_extract_week; }
;
@ -8702,6 +8704,7 @@ next_value_expression
%type <blrOp> timestamp_part
timestamp_part
: YEAR { $$ = blr_extract_year; }
| QUARTER { $$ = blr_extract_quarter; }
| MONTH { $$ = blr_extract_month; }
| DAY { $$ = blr_extract_day; }
| HOUR { $$ = blr_extract_hour; }
@ -9180,6 +9183,7 @@ non_reserved_word
| BLOB_APPEND
// added in FB 5.0
| LOCKED
| QUARTER
| TARGET
| TIMEZONE_NAME
| UNICODE_CHAR

View File

@ -289,6 +289,7 @@
#define blr_extract_timezone_hour (unsigned char)10
#define blr_extract_timezone_minute (unsigned char)11
#define blr_extract_timezone_name (unsigned char)12
#define blr_extract_quarter (unsigned char)13
#define blr_current_date (unsigned char)160
#define blr_current_timestamp (unsigned char)161

View File

@ -2668,16 +2668,33 @@ dsc* evlCharToUuid(thread_db* tdbb, const SysFunction* function, const NestValue
#define blr_extract_yearday (unsigned char)7
#define blr_extract_millisecond (unsigned char)8
#define blr_extract_week (unsigned char)9
#define blr_extract_timezone_hour (unsigned char)10
#define blr_extract_timezone_minute (unsigned char)11
#define blr_extract_timezone_name (unsigned char)12
#define blr_extract_quarter (unsigned char)13
*/
const char* extractParts[10] =
const char* extractParts[] =
{
"YEAR", "MONTH", "DAY", "HOUR", "MINUTE", "SECOND", "WEEKDAY", "YEARDAY", "MILLISECOND", "WEEK"
"YEAR",
"MONTH",
"DAY",
"HOUR",
"MINUTE",
"SECOND",
"WEEKDAY",
"YEARDAY",
"MILLISECOND",
"WEEK",
nullptr,
nullptr,
nullptr,
"QUARTER"
};
const char* getPartName(int n)
{
if (n < 0 || n >= FB_NELEM(extractParts))
if (n < 0 || n >= FB_NELEM(extractParts) || !extractParts[n])
return "Unknown";
return extractParts[n];
@ -4117,6 +4134,7 @@ dsc* evlDateDiff(thread_db* tdbb, const SysFunction* function, const NestValueAr
switch (part)
{
case blr_extract_year:
case blr_extract_quarter:
case blr_extract_month:
case blr_extract_day:
case blr_extract_week:
@ -4322,6 +4340,11 @@ dsc* evlFirstLastDay(thread_db* tdbb, const SysFunction* function, const NestVal
times.tm_mday = 1;
break;
case blr_extract_quarter:
times.tm_mon = times.tm_mon / 3 * 3;
times.tm_mday = 1;
break;
case blr_extract_week:
break;
@ -4345,6 +4368,10 @@ dsc* evlFirstLastDay(thread_db* tdbb, const SysFunction* function, const NestVal
adjust = -1;
break;
case blr_extract_quarter:
times.tm_mon += 2;
// fall through
case blr_extract_month:
if (++times.tm_mon == 12)
{