ExtDateTime.cpp File Reference

Go to the source code of this file.

Namespaces

namespace  boost::local_time

Functions

 FENNEL_BEGIN_CPPFILE ("$Id: //open/dev/fennel/calculator/ExtDateTime.cpp#2 $")
void CastDateToStrA (RegisterRef< char * > *result, RegisterRef< int64_t > *date)
void CastTimeToStrA (RegisterRef< char * > *result, RegisterRef< int64_t > *time)
void CastTimestampToStrA (RegisterRef< char * > *result, RegisterRef< int64_t > *tstamp)
void CastStrAToDate (RegisterRef< int64_t > *result, RegisterRef< char * > *dateStr)
void CastStrAToTime (RegisterRef< int64_t > *result, RegisterRef< char * > *timeStr)
void CastStrAToTimestamp (RegisterRef< int64_t > *result, RegisterRef< char * > *timestampStr)
void CastDateTimeToInt64 (RegisterRef< int64_t > *result, RegisterRef< int64_t > *dtime)
void CurrentTime (RegisterRef< int64_t > *result)
void CurrentTimestamp (RegisterRef< int64_t > *result)
void CurrentTime (RegisterRef< int64_t > *result, RegisterRef< int32_t > *precision)
void CurrentTimestamp (RegisterRef< int64_t > *result, RegisterRef< int32_t > *precision)
void LocalTime (RegisterRef< int64_t > *result, RegisterRef< char * > *tz)
void LocalTimestamp (RegisterRef< int64_t > *result, RegisterRef< char * > *tz)
void LocalTime (RegisterRef< int64_t > *result, RegisterRef< char * > *tz, RegisterRef< int32_t > *precision)
void LocalTimestamp (RegisterRef< int64_t > *result, RegisterRef< char * > *tz, RegisterRef< int32_t > *precision)
void ExtDateTimeRegister (ExtendedInstructionTable *eit)
 Registers extended instructions relating to date, time, and timestamp values.
 FENNEL_END_CPPFILE ("$Id: //open/dev/fennel/calculator/ExtDateTime.cpp#2 $")


Function Documentation

void CastDateTimeToInt64 ( RegisterRef< int64_t > *  result,
RegisterRef< int64_t > *  dtime 
)

Definition at line 147 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::isNull(), STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00150 {
00151     assert(result->type() == STANDARD_TYPE_INT_64);
00152     assert(dtime->type() == STANDARD_TYPE_INT_64);
00153 
00154     if (dtime->isNull()) {
00155         result->toNull();
00156     } else {
00157         result->value(dtime->value());
00158     }
00159 }

void CastDateToStrA ( RegisterRef< char * > *  result,
RegisterRef< int64_t > *  date 
)

Definition at line 32 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::isNull(), StandardTypeDescriptor::isTextArray(), RegisterRef< TMPLT >::length(), RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_CHAR, STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::storage(), RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00035 {
00036     assert(date->type() == STANDARD_TYPE_INT_64);
00037     assert(StandardTypeDescriptor::isTextArray(result->type()));
00038 
00039     if (date->isNull()) {
00040         result->toNull();
00041         result->length(0);
00042     } else {
00043         // Produce a result like "2004-05-12"
00044         int64_t v = date->value() * 1000;
00045         int len = SqlDateToStr<1,1,SQLDATE>(
00046             result->pointer(), result->storage(), v,
00047             (result->type() == STANDARD_TYPE_CHAR ? true : false));
00048         result->length(len);
00049     }
00050 }

void CastStrAToDate ( RegisterRef< int64_t > *  result,
RegisterRef< char * > *  dateStr 
)

Definition at line 93 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::isNull(), StandardTypeDescriptor::isTextArray(), RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::stringLength(), RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00096 {
00097     assert(result->type() == STANDARD_TYPE_INT_64);
00098     assert(StandardTypeDescriptor::isTextArray(dateStr->type()));
00099 
00100     if (dateStr->isNull()) {
00101         result->toNull();
00102     } else {
00103         result->value(
00104             SqlStrToDate<1,1,SQLDATE>(
00105                 dateStr->pointer(),
00106                 dateStr->stringLength()));
00107     }
00108 }

void CastStrAToTime ( RegisterRef< int64_t > *  result,
RegisterRef< char * > *  timeStr 
)

Definition at line 111 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::isNull(), StandardTypeDescriptor::isTextArray(), RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::stringLength(), RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00114 {
00115     assert(result->type() == STANDARD_TYPE_INT_64);
00116     assert(StandardTypeDescriptor::isTextArray(timeStr->type()));
00117 
00118     if (timeStr->isNull()) {
00119         result->toNull();
00120     } else {
00121         result->value(
00122             SqlStrToDate<1,1,SQLTIME>(
00123                 timeStr->pointer(),
00124                 timeStr->stringLength()));
00125     }
00126 }

void CastStrAToTimestamp ( RegisterRef< int64_t > *  result,
RegisterRef< char * > *  timestampStr 
)

Definition at line 129 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::isNull(), StandardTypeDescriptor::isTextArray(), RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::stringLength(), RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00132 {
00133     assert(result->type() == STANDARD_TYPE_INT_64);
00134     assert(StandardTypeDescriptor::isTextArray(timestampStr->type()));
00135 
00136     if (timestampStr->isNull()) {
00137         result->toNull();
00138     } else {
00139         result->value(
00140             SqlStrToDate<1,1,SQLTIMESTAMP>(
00141                 timestampStr->pointer(),
00142                 timestampStr->stringLength()));
00143     }
00144 }

void CastTimestampToStrA ( RegisterRef< char * > *  result,
RegisterRef< int64_t > *  tstamp 
)

Definition at line 73 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::isNull(), StandardTypeDescriptor::isTextArray(), RegisterRef< TMPLT >::length(), RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_CHAR, STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::storage(), RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00076 {
00077     assert(tstamp->type() == STANDARD_TYPE_INT_64);
00078     assert(StandardTypeDescriptor::isTextArray(result->type()));
00079 
00080     if (tstamp->isNull()) {
00081         result->toNull();
00082         result->length(0);
00083     } else {
00084         int64_t v = tstamp->value() * 1000;
00085         int len = SqlDateToStr<1,1,SQLTIMESTAMP>(
00086             result->pointer(), result->storage(), v,
00087             (result->type() == STANDARD_TYPE_CHAR ? true : false));
00088         result->length(len);
00089     }
00090 }

void CastTimeToStrA ( RegisterRef< char * > *  result,
RegisterRef< int64_t > *  time 
)

Definition at line 53 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::isNull(), StandardTypeDescriptor::isTextArray(), RegisterRef< TMPLT >::length(), RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_CHAR, STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::storage(), RegisterRef< TMPLT >::toNull(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00056 {
00057     assert(time->type() == STANDARD_TYPE_INT_64);
00058     assert(StandardTypeDescriptor::isTextArray(result->type()));
00059 
00060     if (time->isNull()) {
00061         result->toNull();
00062         result->length(0);
00063     } else {
00064         int64_t v = time->value() * 1000;
00065         int len = SqlDateToStr<1,1,SQLTIME>(
00066             result->pointer(), result->storage(), v,
00067             (result->type() == STANDARD_TYPE_CHAR ? true : false));
00068         result->length(len);
00069     }
00070 }

void CurrentTime ( RegisterRef< int64_t > *  result,
RegisterRef< int32_t > *  precision 
)

Definition at line 173 of file ExtDateTime.cpp.

References STANDARD_TYPE_INT_32, STANDARD_TYPE_INT_64, RegisterReference::type(), UniversalTime(), and RegisterRef< TMPLT >::value().

00176 {
00177     assert (result->type() == STANDARD_TYPE_INT_64);
00178     assert (precision->type() == STANDARD_TYPE_INT_32);
00179 
00180     // precision is ignored for now
00181     result->value(UniversalTime());
00182 }

void CurrentTime ( RegisterRef< int64_t > *  result  ) 

Definition at line 161 of file ExtDateTime.cpp.

References STANDARD_TYPE_INT_64, RegisterReference::type(), UniversalTime(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00162 {
00163     assert (result->type() == STANDARD_TYPE_INT_64);
00164     result->value(UniversalTime());
00165 }

void CurrentTimestamp ( RegisterRef< int64_t > *  result,
RegisterRef< int32_t > *  precision 
)

Definition at line 184 of file ExtDateTime.cpp.

References STANDARD_TYPE_INT_32, STANDARD_TYPE_INT_64, RegisterReference::type(), UniversalTimestamp(), and RegisterRef< TMPLT >::value().

00187 {
00188     assert (result->type() == STANDARD_TYPE_INT_64);
00189     assert (precision->type() == STANDARD_TYPE_INT_32);
00190 
00191     // precision is ignored for now
00192     result->value(UniversalTimestamp());
00193 }

void CurrentTimestamp ( RegisterRef< int64_t > *  result  ) 

Definition at line 167 of file ExtDateTime.cpp.

References STANDARD_TYPE_INT_64, RegisterReference::type(), UniversalTimestamp(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister().

00168 {
00169     assert (result->type() == STANDARD_TYPE_INT_64);
00170     result->value(UniversalTimestamp());
00171 }

void ExtDateTimeRegister ( ExtendedInstructionTable eit  ) 

Registers extended instructions relating to date, time, and timestamp values.

Definition at line 259 of file ExtDateTime.cpp.

References ExtendedInstructionTable::add(), CastDateTimeToInt64(), CastDateToStrA(), CastStrAToDate(), CastStrAToTime(), CastStrAToTimestamp(), CastTimestampToStrA(), CastTimeToStrA(), CurrentTime(), CurrentTimestamp(), LocalTime(), LocalTimestamp(), STANDARD_TYPE_CHAR, STANDARD_TYPE_INT_32, STANDARD_TYPE_INT_64, and STANDARD_TYPE_VARCHAR.

Referenced by CalcInit::instance().

00260 {
00261     assert(eit != NULL);
00262 
00263     vector<StandardTypeDescriptorOrdinal> params_V_I64;
00264     params_V_I64.push_back(STANDARD_TYPE_VARCHAR);
00265     params_V_I64.push_back(STANDARD_TYPE_INT_64);
00266 
00267     vector<StandardTypeDescriptorOrdinal> params_C_I64;
00268     params_C_I64.push_back(STANDARD_TYPE_CHAR);
00269     params_C_I64.push_back(STANDARD_TYPE_INT_64);
00270 
00271     vector<StandardTypeDescriptorOrdinal> params_I64_V;
00272     params_I64_V.push_back(STANDARD_TYPE_INT_64);
00273     params_I64_V.push_back(STANDARD_TYPE_VARCHAR);
00274 
00275     vector<StandardTypeDescriptorOrdinal> params_I64_C;
00276     params_I64_C.push_back(STANDARD_TYPE_INT_64);
00277     params_I64_C.push_back(STANDARD_TYPE_CHAR);
00278 
00279     vector<StandardTypeDescriptorOrdinal> params_I64_C_I32;
00280     params_I64_C_I32.push_back(STANDARD_TYPE_INT_64);
00281     params_I64_C_I32.push_back(STANDARD_TYPE_CHAR);
00282     params_I64_C_I32.push_back(STANDARD_TYPE_INT_32);
00283 
00284     vector<StandardTypeDescriptorOrdinal> params_I64_I64;
00285     params_I64_I64.push_back(STANDARD_TYPE_INT_64);
00286     params_I64_I64.push_back(STANDARD_TYPE_INT_64);
00287 
00288     vector<StandardTypeDescriptorOrdinal> params_I64;
00289     params_I64.push_back(STANDARD_TYPE_INT_64);
00290 
00291     vector<StandardTypeDescriptorOrdinal> params_I64_I32;
00292     params_I64_I32.push_back(STANDARD_TYPE_INT_64);
00293     params_I64_I32.push_back(STANDARD_TYPE_INT_32);
00294 
00295     // date -> str
00296     eit->add(
00297         "CastDateToStrA", params_V_I64,
00298         (ExtendedInstruction2<char*, int64_t>*) NULL,
00299         &CastDateToStrA);
00300 
00301     eit->add(
00302         "CastDateToStrA", params_C_I64,
00303         (ExtendedInstruction2<char*, int64_t>*) NULL,
00304         &CastDateToStrA);
00305 
00306     eit->add(
00307         "CastTimeToStrA", params_V_I64,
00308         (ExtendedInstruction2<char*, int64_t>*) NULL,
00309         &CastTimeToStrA);
00310 
00311     eit->add(
00312         "CastTimeToStrA", params_C_I64,
00313         (ExtendedInstruction2<char*, int64_t>*) NULL,
00314         &CastTimeToStrA);
00315 
00316     eit->add(
00317         "CastTimestampToStrA", params_V_I64,
00318         (ExtendedInstruction2<char*, int64_t>*) NULL,
00319         &CastTimestampToStrA);
00320 
00321     eit->add(
00322         "CastTimestampToStrA", params_C_I64,
00323         (ExtendedInstruction2<char*, int64_t>*) NULL,
00324         &CastTimestampToStrA);
00325 
00326     // str -> date
00327     eit->add(
00328         "CastStrAToDate", params_I64_V,
00329         (ExtendedInstruction2<int64_t, char*>*) NULL,
00330         &CastStrAToDate);
00331 
00332     eit->add(
00333         "CastStrAToDate", params_I64_C,
00334         (ExtendedInstruction2<int64_t, char*>*) NULL,
00335         &CastStrAToDate);
00336 
00337     eit->add(
00338         "CastStrAToTime", params_I64_V,
00339         (ExtendedInstruction2<int64_t, char*>*) NULL,
00340         &CastStrAToTime);
00341 
00342     eit->add(
00343         "CastStrAToTime", params_I64_C,
00344         (ExtendedInstruction2<int64_t, char*>*) NULL,
00345         &CastStrAToTime);
00346 
00347     eit->add(
00348         "CastStrAToTimestamp", params_I64_V,
00349         (ExtendedInstruction2<int64_t, char*>*) NULL,
00350         &CastStrAToTimestamp);
00351 
00352     eit->add(
00353         "CastStrAToTimestamp", params_I64_C,
00354         (ExtendedInstruction2<int64_t, char*>*) NULL,
00355         &CastStrAToTimestamp);
00356 
00357     // others
00358     eit->add(
00359         "CastDateTimeToInt64", params_I64_I64,
00360         (ExtendedInstruction2<int64_t, int64_t>*) NULL,
00361         &CastDateTimeToInt64);
00362 
00363     eit->add(
00364         "LocalTime2", params_I64_C,
00365         (ExtendedInstruction2<int64_t, char *>*) NULL,
00366         &LocalTime);
00367 
00368     eit->add(
00369         "LocalTimestamp2", params_I64_C,
00370         (ExtendedInstruction2<int64_t, char *>*) NULL,
00371         &LocalTimestamp);
00372 
00373     eit->add(
00374         "LocalTime3", params_I64_C_I32,
00375         (ExtendedInstruction3<int64_t, char *, int32_t>*) NULL,
00376         &LocalTime);
00377 
00378     eit->add(
00379         "LocalTimestamp3", params_I64_C_I32,
00380         (ExtendedInstruction3<int64_t, char *, int32_t>*) NULL,
00381         &LocalTimestamp);
00382 
00383     eit->add(
00384         "CurrentTime1", params_I64,
00385         (ExtendedInstruction1<int64_t>*) NULL,
00386         &CurrentTime);
00387 
00388     eit->add(
00389         "CurrentTimestamp1", params_I64,
00390         (ExtendedInstruction1<int64_t>*) NULL,
00391         &CurrentTimestamp);
00392 
00393     eit->add(
00394         "CurrentTime2", params_I64_I32,
00395         (ExtendedInstruction2<int64_t, int32_t>*) NULL,
00396         &CurrentTime);
00397 
00398     eit->add(
00399         "CurrentTimestamp2", params_I64_I32,
00400         (ExtendedInstruction2<int64_t, int32_t>*) NULL,
00401         &CurrentTimestamp);
00402 
00403 }

FENNEL_BEGIN_CPPFILE ( "$Id: //open/dev/fennel/calculator/ExtDateTime.cpp#2 $"   ) 

FENNEL_END_CPPFILE ( "$Id: //open/dev/fennel/calculator/ExtDateTime.cpp#2 $"   ) 

void LocalTime ( RegisterRef< int64_t > *  result,
RegisterRef< char * > *  tz,
RegisterRef< int32_t > *  precision 
)

Definition at line 223 of file ExtDateTime.cpp.

References LocalTime(), RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_CHAR, STANDARD_TYPE_INT_32, STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::stringLength(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

00227 {
00228     assert (result->type() == STANDARD_TYPE_INT_64);
00229     assert (tz->type() == STANDARD_TYPE_CHAR);
00230     assert (precision->type() == STANDARD_TYPE_INT_32);
00231 
00232     time_zone_ptr tzPtr(
00233         new posix_time_zone(
00234             string(tz->pointer(), tz->stringLength())));
00235 
00236     // precision is ignored for now
00237     result->value(LocalTime(tzPtr));
00238 }

void LocalTime ( RegisterRef< int64_t > *  result,
RegisterRef< char * > *  tz 
)

Definition at line 195 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_CHAR, STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::stringLength(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister(), LocalTime(), and SqlDateTest::testLocalTime().

00198 {
00199     assert (result->type() == STANDARD_TYPE_INT_64);
00200     assert (tz->type() == STANDARD_TYPE_CHAR);
00201 
00202     time_zone_ptr tzPtr(
00203         new posix_time_zone(
00204             string(tz->pointer(), tz->stringLength())));
00205 
00206     result->value(LocalTime(tzPtr));
00207 }

void LocalTimestamp ( RegisterRef< int64_t > *  result,
RegisterRef< char * > *  tz,
RegisterRef< int32_t > *  precision 
)

Definition at line 240 of file ExtDateTime.cpp.

References LocalTimestamp(), RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_CHAR, STANDARD_TYPE_INT_32, STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::stringLength(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

00244 {
00245     assert (result->type() == STANDARD_TYPE_INT_64);
00246     assert (tz->type() == STANDARD_TYPE_CHAR);
00247     assert (precision->type() == STANDARD_TYPE_INT_32);
00248 
00249     time_zone_ptr tzPtr(
00250         new posix_time_zone(
00251             string(tz->pointer(), tz->stringLength())));
00252 
00253     // precision is ignored for now
00254     result->value(LocalTimestamp(tzPtr));
00255 }

void LocalTimestamp ( RegisterRef< int64_t > *  result,
RegisterRef< char * > *  tz 
)

Definition at line 209 of file ExtDateTime.cpp.

References RegisterRef< TMPLT >::pointer(), STANDARD_TYPE_CHAR, STANDARD_TYPE_INT_64, RegisterRef< TMPLT >::stringLength(), RegisterReference::type(), and RegisterRef< TMPLT >::value().

Referenced by ExtDateTimeRegister(), LocalTimestamp(), and SqlDateTest::testLocalTime().

00212 {
00213     assert (result->type() == STANDARD_TYPE_INT_64);
00214     assert (tz->type() == STANDARD_TYPE_CHAR);
00215 
00216     time_zone_ptr tzPtr(
00217         new posix_time_zone(
00218             string(tz->pointer(), tz->stringLength())));
00219 
00220     result->value(LocalTimestamp(tzPtr));
00221 }


Generated on Mon Jun 22 04:00:21 2009 for Fennel by  doxygen 1.5.1