MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / addDateTime

Method addDateTime

src/dsql/ExprNodes.cpp:2668–2727  ·  view source on GitHub ↗

Vector out to one of the actual datetime addition routines.

Source from the content-addressed store, hash-verified

2666
2667// Vector out to one of the actual datetime addition routines.
2668dsc* ArithmeticNode::addDateTime(thread_db* tdbb, const dsc* desc, impure_value* value) const
2669{
2670 BYTE dtype; // Which addition routine to use?
2671
2672 fb_assert(nodFlags & FLAG_DATE);
2673
2674 // Value is the LHS of the operand. desc is the RHS
2675
2676 if (blrOp == blr_add)
2677 dtype = DSC_add_result[value->vlu_desc.dsc_dtype][desc->dsc_dtype];
2678 else
2679 {
2680 fb_assert(blrOp == blr_subtract);
2681 dtype = DSC_sub_result[value->vlu_desc.dsc_dtype][desc->dsc_dtype];
2682
2683 /* Is this a <date type> - <date type> construct?
2684 chose the proper routine to do the subtract from the
2685 LHS of expression
2686 Thus: <TIME> - <TIMESTAMP> uses TIME arithmetic
2687 <DATE> - <TIMESTAMP> uses DATE arithmetic
2688 <TIMESTAMP> - <DATE> uses TIMESTAMP arithmetic */
2689 if (DTYPE_IS_NUMERIC(dtype))
2690 dtype = value->vlu_desc.dsc_dtype;
2691
2692 // Handle historical <timestamp> = <string> - <value> case
2693 if (!DTYPE_IS_DATE(dtype) &&
2694 (DTYPE_IS_TEXT(value->vlu_desc.dsc_dtype) || DTYPE_IS_TEXT(desc->dsc_dtype)))
2695 {
2696 dtype = dtype_timestamp;
2697 }
2698 }
2699
2700 switch (dtype)
2701 {
2702 case dtype_sql_time:
2703 case dtype_sql_time_tz:
2704 return addSqlTime(tdbb, desc, value);
2705
2706 case dtype_sql_date:
2707 return addSqlDate(desc, value);
2708
2709 case DTYPE_CANNOT:
2710 ERR_post(Arg::Gds(isc_expression_eval_err) << Arg::Gds(isc_invalid_type_datetime_op));
2711 break;
2712
2713 case dtype_ex_time_tz:
2714 case dtype_ex_timestamp_tz:
2715 fb_assert(false);
2716 ERRD_post(Arg::Gds(isc_expression_eval_err));
2717
2718 case dtype_timestamp:
2719 case dtype_timestamp_tz:
2720 default:
2721 // This needs to handle a dtype_sql_date + dtype_sql_time
2722 // For historical reasons prior to V6 - handle any types for timestamp arithmetic
2723 return addTimeStamp(tdbb, desc, value);
2724 }
2725

Callers 2

addMethod · 0.80
add2Method · 0.80

Calls 6

DTYPE_IS_NUMERICFunction · 0.85
DTYPE_IS_DATEFunction · 0.85
DTYPE_IS_TEXTFunction · 0.85
GdsClass · 0.85
ERRD_postFunction · 0.85
ERR_postFunction · 0.50

Tested by

no test coverage detected