00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "functtruncateexpression.h"
00036
00037 FunctTruncateExpression::FunctTruncateExpression(AggregateFunctExpression * _aggfunct):
00038 RoundingExpression(et_truncate, _aggfunct) {
00039 }
00040
00041 FunctTruncateExpression::~FunctTruncateExpression() {
00042 }
00043
00044 void FunctTruncateExpression::eval(OutputStream & eos, Environment * env,
00045 unsigned modus) {
00046
00047 switch (modus) {
00048
00049 case EVAL_QUERY:
00050 {
00051 bool non_value = true;
00052 long double truncate_val =
00053 calculateValue(eos, env, modus, non_value);
00054 if (!non_value) {
00055 const char *truncate_str =
00056 MiscFunctions::getStringFromNumerical(truncate_val);
00057 eos << truncate_str;
00058 delete[]truncate_str;
00059 } else {
00060 eos << OUTPUT_TRUNCATE_ON_NON_VALUE;
00061 }
00062 break;
00063 }
00064
00065 case EVAL_QUERY_SILENT:
00066 {
00067 bool non_value = true;
00068 long double truncate_val =
00069 calculateValue(eos, env, modus, non_value);
00070 if (!non_value) {
00071 cur_val.setNumVal(truncate_val);
00072 } else {
00073 const char *truncate_non_val =
00074 new char[strlen(OUTPUT_TRUNCATE_ON_NON_VALUE) + 1];
00075 strcpy((char *) truncate_non_val,
00076 OUTPUT_TRUNCATE_ON_NON_VALUE);
00077 cur_val.setStrVal(truncate_non_val);
00078 }
00079 break;
00080 }
00081
00082 case EVAL_SIGNOFF:
00083 break;
00084
00085 default:
00086 throw
00087 RuntimeException
00088 ("FunctTruncateExpression: Illegal Evaluation Mode",
00089 eid_runtime_illegalmode);
00090 break;
00091 }
00092 }
00093
00094 long double FunctTruncateExpression::calculateValue(OutputStream & eos,
00095 Environment * env,
00096 unsigned modus,
00097 bool & non_value) {
00098
00099 long double truncate_ret = 0;
00100
00101 aggfunct->prepareOperand(eos, env, modus);
00102 Value *agg_val = aggfunct->getNextValue();
00103
00104 if (agg_val->getType() == xsd_numeric) {
00105 non_value = false;
00106 truncate_ret = truncl(agg_val->getNumVal());
00107 }
00108 aggfunct->unprepareOperand();
00109
00110 return truncate_ret;
00111 }