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
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "ocilib_internal.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 OCI_Timestamp * OCI_TimestampInit(OCI_Connection *con, OCI_Timestamp **ptmsp,
00046 OCIDateTime *buffer, ub4 type)
00047 {
00048 OCI_Timestamp *tmsp = NULL;
00049
00050 #if OCI_VERSION_COMPILE >= OCI_9_0
00051
00052 boolean res = TRUE;
00053
00054 OCI_CHECK(ptmsp == NULL, NULL);
00055
00056 if (*ptmsp == NULL)
00057 *ptmsp = (OCI_Timestamp *) OCI_MemAlloc(OCI_IPC_TIMESTAMP, sizeof(*tmsp),
00058 1, TRUE);
00059
00060 if (*ptmsp != NULL)
00061 {
00062 tmsp = *ptmsp;
00063
00064 tmsp->con = con;
00065 tmsp->handle = buffer;
00066 tmsp->type = type;
00067
00068
00069
00070 if (con != NULL)
00071 tmsp->err = con->err;
00072 else
00073 tmsp->err = OCILib.err;
00074
00075
00076
00077 if (tmsp != NULL && tmsp->handle == NULL)
00078 {
00079 ub4 htype = 0;
00080
00081 tmsp->hstate = OCI_OBJECT_ALLOCATED;
00082
00083 if (tmsp->type == OCI_TIMESTAMP)
00084 htype = OCI_DTYPE_TIMESTAMP;
00085 else if (tmsp->type == OCI_TIMESTAMP_TZ)
00086 htype = OCI_DTYPE_TIMESTAMP_TZ;
00087 else if (tmsp->type == OCI_TIMESTAMP_LTZ)
00088 htype = OCI_DTYPE_TIMESTAMP_LTZ;
00089
00090 res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid *) OCILib.env,
00091 (dvoid **) (void *) &tmsp->handle,
00092 (ub4 ) htype, (size_t) 0,
00093 (dvoid **) NULL));
00094 }
00095 else
00096 tmsp->hstate = OCI_OBJECT_FETCHED_CLEAN;
00097 }
00098 else
00099 res = FALSE;
00100
00101
00102
00103 if (res == FALSE)
00104 {
00105 OCI_TimestampFree(tmsp);
00106 tmsp = NULL;
00107 }
00108
00109 #else
00110
00111 OCI_NOT_USED(con);
00112 OCI_NOT_USED(type);
00113 OCI_NOT_USED(buffer);
00114 OCI_NOT_USED(ptmsp);
00115
00116 #endif
00117
00118 return tmsp;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 OCI_Timestamp * OCI_API OCI_TimestampCreate(OCI_Connection *con,
00130 unsigned int type)
00131 {
00132 OCI_Timestamp *tmsp = NULL;
00133
00134 OCI_CHECK_INITIALIZED(NULL);
00135
00136 OCI_CHECK_TIMESTAMP_ENABLED(con, NULL);
00137
00138 #if OCI_VERSION_COMPILE >= OCI_9_0
00139
00140 tmsp = OCI_TimestampInit(con, &tmsp, NULL, type);
00141
00142 #else
00143
00144 OCI_NOT_USED(type);
00145
00146 #endif
00147
00148 OCI_RESULT(tmsp != NULL);
00149
00150 return tmsp;
00151 }
00152
00153
00154
00155
00156
00157 boolean OCI_API OCI_TimestampFree(OCI_Timestamp *tmsp)
00158 {
00159 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00160
00161 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00162
00163 #if OCI_VERSION_COMPILE >= OCI_9_0
00164
00165 OCI_CHECK_OBJECT_FETCHED(tmsp, FALSE);
00166
00167 if (tmsp->hstate == OCI_OBJECT_ALLOCATED)
00168 {
00169 ub4 htype = 0;
00170
00171 if (tmsp->type == OCI_TIMESTAMP)
00172 htype = OCI_DTYPE_TIMESTAMP;
00173 else if (tmsp->type == OCI_TIMESTAMP_TZ)
00174 htype = OCI_DTYPE_TIMESTAMP_TZ;
00175 else if (tmsp->type == OCI_TIMESTAMP_LTZ)
00176 htype = OCI_DTYPE_TIMESTAMP_LTZ;
00177
00178 OCI_DescriptorFree((dvoid *) tmsp->handle, htype);
00179 }
00180
00181 OCI_FREE(tmsp);
00182
00183 #endif
00184
00185 OCI_RESULT(TRUE);
00186
00187 return TRUE;
00188 }
00189
00190
00191
00192
00193
00194 unsigned int OCI_API OCI_TimestampGetType(OCI_Timestamp *tmsp)
00195 {
00196 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, OCI_UNKNOWN);
00197
00198 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, OCI_UNKNOWN);
00199
00200 OCI_RESULT(TRUE);
00201
00202 return tmsp->type;
00203 }
00204
00205
00206
00207
00208
00209 boolean OCI_API OCI_TimestampAssign(OCI_Timestamp *tmsp, OCI_Timestamp *tmsp_src)
00210 {
00211 boolean res = TRUE;
00212
00213 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00214 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp_src, FALSE);
00215
00216 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00217
00218 #if OCI_VERSION_COMPILE >= OCI_9_0
00219
00220 OCI_CALL4
00221 (
00222 res, tmsp->err, tmsp->con,
00223
00224 OCIDateTimeAssign((dvoid *) OCILib.env, tmsp->err,
00225 tmsp_src->handle, tmsp->handle)
00226 )
00227
00228 #endif
00229
00230 OCI_RESULT(res);
00231
00232 return res;
00233 }
00234
00235
00236
00237
00238
00239 int OCI_API OCI_TimestampCheck(OCI_Timestamp *tmsp)
00240 {
00241 boolean res = TRUE;
00242 ub4 value = 0;
00243
00244 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, value);
00245
00246 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, value);
00247
00248 #if OCI_VERSION_COMPILE >= OCI_9_0
00249
00250 OCI_CALL4
00251 (
00252 res, tmsp->err, tmsp->con,
00253
00254 OCIDateTimeCheck((dvoid *) OCILib.env, tmsp->err, tmsp->handle, &value)
00255 )
00256
00257 #endif
00258
00259 OCI_RESULT(res);
00260
00261 return (int) value;
00262 }
00263
00264
00265
00266
00267
00268 int OCI_API OCI_TimestampCompare(OCI_Timestamp *tmsp, OCI_Timestamp *tmsp2)
00269 {
00270 boolean res = TRUE;
00271 sword value = OCI_ERROR;
00272
00273 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, value);
00274 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp2, value);
00275
00276 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00277
00278 #if OCI_VERSION_COMPILE >= OCI_9_0
00279
00280 OCI_CALL4
00281 (
00282 res, tmsp->err, tmsp->con,
00283
00284 OCIDateTimeCompare((dvoid *) OCILib.env, tmsp->err,
00285 tmsp2->handle, tmsp2->handle, &value)
00286 )
00287
00288 #endif
00289
00290 OCI_RESULT(res);
00291
00292 return (int) value;
00293 }
00294
00295
00296
00297
00298
00299 boolean OCI_API OCI_TimestampConstruct(OCI_Timestamp *tmsp, int year,int month,
00300 int day, int hour, int min, int sec,
00301 int fsec, const mtext *timezone)
00302 {
00303 boolean res = TRUE;
00304
00305 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00306
00307 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00308
00309 #if OCI_VERSION_COMPILE >= OCI_9_0
00310
00311 OCI_CALL4
00312 (
00313 res, tmsp->err, tmsp->con,
00314
00315 OCIDateTimeConstruct((dvoid *) OCILib.env, tmsp->err,
00316 tmsp->handle,
00317 (sb2) year, (ub1) month, (ub1) day,
00318 (ub1) hour, (ub1) min,(ub1) sec,
00319 (ub4) fsec, (OraText *) timezone,
00320 (size_t) (timezone ? mtextsize(timezone) : 0))
00321 )
00322
00323 #else
00324
00325 OCI_NOT_USED(year);
00326 OCI_NOT_USED(month);
00327 OCI_NOT_USED(day);
00328 OCI_NOT_USED(hour);
00329 OCI_NOT_USED(min);
00330 OCI_NOT_USED(sec);
00331 OCI_NOT_USED(fsec);
00332 OCI_NOT_USED(timezone);
00333
00334 #endif
00335
00336 OCI_RESULT(res);
00337
00338 return res;
00339 }
00340
00341
00342
00343
00344
00345 boolean OCI_API OCI_TimestampConvert(OCI_Timestamp *tmsp, OCI_Timestamp *tmsp_src)
00346 {
00347 boolean res = TRUE;
00348
00349 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00350 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp_src, FALSE);
00351
00352 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00353
00354 #if OCI_VERSION_COMPILE >= OCI_9_0
00355
00356 OCI_CALL4
00357 (
00358 res, tmsp->err, tmsp->con,
00359
00360 OCIDateTimeConvert((dvoid *) OCILib.env, tmsp->err,
00361 tmsp_src->handle, tmsp->handle)
00362 )
00363
00364 #endif
00365
00366 OCI_RESULT(res);
00367
00368 return res;
00369 }
00370
00371
00372
00373
00374
00375 boolean OCI_API OCI_TimestampFromText(OCI_Timestamp *tmsp, const mtext *str,
00376 const mtext *fmt)
00377 {
00378 boolean res = TRUE;
00379 void *ostr1 = NULL;
00380 void *ostr2 = NULL;
00381 int osize1 = -1;
00382 int osize2 = -1;
00383
00384 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00385 OCI_CHECK_PTR(OCI_IPC_STRING, str, FALSE);
00386 OCI_CHECK_PTR(OCI_IPC_STRING, fmt, FALSE);
00387
00388 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00389
00390 #if OCI_VERSION_COMPILE >= OCI_9_0
00391
00392 ostr1 = OCI_GetInputMetaString(str, &osize1);
00393 ostr2 = OCI_GetInputMetaString(fmt, &osize2);
00394
00395 OCI_CALL4
00396 (
00397 res, tmsp->err, tmsp->con,
00398
00399 OCIDateTimeFromText((dvoid *) OCILib.env, tmsp->err,
00400 (OraText *) ostr1, (size_t) osize1,
00401 (OraText *) ostr2, (ub1) osize2,
00402 (OraText *) NULL, (size_t) 0,
00403 tmsp->handle)
00404 )
00405
00406 OCI_ReleaseMetaString(ostr1);
00407 OCI_ReleaseMetaString(ostr2);
00408
00409 #else
00410
00411 OCI_NOT_USED(ostr1);
00412 OCI_NOT_USED(ostr2);
00413 OCI_NOT_USED(osize1);
00414 OCI_NOT_USED(osize2);
00415
00416 #endif
00417
00418 OCI_RESULT(res);
00419
00420 return res;
00421 }
00422
00423
00424
00425
00426
00427 boolean OCI_API OCI_TimestampToText(OCI_Timestamp *tmsp, const mtext *fmt,
00428 int size, mtext *str, int precision)
00429 {
00430 boolean res = TRUE;
00431 void *ostr1 = NULL;
00432 void *ostr2 = NULL;
00433 int osize1 = size*sizeof(mtext);
00434 int osize2 = -1;
00435
00436 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00437 OCI_CHECK_PTR(OCI_IPC_STRING, str, FALSE);
00438 OCI_CHECK_PTR(OCI_IPC_STRING, fmt, FALSE);
00439
00440
00441
00442 str[0] = 0;
00443
00444 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00445
00446 #if OCI_VERSION_COMPILE >= OCI_9_0
00447
00448 ostr1 = OCI_GetInputMetaString(str, &osize1);
00449 ostr2 = OCI_GetInputMetaString(fmt, &osize2);
00450
00451 OCI_CALL4
00452 (
00453 res, tmsp->err, tmsp->con,
00454
00455 OCIDateTimeToText((dvoid *) OCILib.env, tmsp->err,
00456 tmsp->handle, (OraText *) ostr2,
00457 (ub1) osize2, (ub1) precision,
00458 (OraText *) NULL, (size_t) 0,
00459 (ub4*) &osize1, (OraText *) ostr1)
00460
00461 )
00462
00463 OCI_GetOutputMetaString(ostr1, str, &osize1);
00464
00465 OCI_ReleaseMetaString(ostr1);
00466 OCI_ReleaseMetaString(ostr2);
00467
00468
00469
00470 str[osize1/sizeof(mtext)] = 0;
00471
00472 #else
00473
00474 OCI_NOT_USED(ostr1);
00475 OCI_NOT_USED(ostr2);
00476 OCI_NOT_USED(osize1);
00477 OCI_NOT_USED(osize2);
00478 OCI_NOT_USED(precision);
00479
00480 #endif
00481
00482 OCI_RESULT(res);
00483
00484 return res;
00485 }
00486
00487
00488
00489
00490
00491 boolean OCI_API OCI_TimestampGetDate(OCI_Timestamp *tmsp, int *year, int *month,
00492 int *day)
00493 {
00494 boolean res = TRUE;
00495 sb2 yr = 0;
00496 ub1 mt = 0;
00497 ub1 dy = 0;
00498
00499 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00500
00501 OCI_CHECK_PTR(OCI_IPC_INT, year, FALSE);
00502 OCI_CHECK_PTR(OCI_IPC_INT, month, FALSE);
00503 OCI_CHECK_PTR(OCI_IPC_INT, day, FALSE);
00504
00505 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00506
00507 *year = 0;
00508 *month = 0;
00509 *day = 0;
00510
00511 #if OCI_VERSION_COMPILE >= OCI_9_0
00512
00513 OCI_CALL4
00514 (
00515 res, tmsp->err, tmsp->con,
00516
00517 OCIDateTimeGetDate((dvoid *) OCILib.env, tmsp->err, tmsp->handle,
00518 &yr, &mt, &dy)
00519 )
00520
00521 *year = (int) yr;
00522 *month = (int) mt;
00523 *day = (int) dy;
00524
00525 #else
00526
00527 OCI_NOT_USED(year);
00528 OCI_NOT_USED(month);
00529 OCI_NOT_USED(day);
00530 OCI_NOT_USED(yr);
00531 OCI_NOT_USED(mt);
00532 OCI_NOT_USED(dy);
00533
00534 #endif
00535
00536 OCI_RESULT(res);
00537
00538 return res;
00539 }
00540
00541
00542
00543
00544
00545 boolean OCI_API OCI_TimestampGetTime(OCI_Timestamp *tmsp, int *hour, int *min,
00546 int *sec, int *fsec)
00547 {
00548 boolean res = TRUE;
00549
00550 ub1 hr = 0;
00551 ub1 mn = 0;
00552 ub1 sc = 0;
00553 ub4 fs = 0;
00554
00555 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00556
00557 OCI_CHECK_PTR(OCI_IPC_INT, hour, FALSE);
00558 OCI_CHECK_PTR(OCI_IPC_INT, min, FALSE);
00559 OCI_CHECK_PTR(OCI_IPC_INT, sec, FALSE);
00560 OCI_CHECK_PTR(OCI_IPC_INT, fsec, FALSE);
00561
00562 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00563
00564 *hour = 0;
00565 *min = 0;
00566 *sec = 0;
00567 *fsec = 0;
00568
00569 #if OCI_VERSION_COMPILE >= OCI_9_0
00570
00571 OCI_CALL4
00572 (
00573 res, tmsp->err, tmsp->con,
00574
00575 OCIDateTimeGetTime((dvoid *) OCILib.env, tmsp->err, tmsp->handle,
00576 &hr, &mn, &sc, &fs)
00577 )
00578
00579 *hour = (int) hr;
00580 *min = (int) mn;
00581 *sec = (int) sc;
00582 *fsec = (int) fs;
00583
00584 #else
00585
00586 OCI_NOT_USED(hour);
00587 OCI_NOT_USED(min);
00588 OCI_NOT_USED(sec);
00589 OCI_NOT_USED(fsec);
00590 OCI_NOT_USED(hr);
00591 OCI_NOT_USED(mn);
00592 OCI_NOT_USED(sc);
00593 OCI_NOT_USED(fs);
00594
00595 #endif
00596
00597 OCI_RESULT(res);
00598
00599 return res;
00600 }
00601
00602
00603
00604
00605
00606 boolean OCI_API OCI_TimestampGetDateTime(OCI_Timestamp *tmsp, int *year,
00607 int *month, int *day, int *hour,
00608 int *min, int *sec, int *fsec)
00609 {
00610 return (OCI_TimestampGetDate(tmsp, year, month, day) &&
00611 OCI_TimestampGetTime(tmsp, hour, min, sec, fsec));
00612 }
00613
00614
00615
00616
00617
00618 boolean OCI_API OCI_TimestampGetTimeZoneName(OCI_Timestamp *tmsp, int size,
00619 mtext *str)
00620 {
00621 boolean res = TRUE;
00622 void *ostr = NULL;
00623 int osize = size*sizeof(mtext);
00624
00625 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00626 OCI_CHECK_PTR(OCI_IPC_STRING, str, FALSE);
00627
00628 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00629
00630 #if OCI_VERSION_COMPILE >= OCI_9_0
00631
00632 ostr = OCI_GetInputMetaString(str, &osize);
00633
00634 OCI_CALL4
00635 (
00636 res, tmsp->err, tmsp->con,
00637
00638 OCIDateTimeGetTimeZoneName((dvoid *) OCILib.env, tmsp->err, tmsp->handle,
00639 (ub1*) ostr, (ub4*) &osize)
00640 )
00641
00642 OCI_GetOutputMetaString(ostr, str, &osize);
00643
00644 OCI_ReleaseMetaString(ostr);
00645
00646
00647
00648 str[osize/sizeof(mtext)] = 0;
00649
00650 #else
00651
00652 OCI_NOT_USED(str);
00653 OCI_NOT_USED(size);
00654 OCI_NOT_USED(ostr);
00655 OCI_NOT_USED(osize);
00656
00657 #endif
00658
00659 OCI_RESULT(res);
00660
00661 return res;
00662 }
00663
00664
00665
00666
00667
00668 boolean OCI_API OCI_TimestampGetTimeZoneOffset(OCI_Timestamp *tmsp,
00669 int *hour, int *min)
00670 {
00671 boolean res = TRUE;
00672
00673 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00674 OCI_CHECK_PTR(OCI_IPC_INT, hour, FALSE);
00675 OCI_CHECK_PTR(OCI_IPC_INT, min, FALSE);
00676
00677 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00678
00679 #if OCI_VERSION_COMPILE >= OCI_9_0
00680
00681 OCI_CALL4
00682 (
00683 res, tmsp->err, tmsp->con,
00684
00685 OCIDateTimeGetTimeZoneOffset((dvoid *) OCILib.env, tmsp->err,
00686 tmsp->handle, (sb1*) hour, (sb1*) min)
00687 )
00688
00689 #else
00690
00691 OCI_NOT_USED(hour);
00692 OCI_NOT_USED(min);
00693
00694 #endif
00695
00696 OCI_RESULT(res);
00697
00698 return res;
00699 }
00700
00701
00702
00703
00704
00705 boolean OCI_API OCI_TimestampIntervalAdd(OCI_Timestamp *tmsp, OCI_Interval *itv)
00706 {
00707 boolean res = TRUE;
00708 OCI_Timestamp *tmp = NULL;
00709
00710 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00711 OCI_CHECK_PTR(OCI_IPC_INTERVAL, itv, FALSE);
00712
00713 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00714
00715 #if OCI_VERSION_COMPILE >= OCI_9_0
00716
00717
00718
00719 if ((res == TRUE) && (tmsp->type != OCI_TIMESTAMP_TZ))
00720 {
00721 tmp = OCI_TimestampCreate(tmsp->con, OCI_TIMESTAMP_TZ);
00722
00723 res = OCI_TimestampConvert(tmp, tmsp);
00724 }
00725 else
00726 tmp = tmsp;
00727
00728 OCI_CALL4
00729 (
00730 res, tmsp->err, tmsp->con,
00731
00732 OCIDateTimeIntervalAdd((dvoid *) OCILib.env, tmp->err, tmp->handle,
00733 itv->handle, tmp->handle)
00734 )
00735
00736
00737
00738 if ((res == TRUE) && (tmsp->type != OCI_TIMESTAMP_TZ))
00739 {
00740 res = OCI_TimestampConvert(tmsp, tmp);
00741
00742 OCI_TimestampFree(tmp);
00743 }
00744
00745 #else
00746
00747 OCI_NOT_USED(tmp);
00748
00749 #endif
00750
00751 OCI_RESULT(res);
00752
00753 return res;
00754 }
00755
00756
00757
00758
00759
00760 boolean OCI_API OCI_TimestampIntervalSub(OCI_Timestamp *tmsp,
00761 OCI_Interval *itv)
00762 {
00763 boolean res = TRUE;
00764 OCI_Timestamp *tmp = NULL;
00765
00766 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00767 OCI_CHECK_PTR(OCI_IPC_INTERVAL, itv, FALSE);
00768
00769 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00770
00771 #if OCI_VERSION_COMPILE >= OCI_9_0
00772
00773
00774
00775 if ((res == TRUE) && (tmsp->type != OCI_TIMESTAMP_TZ))
00776 {
00777 tmp = OCI_TimestampCreate(tmsp->con, OCI_TIMESTAMP_TZ);
00778
00779 res = OCI_TimestampConvert(tmp, tmsp);
00780 }
00781 else
00782 tmp = tmsp;
00783
00784 OCI_CALL4
00785 (
00786 res, tmsp->err, tmsp->con,
00787
00788 OCIDateTimeIntervalSub((dvoid *) OCILib.env, tmp->err, tmp->handle,
00789 itv->handle, tmp->handle)
00790 )
00791
00792
00793
00794 if ((res == TRUE) && (tmsp->type != OCI_TIMESTAMP_TZ))
00795 {
00796 res = OCI_TimestampConvert(tmsp, tmp);
00797
00798 OCI_TimestampFree(tmp);
00799 }
00800
00801 #else
00802
00803 OCI_NOT_USED(tmp);
00804
00805 #endif
00806
00807 OCI_RESULT(res);
00808
00809 return res;
00810 }
00811
00812
00813
00814
00815
00816 boolean OCI_API OCI_TimestampSubtract(OCI_Timestamp *tmsp, OCI_Timestamp *tmsp2,
00817 OCI_Interval *itv)
00818 {
00819 boolean res = TRUE;
00820
00821 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00822 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp2, FALSE);
00823 OCI_CHECK_PTR(OCI_IPC_INTERVAL, itv, FALSE);
00824
00825 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00826
00827 #if OCI_VERSION_COMPILE >= OCI_9_0
00828
00829 OCI_CALL4
00830 (
00831 res, tmsp->err, tmsp->con,
00832
00833 OCIDateTimeSubtract((dvoid *) OCILib.env, tmsp->err, tmsp->handle,
00834 tmsp2->handle, itv->handle)
00835 )
00836
00837 #endif
00838
00839 OCI_RESULT(res);
00840
00841 return res;
00842 }
00843
00844
00845
00846
00847
00848 boolean OCI_API OCI_TimestampSysTimeStamp(OCI_Timestamp *tmsp)
00849 {
00850 boolean res = TRUE;
00851 OCI_Timestamp *tmp = NULL;
00852 OCIDateTime *handle = NULL;
00853
00854 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00855
00856 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00857
00858 #if OCI_VERSION_COMPILE >= OCI_9_0
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868 if ((res == TRUE) && (tmsp->type == OCI_TIMESTAMP))
00869 {
00870 tmp = OCI_TimestampCreate(tmsp->con, OCI_TIMESTAMP_TZ);
00871
00872 handle = tmp->handle;
00873 }
00874 else
00875 handle = tmsp->handle;
00876
00877 OCI_CALL4
00878 (
00879 res, tmsp->err, tmsp->con,
00880
00881 OCIDateTimeSysTimeStamp((dvoid *) OCILib.env, tmsp->err, handle)
00882 )
00883
00884 if ((res == TRUE) && (tmsp->type == OCI_TIMESTAMP))
00885 {
00886 res = OCI_TimestampConvert(tmsp, tmp);
00887
00888 OCI_TimestampFree(tmp);
00889 }
00890
00891 #else
00892
00893 OCI_NOT_USED(tmp);
00894 OCI_NOT_USED(handle);
00895
00896 #endif
00897
00898 OCI_RESULT(res);
00899
00900 return res;
00901 }
00902
00903
00904
00905
00906
00907 boolean OCI_API OCI_TimestampToCTime(OCI_Timestamp *tmsp, struct tm *ptm,
00908 time_t *pt)
00909 {
00910 boolean res = TRUE;
00911 time_t time = -1;
00912 int msec = 0;
00913 struct tm t;
00914
00915 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00916
00917 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00918
00919 res = OCI_TimestampGetDateTime(tmsp, &t.tm_year, &t.tm_mon, &t.tm_mday,
00920 &t.tm_hour, &t.tm_min, &t.tm_sec,
00921 &msec);
00922
00923
00924 if (res == TRUE)
00925 {
00926 t.tm_year -= 1900;
00927 t.tm_mon -= 1;
00928 t.tm_wday = 0;
00929 t.tm_yday = 0;
00930 t.tm_isdst = -1;
00931
00932 time = mktime(&t);
00933
00934 if (ptm != NULL)
00935 memcpy(ptm, &t, sizeof(t));
00936
00937 if (pt != NULL)
00938 *pt = time;
00939 }
00940
00941 OCI_RESULT(res);
00942
00943 return (time != -1);
00944 }
00945
00946
00947
00948
00949
00950 boolean OCI_API OCI_TimestampFromCTime(OCI_Timestamp *tmsp, struct tm *ptm,
00951 time_t t)
00952 {
00953 boolean res = TRUE;
00954
00955 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE);
00956
00957 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE);
00958
00959 if (ptm == NULL && t == 0)
00960 return FALSE;
00961
00962 if (ptm == NULL)
00963 ptm = localtime(&t);
00964
00965 res = OCI_TimestampConstruct(tmsp,
00966 ptm->tm_year + 1900,
00967 ptm->tm_mon + 1,
00968 ptm->tm_mday,
00969 ptm->tm_hour,
00970 ptm->tm_min,
00971 ptm->tm_sec,
00972 (int) 0,
00973 (const mtext *) NULL);
00974
00975 OCI_RESULT(res);
00976
00977 return res;
00978 }