OCILIB (C Driver for Oracle) 3.12.1
|
00001 /* 00002 +-----------------------------------------------------------------------------------------+ 00003 | | 00004 | OCILIB - C Driver for Oracle | 00005 | | 00006 | (C Wrapper for Oracle OCI) | 00007 | | 00008 | Website : http://www.ocilib.net | 00009 | | 00010 | Copyright (c) 2007-2013 Vincent ROGIER <vince.rogier@ocilib.net> | 00011 | | 00012 +-----------------------------------------------------------------------------------------+ 00013 | | 00014 | This library is free software; you can redistribute it and/or | 00015 | modify it under the terms of the GNU Lesser General Public | 00016 | License as published by the Free Software Foundation; either | 00017 | version 2 of the License, or (at your option) any later version. | 00018 | | 00019 | This library is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 00022 | Lesser General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU Lesser General Public | 00025 | License along with this library; if not, write to the Free | 00026 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 00027 | | 00028 +-----------------------------------------------------------------------------------------+ 00029 */ 00030 00031 /* --------------------------------------------------------------------------------------------- * 00032 * $Id: timestamp.c, Vincent Rogier $ 00033 * --------------------------------------------------------------------------------------------- */ 00034 00035 #include "ocilib_internal.h" 00036 00037 /* ********************************************************************************************* * 00038 * PRIVATE FUNCTIONS 00039 * ********************************************************************************************* */ 00040 00041 /* --------------------------------------------------------------------------------------------- * 00042 * OCI_TimestampInit 00043 * --------------------------------------------------------------------------------------------- */ 00044 00045 OCI_Timestamp * OCI_TimestampInit 00046 ( 00047 OCI_Connection *con, 00048 OCI_Timestamp **ptmsp, 00049 OCIDateTime *buffer, 00050 ub4 type 00051 ) 00052 { 00053 OCI_Timestamp *tmsp = NULL; 00054 00055 #if OCI_VERSION_COMPILE >= OCI_9_0 00056 00057 boolean res = TRUE; 00058 00059 OCI_CHECK(ptmsp == NULL, NULL); 00060 00061 if (*ptmsp == NULL) 00062 { 00063 *ptmsp = (OCI_Timestamp *) OCI_MemAlloc(OCI_IPC_TIMESTAMP, sizeof(*tmsp), (size_t) 1, TRUE); 00064 } 00065 00066 if (*ptmsp != NULL) 00067 { 00068 tmsp = *ptmsp; 00069 00070 tmsp->con = con; 00071 tmsp->handle = buffer; 00072 tmsp->type = type; 00073 00074 /* get the right error handle */ 00075 00076 if (con != NULL) 00077 { 00078 tmsp->err = con->err; 00079 tmsp->env = con->env; 00080 } 00081 else 00082 { 00083 tmsp->err = OCILib.err; 00084 tmsp->env = OCILib.env; 00085 } 00086 00087 /* allocate buffer if needed */ 00088 00089 if ((tmsp->handle == NULL) || (tmsp->hstate == OCI_OBJECT_ALLOCATED_ARRAY)) 00090 { 00091 ub4 htype = 0; 00092 00093 if (tmsp->type == OCI_TIMESTAMP) 00094 { 00095 htype = OCI_DTYPE_TIMESTAMP; 00096 } 00097 else if (tmsp->type == OCI_TIMESTAMP_TZ) 00098 { 00099 htype = OCI_DTYPE_TIMESTAMP_TZ; 00100 } 00101 else if (tmsp->type == OCI_TIMESTAMP_LTZ) 00102 { 00103 htype = OCI_DTYPE_TIMESTAMP_LTZ; 00104 } 00105 00106 if (tmsp->hstate != OCI_OBJECT_ALLOCATED_ARRAY) 00107 { 00108 res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid *) tmsp->env, 00109 (dvoid **) (void *) &tmsp->handle, 00110 (ub4 ) htype, (size_t) 0, 00111 (dvoid **) NULL)); 00112 tmsp->hstate = OCI_OBJECT_ALLOCATED; 00113 } 00114 00115 } 00116 else 00117 { 00118 tmsp->hstate = OCI_OBJECT_FETCHED_CLEAN; 00119 } 00120 } 00121 else 00122 { 00123 res = FALSE; 00124 } 00125 00126 /* check for failure */ 00127 00128 if (res == FALSE) 00129 { 00130 OCI_TimestampFree(tmsp); 00131 tmsp = NULL; 00132 } 00133 00134 #else 00135 00136 OCI_NOT_USED(con); 00137 OCI_NOT_USED(type); 00138 OCI_NOT_USED(buffer); 00139 OCI_NOT_USED(ptmsp); 00140 00141 #endif 00142 00143 return tmsp; 00144 } 00145 00146 /* ********************************************************************************************* * 00147 * PUBLIC FUNCTIONS 00148 * ********************************************************************************************* */ 00149 00150 /* --------------------------------------------------------------------------------------------- * 00151 * OCI_TimestampCreate 00152 * --------------------------------------------------------------------------------------------- */ 00153 00154 OCI_Timestamp * OCI_API OCI_TimestampCreate 00155 ( 00156 OCI_Connection *con, 00157 unsigned int type 00158 ) 00159 { 00160 OCI_Timestamp *tmsp = NULL; 00161 00162 OCI_CHECK_INITIALIZED(NULL); 00163 00164 OCI_CHECK_TIMESTAMP_ENABLED(con, NULL); 00165 00166 #if OCI_VERSION_COMPILE >= OCI_9_0 00167 00168 tmsp = OCI_TimestampInit(con, &tmsp, NULL, type); 00169 00170 #else 00171 00172 OCI_NOT_USED(type); 00173 00174 #endif 00175 00176 OCI_RESULT(tmsp != NULL); 00177 00178 return tmsp; 00179 } 00180 00181 /* --------------------------------------------------------------------------------------------- * 00182 * OCI_TimestampFree 00183 * --------------------------------------------------------------------------------------------- */ 00184 00185 boolean OCI_API OCI_TimestampFree 00186 ( 00187 OCI_Timestamp *tmsp 00188 ) 00189 { 00190 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00191 00192 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00193 00194 #if OCI_VERSION_COMPILE >= OCI_9_0 00195 00196 OCI_CHECK_OBJECT_FETCHED(tmsp, FALSE); 00197 00198 if (tmsp->hstate == OCI_OBJECT_ALLOCATED) 00199 { 00200 ub4 htype = 0; 00201 00202 if (tmsp->type == OCI_TIMESTAMP) 00203 { 00204 htype = OCI_DTYPE_TIMESTAMP; 00205 } 00206 else if (tmsp->type == OCI_TIMESTAMP_TZ) 00207 { 00208 htype = OCI_DTYPE_TIMESTAMP_TZ; 00209 } 00210 else if (tmsp->type == OCI_TIMESTAMP_LTZ) 00211 { 00212 htype = OCI_DTYPE_TIMESTAMP_LTZ; 00213 } 00214 00215 OCI_DescriptorFree((dvoid *) tmsp->handle, htype); 00216 } 00217 00218 if (tmsp->hstate != OCI_OBJECT_ALLOCATED_ARRAY) 00219 { 00220 OCI_FREE(tmsp); 00221 } 00222 00223 #endif 00224 00225 OCI_RESULT(TRUE); 00226 00227 return TRUE; 00228 } 00229 00230 /* --------------------------------------------------------------------------------------------- * 00231 * OCI_TimestampArrayCreate 00232 * --------------------------------------------------------------------------------------------- */ 00233 00234 OCI_Timestamp ** OCI_API OCI_TimestampArrayCreate 00235 ( 00236 OCI_Connection *con, 00237 unsigned int type, 00238 unsigned int nbelem 00239 ) 00240 { 00241 OCI_Array *arr = NULL; 00242 OCI_Timestamp **tmsps = NULL; 00243 unsigned int htype = 0; 00244 00245 OCI_CHECK_TIMESTAMP_ENABLED(con, NULL); 00246 00247 #if OCI_VERSION_COMPILE >= OCI_9_0 00248 00249 if (type == OCI_TIMESTAMP) 00250 { 00251 htype = OCI_DTYPE_TIMESTAMP; 00252 } 00253 else if (type == OCI_TIMESTAMP_TZ) 00254 { 00255 htype = OCI_DTYPE_TIMESTAMP_TZ; 00256 } 00257 else if (type == OCI_TIMESTAMP_LTZ) 00258 { 00259 htype = OCI_DTYPE_TIMESTAMP_LTZ; 00260 } 00261 00262 arr = OCI_ArrayCreate(con, nbelem, OCI_CDT_TIMESTAMP, type,sizeof(OCIDateTime *), 00263 sizeof(OCI_Timestamp), htype, NULL); 00264 00265 if (arr != NULL) 00266 { 00267 tmsps = (OCI_Timestamp **) arr->tab_obj; 00268 } 00269 00270 #else 00271 00272 OCI_NOT_USED(arr); 00273 OCI_NOT_USED(type); 00274 OCI_NOT_USED(nbelem); 00275 OCI_NOT_USED(htype); 00276 00277 #endif 00278 00279 return tmsps; 00280 } 00281 00282 /* --------------------------------------------------------------------------------------------- * 00283 * OCI_TimestampArrayFree 00284 * --------------------------------------------------------------------------------------------- */ 00285 00286 boolean OCI_API OCI_TimestampArrayFree 00287 ( 00288 OCI_Timestamp **tmsps 00289 ) 00290 { 00291 return OCI_ArrayFreeFromHandles((void **) tmsps); 00292 } 00293 00294 /* --------------------------------------------------------------------------------------------- * 00295 * OCI_TimestampGetType 00296 * --------------------------------------------------------------------------------------------- */ 00297 00298 unsigned int OCI_API OCI_TimestampGetType 00299 ( 00300 OCI_Timestamp *tmsp 00301 ) 00302 { 00303 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, OCI_UNKNOWN); 00304 00305 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, OCI_UNKNOWN); 00306 00307 OCI_RESULT(TRUE); 00308 00309 return tmsp->type; 00310 } 00311 00312 /* --------------------------------------------------------------------------------------------- * 00313 * OCI_DateZoneToZone 00314 * --------------------------------------------------------------------------------------------- */ 00315 00316 boolean OCI_API OCI_TimestampAssign 00317 ( 00318 OCI_Timestamp *tmsp, 00319 OCI_Timestamp *tmsp_src 00320 ) 00321 { 00322 boolean res = TRUE; 00323 00324 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00325 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp_src, FALSE); 00326 00327 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00328 00329 #if OCI_VERSION_COMPILE >= OCI_9_0 00330 00331 OCI_CALL4 00332 ( 00333 res, tmsp->err, tmsp->con, 00334 00335 OCIDateTimeAssign((dvoid *) tmsp->env, tmsp->err, 00336 tmsp_src->handle, tmsp->handle) 00337 ) 00338 00339 #endif 00340 00341 OCI_RESULT(res); 00342 00343 return res; 00344 } 00345 00346 /* --------------------------------------------------------------------------------------------- * 00347 * OCI_TimestampCheck 00348 * --------------------------------------------------------------------------------------------- */ 00349 00350 int OCI_API OCI_TimestampCheck 00351 ( 00352 OCI_Timestamp *tmsp 00353 ) 00354 { 00355 boolean res = TRUE; 00356 ub4 value = 0; 00357 00358 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, value); 00359 00360 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, value); 00361 00362 #if OCI_VERSION_COMPILE >= OCI_9_0 00363 00364 OCI_CALL4 00365 ( 00366 res, tmsp->err, tmsp->con, 00367 00368 OCIDateTimeCheck((dvoid *) tmsp->env, tmsp->err, tmsp->handle, &value) 00369 ) 00370 00371 #endif 00372 00373 OCI_RESULT(res); 00374 00375 return (int) value; 00376 } 00377 00378 /* --------------------------------------------------------------------------------------------- * 00379 * OCI_TimestampCompare 00380 * --------------------------------------------------------------------------------------------- */ 00381 00382 int OCI_API OCI_TimestampCompare 00383 ( 00384 OCI_Timestamp *tmsp, 00385 OCI_Timestamp *tmsp2 00386 ) 00387 { 00388 boolean res = TRUE; 00389 sword value = OCI_ERROR; 00390 00391 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, value); 00392 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp2, value); 00393 00394 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00395 00396 #if OCI_VERSION_COMPILE >= OCI_9_0 00397 00398 OCI_CALL4 00399 ( 00400 res, tmsp->err, tmsp->con, 00401 00402 OCIDateTimeCompare((dvoid *) tmsp->env, tmsp->err, 00403 tmsp2->handle, tmsp2->handle, &value) 00404 ) 00405 00406 #endif 00407 00408 OCI_RESULT(res); 00409 00410 return (int) value; 00411 } 00412 00413 /* --------------------------------------------------------------------------------------------- * 00414 * OCI_TimestampConstruct 00415 * --------------------------------------------------------------------------------------------- */ 00416 00417 boolean OCI_API OCI_TimestampConstruct 00418 ( 00419 OCI_Timestamp *tmsp, 00420 int year, 00421 int month, 00422 int day, 00423 int hour, 00424 int min, 00425 int sec, 00426 int fsec, 00427 const mtext *time_zone 00428 ) 00429 { 00430 boolean res = TRUE; 00431 00432 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00433 00434 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00435 00436 #if OCI_VERSION_COMPILE >= OCI_9_0 00437 00438 OCI_CALL4 00439 ( 00440 res, tmsp->err, tmsp->con, 00441 00442 OCIDateTimeConstruct((dvoid *) tmsp->env, tmsp->err, 00443 tmsp->handle, 00444 (sb2) year, (ub1) month, (ub1) day, 00445 (ub1) hour, (ub1) min,(ub1) sec, 00446 (ub4) fsec, (OraText *) time_zone, 00447 (size_t) (time_zone ? mtextsize(time_zone) : 0)) 00448 ) 00449 00450 #else 00451 00452 OCI_NOT_USED(year); 00453 OCI_NOT_USED(month); 00454 OCI_NOT_USED(day); 00455 OCI_NOT_USED(hour); 00456 OCI_NOT_USED(min); 00457 OCI_NOT_USED(sec); 00458 OCI_NOT_USED(fsec); 00459 OCI_NOT_USED(time_zone); 00460 00461 #endif 00462 00463 OCI_RESULT(res); 00464 00465 return res; 00466 } 00467 00468 /* --------------------------------------------------------------------------------------------- * 00469 * OCI_TimestampConvert 00470 * --------------------------------------------------------------------------------------------- */ 00471 00472 boolean OCI_API OCI_TimestampConvert 00473 ( 00474 OCI_Timestamp *tmsp, 00475 OCI_Timestamp *tmsp_src 00476 ) 00477 { 00478 boolean res = TRUE; 00479 00480 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00481 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp_src, FALSE); 00482 00483 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00484 00485 #if OCI_VERSION_COMPILE >= OCI_9_0 00486 00487 OCI_CALL4 00488 ( 00489 res, tmsp->err, tmsp->con, 00490 00491 OCIDateTimeConvert((dvoid *) tmsp->env, tmsp->err, 00492 tmsp_src->handle, tmsp->handle) 00493 ) 00494 00495 #endif 00496 00497 OCI_RESULT(res); 00498 00499 return res; 00500 } 00501 00502 /* --------------------------------------------------------------------------------------------- * 00503 * OCI_TimestampFromText 00504 * --------------------------------------------------------------------------------------------- */ 00505 00506 boolean OCI_API OCI_TimestampFromText 00507 ( 00508 OCI_Timestamp *tmsp, 00509 const mtext *str, 00510 const mtext *fmt 00511 ) 00512 { 00513 boolean res = TRUE; 00514 void *ostr1 = NULL; 00515 void *ostr2 = NULL; 00516 int osize1 = -1; 00517 int osize2 = -1; 00518 00519 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00520 OCI_CHECK_PTR(OCI_IPC_STRING, str, FALSE); 00521 OCI_CHECK_PTR(OCI_IPC_STRING, fmt, FALSE); 00522 00523 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00524 00525 #if OCI_VERSION_COMPILE >= OCI_9_0 00526 00527 ostr1 = OCI_GetInputMetaString(str, &osize1); 00528 ostr2 = OCI_GetInputMetaString(fmt, &osize2); 00529 00530 OCI_CALL4 00531 ( 00532 res, tmsp->err, tmsp->con, 00533 00534 OCIDateTimeFromText((dvoid *) tmsp->env, tmsp->err, 00535 (OraText *) ostr1, (size_t) osize1, 00536 (OraText *) ostr2, (ub1) osize2, 00537 (OraText *) NULL, (size_t) 0, 00538 tmsp->handle) 00539 ) 00540 00541 OCI_ReleaseMetaString(ostr1); 00542 OCI_ReleaseMetaString(ostr2); 00543 00544 #else 00545 00546 OCI_NOT_USED(ostr1); 00547 OCI_NOT_USED(ostr2); 00548 OCI_NOT_USED(osize1); 00549 OCI_NOT_USED(osize2); 00550 00551 #endif 00552 00553 OCI_RESULT(res); 00554 00555 return res; 00556 } 00557 00558 /* --------------------------------------------------------------------------------------------- * 00559 * OCI_TimestampToText 00560 * --------------------------------------------------------------------------------------------- */ 00561 00562 boolean OCI_API OCI_TimestampToText 00563 ( 00564 OCI_Timestamp *tmsp, 00565 const mtext *fmt, 00566 int size, 00567 mtext *str, 00568 int precision 00569 ) 00570 { 00571 boolean res = TRUE; 00572 void *ostr1 = NULL; 00573 void *ostr2 = NULL; 00574 int osize1 = size * (int) sizeof(mtext); 00575 int osize2 = -1; 00576 00577 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00578 OCI_CHECK_PTR(OCI_IPC_STRING, str, FALSE); 00579 OCI_CHECK_PTR(OCI_IPC_STRING, fmt, FALSE); 00580 00581 /* init output buffer in case of OCI failure */ 00582 00583 str[0] = 0; 00584 00585 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00586 00587 #if OCI_VERSION_COMPILE >= OCI_9_0 00588 00589 ostr1 = OCI_GetInputMetaString(str, &osize1); 00590 ostr2 = OCI_GetInputMetaString(fmt, &osize2); 00591 00592 OCI_CALL4 00593 ( 00594 res, tmsp->err, tmsp->con, 00595 00596 OCIDateTimeToText((dvoid *) tmsp->env, tmsp->err, 00597 tmsp->handle, (OraText *) ostr2, 00598 (ub1) osize2, (ub1) precision, 00599 (OraText *) NULL, (size_t) 0, 00600 (ub4*) &osize1, (OraText *) ostr1) 00601 00602 ) 00603 00604 OCI_GetOutputMetaString(ostr1, str, &osize1); 00605 00606 OCI_ReleaseMetaString(ostr1); 00607 OCI_ReleaseMetaString(ostr2); 00608 00609 /* set null string terminator */ 00610 00611 str[osize1/ (int) sizeof(mtext)] = 0; 00612 00613 #else 00614 00615 OCI_NOT_USED(ostr1); 00616 OCI_NOT_USED(ostr2); 00617 OCI_NOT_USED(osize1); 00618 OCI_NOT_USED(osize2); 00619 OCI_NOT_USED(precision); 00620 00621 #endif 00622 00623 OCI_RESULT(res); 00624 00625 return res; 00626 } 00627 00628 /* --------------------------------------------------------------------------------------------- * 00629 * OCI_TimestampGetDate 00630 * --------------------------------------------------------------------------------------------- */ 00631 00632 boolean OCI_API OCI_TimestampGetDate 00633 ( 00634 OCI_Timestamp *tmsp, 00635 int *year, 00636 int *month, 00637 int *day 00638 ) 00639 { 00640 boolean res = TRUE; 00641 sb2 yr = 0; 00642 ub1 mt = 0; 00643 ub1 dy = 0; 00644 00645 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00646 00647 OCI_CHECK_PTR(OCI_IPC_INT, year, FALSE); 00648 OCI_CHECK_PTR(OCI_IPC_INT, month, FALSE); 00649 OCI_CHECK_PTR(OCI_IPC_INT, day, FALSE); 00650 00651 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00652 00653 *year = 0; 00654 *month = 0; 00655 *day = 0; 00656 00657 #if OCI_VERSION_COMPILE >= OCI_9_0 00658 00659 OCI_CALL4 00660 ( 00661 res, tmsp->err, tmsp->con, 00662 00663 OCIDateTimeGetDate((dvoid *) tmsp->env, tmsp->err, tmsp->handle, 00664 &yr, &mt, &dy) 00665 ) 00666 00667 *year = (int) yr; 00668 *month = (int) mt; 00669 *day = (int) dy; 00670 00671 #else 00672 00673 OCI_NOT_USED(year); 00674 OCI_NOT_USED(month); 00675 OCI_NOT_USED(day); 00676 OCI_NOT_USED(yr); 00677 OCI_NOT_USED(mt); 00678 OCI_NOT_USED(dy); 00679 00680 #endif 00681 00682 OCI_RESULT(res); 00683 00684 return res; 00685 } 00686 00687 /* --------------------------------------------------------------------------------------------- * 00688 * OCI_TimestampGetTime 00689 * --------------------------------------------------------------------------------------------- */ 00690 00691 boolean OCI_API OCI_TimestampGetTime 00692 ( 00693 OCI_Timestamp *tmsp, 00694 int *hour, 00695 int *min, 00696 int *sec, 00697 int *fsec 00698 ) 00699 { 00700 boolean res = TRUE; 00701 00702 ub1 hr = 0; 00703 ub1 mn = 0; 00704 ub1 sc = 0; 00705 ub4 fs = 0; 00706 00707 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00708 00709 OCI_CHECK_PTR(OCI_IPC_INT, hour, FALSE); 00710 OCI_CHECK_PTR(OCI_IPC_INT, min, FALSE); 00711 OCI_CHECK_PTR(OCI_IPC_INT, sec, FALSE); 00712 OCI_CHECK_PTR(OCI_IPC_INT, fsec, FALSE); 00713 00714 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00715 00716 *hour = 0; 00717 *min = 0; 00718 *sec = 0; 00719 *fsec = 0; 00720 00721 #if OCI_VERSION_COMPILE >= OCI_9_0 00722 00723 OCI_CALL4 00724 ( 00725 res, tmsp->err, tmsp->con, 00726 00727 OCIDateTimeGetTime((dvoid *) tmsp->env, tmsp->err, tmsp->handle, 00728 &hr, &mn, &sc, &fs) 00729 ) 00730 00731 *hour = (int) hr; 00732 *min = (int) mn; 00733 *sec = (int) sc; 00734 *fsec = (int) fs; 00735 00736 #else 00737 00738 OCI_NOT_USED(hour); 00739 OCI_NOT_USED(min); 00740 OCI_NOT_USED(sec); 00741 OCI_NOT_USED(fsec); 00742 OCI_NOT_USED(hr); 00743 OCI_NOT_USED(mn); 00744 OCI_NOT_USED(sc); 00745 OCI_NOT_USED(fs); 00746 00747 #endif 00748 00749 OCI_RESULT(res); 00750 00751 return res; 00752 } 00753 00754 /* --------------------------------------------------------------------------------------------- * 00755 * OCI_TimestampGetDateTime 00756 * --------------------------------------------------------------------------------------------- */ 00757 00758 boolean OCI_API OCI_TimestampGetDateTime 00759 ( 00760 OCI_Timestamp *tmsp, 00761 int *year, 00762 int *month, 00763 int *day, 00764 int *hour, 00765 int *min, 00766 int *sec, 00767 int *fsec 00768 ) 00769 { 00770 return (OCI_TimestampGetDate(tmsp, year, month, day) && 00771 OCI_TimestampGetTime(tmsp, hour, min, sec, fsec)); 00772 } 00773 00774 /* --------------------------------------------------------------------------------------------- * 00775 * OCI_TimestampGetTimeZoneName 00776 * --------------------------------------------------------------------------------------------- */ 00777 00778 boolean OCI_API OCI_TimestampGetTimeZoneName 00779 ( 00780 OCI_Timestamp *tmsp, 00781 int size, 00782 mtext *str 00783 ) 00784 { 00785 boolean res = TRUE; 00786 void *ostr = NULL; 00787 int osize = size * (int) sizeof(mtext); 00788 00789 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00790 OCI_CHECK_PTR(OCI_IPC_STRING, str, FALSE); 00791 00792 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00793 00794 #if OCI_VERSION_COMPILE >= OCI_9_0 00795 00796 ostr = OCI_GetInputMetaString(str, &osize); 00797 00798 OCI_CALL4 00799 ( 00800 res, tmsp->err, tmsp->con, 00801 00802 OCIDateTimeGetTimeZoneName((dvoid *) tmsp->env, tmsp->err, tmsp->handle, 00803 (ub1*) ostr, (ub4*) &osize) 00804 ) 00805 00806 OCI_GetOutputMetaString(ostr, str, &osize); 00807 00808 OCI_ReleaseMetaString(ostr); 00809 00810 /* set null string terminator */ 00811 00812 str[osize/ (int) sizeof(mtext)] = 0; 00813 00814 #else 00815 00816 OCI_NOT_USED(str); 00817 OCI_NOT_USED(size); 00818 OCI_NOT_USED(ostr); 00819 OCI_NOT_USED(osize); 00820 00821 #endif 00822 00823 OCI_RESULT(res); 00824 00825 return res; 00826 } 00827 00828 /* --------------------------------------------------------------------------------------------- * 00829 * OCI_TimestampGetTimeZoneOffset 00830 * --------------------------------------------------------------------------------------------- */ 00831 00832 boolean OCI_API OCI_TimestampGetTimeZoneOffset 00833 ( 00834 OCI_Timestamp *tmsp, 00835 int *hour, 00836 int *min 00837 ) 00838 { 00839 boolean res = TRUE; 00840 00841 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00842 OCI_CHECK_PTR(OCI_IPC_INT, hour, FALSE); 00843 OCI_CHECK_PTR(OCI_IPC_INT, min, FALSE); 00844 00845 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00846 00847 #if OCI_VERSION_COMPILE >= OCI_9_0 00848 00849 OCI_CALL4 00850 ( 00851 res, tmsp->err, tmsp->con, 00852 00853 OCIDateTimeGetTimeZoneOffset((dvoid *) tmsp->env, tmsp->err, 00854 tmsp->handle, (sb1*) hour, (sb1*) min) 00855 ) 00856 00857 #else 00858 00859 OCI_NOT_USED(hour); 00860 OCI_NOT_USED(min); 00861 00862 #endif 00863 00864 OCI_RESULT(res); 00865 00866 return res; 00867 } 00868 00869 /* --------------------------------------------------------------------------------------------- * 00870 * OCI_TimestampIntervalAdd 00871 * --------------------------------------------------------------------------------------------- */ 00872 00873 boolean OCI_API OCI_TimestampIntervalAdd 00874 ( 00875 OCI_Timestamp *tmsp, 00876 OCI_Interval *itv 00877 ) 00878 { 00879 boolean res = TRUE; 00880 OCI_Timestamp *tmp = NULL; 00881 00882 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00883 OCI_CHECK_PTR(OCI_IPC_INTERVAL, itv, FALSE); 00884 00885 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00886 00887 #if OCI_VERSION_COMPILE >= OCI_9_0 00888 00889 /* OCIDateTimeIntervalAdd() fails if timestamps is not OCI_TIMESTAMP_TZ */ 00890 00891 if (tmsp->type != OCI_TIMESTAMP_TZ) 00892 { 00893 tmp = OCI_TimestampCreate(tmsp->con, OCI_TIMESTAMP_TZ); 00894 00895 res = OCI_TimestampConvert(tmp, tmsp); 00896 } 00897 else 00898 { 00899 tmp = tmsp; 00900 } 00901 00902 OCI_CALL4 00903 ( 00904 res, tmsp->err, tmsp->con, 00905 00906 OCIDateTimeIntervalAdd((dvoid *) tmp->env, tmp->err, tmp->handle, 00907 itv->handle, tmp->handle) 00908 ) 00909 00910 /* converting back */ 00911 00912 if ((res == TRUE) && (tmsp->type != OCI_TIMESTAMP_TZ)) 00913 { 00914 res = OCI_TimestampConvert(tmsp, tmp); 00915 00916 OCI_TimestampFree(tmp); 00917 } 00918 00919 #else 00920 00921 OCI_NOT_USED(tmp); 00922 00923 #endif 00924 00925 OCI_RESULT(res); 00926 00927 return res; 00928 } 00929 00930 /* --------------------------------------------------------------------------------------------- * 00931 * OCI_TimestampIntervalSub 00932 * --------------------------------------------------------------------------------------------- */ 00933 00934 boolean OCI_API OCI_TimestampIntervalSub 00935 ( 00936 OCI_Timestamp *tmsp, 00937 OCI_Interval *itv 00938 ) 00939 { 00940 boolean res = TRUE; 00941 OCI_Timestamp *tmp = NULL; 00942 00943 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 00944 OCI_CHECK_PTR(OCI_IPC_INTERVAL, itv, FALSE); 00945 00946 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 00947 00948 #if OCI_VERSION_COMPILE >= OCI_9_0 00949 00950 /* OCIDateTimeIntervalSub() fails if timestamps is not OCI_TIMESTAMP_TZ */ 00951 00952 if (tmsp->type != OCI_TIMESTAMP_TZ) 00953 { 00954 tmp = OCI_TimestampCreate(tmsp->con, OCI_TIMESTAMP_TZ); 00955 00956 res = OCI_TimestampConvert(tmp, tmsp); 00957 } 00958 else 00959 { 00960 tmp = tmsp; 00961 } 00962 00963 OCI_CALL4 00964 ( 00965 res, tmsp->err, tmsp->con, 00966 00967 OCIDateTimeIntervalSub((dvoid *) tmp->env, tmp->err, tmp->handle, 00968 itv->handle, tmp->handle) 00969 ) 00970 00971 /* converting back */ 00972 00973 if ((res == TRUE) && (tmsp->type != OCI_TIMESTAMP_TZ)) 00974 { 00975 res = OCI_TimestampConvert(tmsp, tmp); 00976 00977 OCI_TimestampFree(tmp); 00978 } 00979 00980 #else 00981 00982 OCI_NOT_USED(tmp); 00983 00984 #endif 00985 00986 OCI_RESULT(res); 00987 00988 return res; 00989 } 00990 00991 /* --------------------------------------------------------------------------------------------- * 00992 * OCI_TimestampSubtract 00993 * --------------------------------------------------------------------------------------------- */ 00994 00995 boolean OCI_API OCI_TimestampSubtract 00996 ( 00997 OCI_Timestamp *tmsp, 00998 OCI_Timestamp *tmsp2, 00999 OCI_Interval *itv 01000 ) 01001 { 01002 boolean res = TRUE; 01003 01004 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 01005 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp2, FALSE); 01006 OCI_CHECK_PTR(OCI_IPC_INTERVAL, itv, FALSE); 01007 01008 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 01009 01010 #if OCI_VERSION_COMPILE >= OCI_9_0 01011 01012 OCI_CALL4 01013 ( 01014 res, tmsp->err, tmsp->con, 01015 01016 OCIDateTimeSubtract((dvoid *) tmsp->env, tmsp->err, tmsp->handle, 01017 tmsp2->handle, itv->handle) 01018 ) 01019 01020 #endif 01021 01022 OCI_RESULT(res); 01023 01024 return res; 01025 } 01026 01027 /* --------------------------------------------------------------------------------------------- * 01028 * OCI_TimestampSysTimestamp 01029 * --------------------------------------------------------------------------------------------- */ 01030 01031 boolean OCI_API OCI_TimestampSysTimestamp 01032 ( 01033 OCI_Timestamp *tmsp 01034 ) 01035 { 01036 boolean res = TRUE; 01037 OCI_Timestamp *tmp = NULL; 01038 OCIDateTime *handle = NULL; 01039 01040 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 01041 01042 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 01043 01044 #if OCI_VERSION_COMPILE >= OCI_9_0 01045 01046 /* Filling a timestamp handle of type OCI_TIMESTAMP with 01047 OCIDateTimeSysTimestamp() can lead later to an error ORA-01483 when 01048 binding the given timestamp to some SQL Statement (Oracle BUG). 01049 The only way to avoid that is to pass to OCIDateTimeSysTimestamp() 01050 a timestamp handle of type OCI_TIMESTAMP_TZ and convert it back to 01051 OCI_TIMESTAMP if needed 01052 */ 01053 01054 if (tmsp->type == OCI_TIMESTAMP) 01055 { 01056 tmp = OCI_TimestampCreate(tmsp->con, OCI_TIMESTAMP_TZ); 01057 01058 handle = tmp->handle; 01059 } 01060 else 01061 { 01062 handle = tmsp->handle; 01063 } 01064 01065 OCI_CALL4 01066 ( 01067 res, tmsp->err, tmsp->con, 01068 01069 OCIDateTimeSysTimeStamp((dvoid *) tmsp->env, tmsp->err, handle) 01070 ) 01071 01072 if ((res == TRUE) && (tmsp->type == OCI_TIMESTAMP)) 01073 { 01074 res = OCI_TimestampConvert(tmsp, tmp); 01075 01076 OCI_TimestampFree(tmp); 01077 } 01078 01079 #else 01080 01081 OCI_NOT_USED(tmp); 01082 OCI_NOT_USED(handle); 01083 01084 #endif 01085 01086 OCI_RESULT(res); 01087 01088 return res; 01089 } 01090 01091 /* --------------------------------------------------------------------------------------------- * 01092 * OCI_TimestampToCTime 01093 * --------------------------------------------------------------------------------------------- */ 01094 01095 boolean OCI_API OCI_TimestampToCTime 01096 ( 01097 OCI_Timestamp *tmsp, 01098 struct tm *ptm, 01099 time_t *pt 01100 ) 01101 { 01102 boolean res = TRUE; 01103 time_t time = (time_t) -1; 01104 int msec = 0; 01105 struct tm t; 01106 01107 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 01108 01109 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 01110 01111 res = OCI_TimestampGetDateTime(tmsp, &t.tm_year, &t.tm_mon, &t.tm_mday, 01112 &t.tm_hour, &t.tm_min, &t.tm_sec, 01113 &msec); 01114 01115 if (res == TRUE) 01116 { 01117 t.tm_year -= 1900; 01118 t.tm_mon -= 1; 01119 t.tm_wday = 0; 01120 t.tm_yday = 0; 01121 t.tm_isdst = -1; 01122 01123 time = mktime(&t); 01124 01125 if (ptm != NULL) 01126 { 01127 memcpy(ptm, &t, sizeof(t)); 01128 } 01129 01130 if (pt != NULL) 01131 { 01132 *pt = time; 01133 } 01134 } 01135 01136 OCI_RESULT(res); 01137 01138 return (time != (time_t) -1); 01139 } 01140 01141 /* --------------------------------------------------------------------------------------------- * 01142 * OCI_TimestampFromCTime 01143 * --------------------------------------------------------------------------------------------- */ 01144 01145 boolean OCI_API OCI_TimestampFromCTime 01146 ( 01147 OCI_Timestamp *tmsp, 01148 struct tm *ptm, 01149 time_t t 01150 ) 01151 { 01152 boolean res = TRUE; 01153 01154 OCI_CHECK_PTR(OCI_IPC_TIMESTAMP, tmsp, FALSE); 01155 01156 OCI_CHECK_TIMESTAMP_ENABLED(tmsp->con, FALSE); 01157 01158 if (ptm == NULL && t == (time_t) 0) 01159 { 01160 OCI_ExceptionNullPointer(OCI_IPC_TM); 01161 01162 return FALSE; 01163 } 01164 01165 if (ptm == NULL) 01166 { 01167 ptm = localtime(&t); 01168 } 01169 01170 if (ptm != NULL) 01171 { 01172 res = OCI_TimestampConstruct(tmsp, 01173 ptm->tm_year + 1900, 01174 ptm->tm_mon + 1, 01175 ptm->tm_mday, 01176 ptm->tm_hour, 01177 ptm->tm_min, 01178 ptm->tm_sec, 01179 (int) 0, 01180 (const mtext *) NULL); 01181 } 01182 else 01183 { 01184 OCI_ExceptionNullPointer(OCI_IPC_TM); 01185 01186 res = FALSE; 01187 } 01188 01189 OCI_RESULT(res); 01190 01191 return res; 01192 }