OCILIB (C Driver for Oracle) 3.9.2
|
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-2011 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: date.c, v 3.9.2 2011-07-13 00:00 Vincent Rogier $ 00033 * --------------------------------------------------------------------------------------------- */ 00034 00035 #include "ocilib_internal.h" 00036 00037 /* ********************************************************************************************* * 00038 * PRIVATE FUNCTIONS 00039 * ********************************************************************************************* */ 00040 00041 /* --------------------------------------------------------------------------------------------- * 00042 * OCI_DateInit 00043 * --------------------------------------------------------------------------------------------- */ 00044 00045 OCI_Date * OCI_DateInit 00046 ( 00047 OCI_Connection *con, 00048 OCI_Date **pdate, 00049 OCIDate *buffer, 00050 boolean allocate, 00051 boolean ansi 00052 ) 00053 { 00054 OCI_Date *date = NULL; 00055 boolean res = TRUE; 00056 00057 OCI_CHECK(pdate == NULL, NULL); 00058 00059 if (*pdate == NULL) 00060 { 00061 *pdate = (OCI_Date *) OCI_MemAlloc(OCI_IPC_DATE, sizeof(*date), (size_t) 1, TRUE); 00062 } 00063 00064 if (*pdate != NULL) 00065 { 00066 date = *pdate; 00067 00068 date->con = con; 00069 00070 /* get the right error handle */ 00071 00072 if (con != NULL) 00073 { 00074 date->err = con->err; 00075 date->env = con->env; 00076 } 00077 else 00078 { 00079 date->err = OCILib.err; 00080 date->env = OCILib.env; 00081 } 00082 00083 /* allocate buffer if needed */ 00084 00085 if ((date->handle == NULL) && ((allocate == TRUE) || (ansi == TRUE))) 00086 { 00087 date->allocated = TRUE; 00088 00089 if (allocate == TRUE) 00090 { 00091 date->hstate = OCI_OBJECT_ALLOCATED; 00092 } 00093 00094 date->handle = (OCIDate *) OCI_MemAlloc(OCI_IPC_OCIDATE, sizeof(*date->handle), 00095 (size_t) 1, TRUE); 00096 00097 res = (date->handle != NULL); 00098 } 00099 else 00100 { 00101 if (date->hstate != OCI_OBJECT_ALLOCATED_ARRAY) 00102 { 00103 date->hstate = OCI_OBJECT_FETCHED_CLEAN; 00104 } 00105 00106 date->handle = buffer; 00107 } 00108 00109 /* if the input buffer is an SQLT_DAT buffer, we need to convert it */ 00110 00111 if ((ansi == TRUE) && (buffer != NULL)) 00112 { 00113 unsigned char *d = (unsigned char *) buffer; 00114 00115 date->handle->OCIDateYYYY = (sb2) (((d[0] - 100) * 100) + (d[1] - 100)); 00116 date->handle->OCIDateMM = (ub1) d[2]; 00117 date->handle->OCIDateDD = (ub1) d[3]; 00118 00119 date->handle->OCIDateTime.OCITimeHH = (ub1) (d[4] - 1); 00120 date->handle->OCIDateTime.OCITimeMI = (ub1) (d[5] - 1); 00121 date->handle->OCIDateTime.OCITimeSS = (ub1) (d[6] - 1); 00122 } 00123 } 00124 else 00125 { 00126 res = FALSE; 00127 } 00128 00129 /* check for failure */ 00130 00131 if (res == FALSE) 00132 { 00133 OCI_DateFree(date); 00134 date = NULL; 00135 } 00136 00137 return date; 00138 } 00139 00140 /* ********************************************************************************************* * 00141 * PUBLIC FUNCTIONS 00142 * ********************************************************************************************* */ 00143 00144 /* --------------------------------------------------------------------------------------------- * 00145 * OCI_DateCreate 00146 * --------------------------------------------------------------------------------------------- */ 00147 00148 OCI_Date * OCI_API OCI_DateCreate 00149 ( 00150 OCI_Connection *con 00151 ) 00152 { 00153 OCI_Date *date = NULL; 00154 00155 OCI_CHECK_INITIALIZED(NULL); 00156 00157 date = OCI_DateInit(con, &date, NULL, TRUE, FALSE); 00158 00159 OCI_RESULT(date != NULL); 00160 00161 return date; 00162 } 00163 00164 /* --------------------------------------------------------------------------------------------- * 00165 * OCI_DateFree 00166 * --------------------------------------------------------------------------------------------- */ 00167 00168 boolean OCI_API OCI_DateFree 00169 ( 00170 OCI_Date *date 00171 ) 00172 { 00173 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00174 00175 OCI_CHECK_OBJECT_FETCHED(date, FALSE); 00176 00177 if (date->allocated == TRUE) 00178 { 00179 OCI_FREE(date->handle); 00180 } 00181 00182 if (date->hstate != OCI_OBJECT_ALLOCATED_ARRAY) 00183 { 00184 OCI_FREE(date); 00185 } 00186 00187 OCI_RESULT(TRUE); 00188 00189 return TRUE; 00190 } 00191 00192 /* --------------------------------------------------------------------------------------------- * 00193 * OCI_DateArrayCreate 00194 * --------------------------------------------------------------------------------------------- */ 00195 00196 OCI_Date ** OCI_API OCI_DateArrayCreate 00197 ( 00198 OCI_Connection *con, 00199 unsigned int nbelem 00200 ) 00201 { 00202 OCI_Array *arr = NULL; 00203 OCI_Date **dates = NULL; 00204 00205 arr = OCI_ArrayCreate(con, nbelem, OCI_CDT_DATETIME, 0, sizeof(OCIDate), sizeof(OCI_Date), 0, NULL); 00206 00207 if (arr != NULL) 00208 { 00209 dates = (OCI_Date **) arr->tab_obj; 00210 } 00211 00212 return dates; 00213 } 00214 00215 /* --------------------------------------------------------------------------------------------- * 00216 * OCI_DateArrayFree 00217 * --------------------------------------------------------------------------------------------- */ 00218 00219 boolean OCI_API OCI_DateArrayFree 00220 ( 00221 OCI_Date **dates 00222 ) 00223 { 00224 return OCI_ArrayFreeFromHandles((void **) dates); 00225 } 00226 00227 /* --------------------------------------------------------------------------------------------- * 00228 * OCI_DateAddDays 00229 * --------------------------------------------------------------------------------------------- */ 00230 00231 boolean OCI_API OCI_DateAddDays 00232 ( 00233 OCI_Date *date, 00234 int nb 00235 ) 00236 { 00237 boolean res = TRUE; 00238 00239 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00240 00241 OCI_CALL4 00242 ( 00243 res, date->err, date->con, 00244 00245 OCIDateAddDays(date->err, date->handle, (sb4) nb, date->handle) 00246 ) 00247 00248 OCI_RESULT(res); 00249 00250 return res; 00251 } 00252 00253 /* --------------------------------------------------------------------------------------------- * 00254 * OCI_DateAddMonths 00255 * --------------------------------------------------------------------------------------------- */ 00256 00257 boolean OCI_API OCI_DateAddMonths 00258 ( 00259 OCI_Date *date, 00260 int nb 00261 ) 00262 { 00263 boolean res = TRUE; 00264 00265 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00266 00267 OCI_CALL4 00268 ( 00269 res, date->err, date->con, 00270 00271 OCIDateAddMonths(date->err, date->handle, (sb4) nb, date->handle) 00272 ) 00273 00274 OCI_RESULT(res); 00275 00276 return res; 00277 } 00278 00279 /* --------------------------------------------------------------------------------------------- * 00280 * OCI_DateAssign 00281 * --------------------------------------------------------------------------------------------- */ 00282 00283 boolean OCI_API OCI_DateAssign 00284 ( 00285 OCI_Date *date, 00286 OCI_Date *date_src 00287 ) 00288 { 00289 boolean res = TRUE; 00290 00291 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00292 OCI_CHECK_PTR(OCI_IPC_DATE, date_src, FALSE); 00293 00294 OCI_CALL4 00295 ( 00296 res, date->err, date->con, 00297 00298 OCIDateAssign(date->err, date_src->handle, date->handle) 00299 ) 00300 00301 OCI_RESULT(res); 00302 00303 return res; 00304 } 00305 00306 /* --------------------------------------------------------------------------------------------- * 00307 * OCI_DateCheck 00308 * --------------------------------------------------------------------------------------------- */ 00309 00310 int OCI_API OCI_DateCheck 00311 ( 00312 OCI_Date *date 00313 ) 00314 { 00315 boolean res = TRUE; 00316 uword valid = 0; 00317 00318 OCI_CHECK_PTR(OCI_IPC_DATE, date, OCI_ERROR); 00319 00320 OCI_CALL4 00321 ( 00322 res, date->err, date->con, 00323 00324 OCIDateCheck(date->err, date->handle, &valid) 00325 ) 00326 00327 OCI_RESULT(res); 00328 00329 return (int) valid; 00330 } 00331 00332 /* --------------------------------------------------------------------------------------------- * 00333 * OCI_DateCompare 00334 * --------------------------------------------------------------------------------------------- */ 00335 00336 int OCI_API OCI_DateCompare 00337 ( 00338 OCI_Date *date, 00339 OCI_Date *date2 00340 ) 00341 { 00342 boolean res = TRUE; 00343 sword value = -1; 00344 00345 OCI_CHECK_PTR(OCI_IPC_DATE, date, -1); 00346 00347 OCI_CALL4 00348 ( 00349 res, date->err, date->con, 00350 00351 OCIDateCompare(date->err, date->handle, date2->handle, &value) 00352 ) 00353 00354 OCI_RESULT(res); 00355 00356 return (int) value; 00357 } 00358 00359 /* --------------------------------------------------------------------------------------------- * 00360 * OCI_DateDaysBetween 00361 * --------------------------------------------------------------------------------------------- */ 00362 00363 int OCI_API OCI_DateDaysBetween 00364 ( 00365 OCI_Date *date, 00366 OCI_Date *date2 00367 ) 00368 { 00369 boolean res = TRUE; 00370 sb4 nb = 0; 00371 00372 OCI_CHECK_PTR(OCI_IPC_DATE, date, OCI_ERROR); 00373 OCI_CHECK_PTR(OCI_IPC_DATE, date2, OCI_ERROR); 00374 00375 OCI_CALL4 00376 ( 00377 res, date->err, date->con, 00378 00379 OCIDateDaysBetween(date->err, date->handle, date2->handle, &nb) 00380 ) 00381 00382 OCI_RESULT(res); 00383 00384 return (sb4) nb; 00385 } 00386 00387 /* --------------------------------------------------------------------------------------------- * 00388 * OCI_DateFromText 00389 * --------------------------------------------------------------------------------------------- */ 00390 00391 boolean OCI_API OCI_DateFromText 00392 ( 00393 OCI_Date *date, 00394 const mtext *str, 00395 const mtext *fmt 00396 ) 00397 { 00398 void *ostr1 = NULL; 00399 void *ostr2 = NULL; 00400 int osize1 = -1; 00401 int osize2 = -1; 00402 boolean res = TRUE; 00403 00404 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00405 OCI_CHECK_PTR(OCI_IPC_STRING, str, FALSE); 00406 OCI_CHECK_PTR(OCI_IPC_STRING, fmt, FALSE); 00407 00408 ostr1 = OCI_GetInputMetaString(str, &osize1); 00409 ostr2 = OCI_GetInputMetaString(fmt, &osize2); 00410 00411 OCI_CALL4 00412 ( 00413 res, date->err, date->con, 00414 00415 OCIDateFromText(date->err, 00416 (oratext *) ostr1, (ub4) osize1, 00417 (oratext *) ostr2, (ub1) osize2, 00418 (oratext *) NULL, (ub4) 0, date->handle) 00419 ) 00420 00421 OCI_ReleaseMetaString(ostr1); 00422 OCI_ReleaseMetaString(ostr2); 00423 00424 OCI_RESULT(res); 00425 00426 return res; 00427 } 00428 00429 /* --------------------------------------------------------------------------------------------- * 00430 * OCI_DateGetDate 00431 * --------------------------------------------------------------------------------------------- */ 00432 00433 boolean OCI_API OCI_DateGetDate 00434 ( 00435 OCI_Date *date, 00436 int *year, 00437 int *month, 00438 int *day 00439 ) 00440 { 00441 sb2 yr = 0; 00442 ub1 mt = 0; 00443 ub1 dy = 0; 00444 00445 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00446 OCI_CHECK_PTR(OCI_IPC_INT, year, FALSE); 00447 OCI_CHECK_PTR(OCI_IPC_INT, month, FALSE); 00448 OCI_CHECK_PTR(OCI_IPC_INT, day, FALSE); 00449 00450 *year = 0; 00451 *month = 0; 00452 *day = 0; 00453 00454 OCIDateGetDate(date->handle, &yr, &mt, &dy); 00455 00456 *year = (int) yr; 00457 *month = (int) mt; 00458 *day = (int) dy; 00459 00460 OCI_RESULT(TRUE); 00461 00462 return TRUE; 00463 } 00464 00465 /* --------------------------------------------------------------------------------------------- * 00466 * OCI_DateGetTime 00467 * --------------------------------------------------------------------------------------------- */ 00468 00469 boolean OCI_API OCI_DateGetTime 00470 ( 00471 OCI_Date *date, 00472 int *hour, 00473 int *min, 00474 int *sec 00475 ) 00476 { 00477 ub1 hr = 0; 00478 ub1 mn = 0; 00479 ub1 sc = 0; 00480 00481 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00482 OCI_CHECK_PTR(OCI_IPC_INT, hour, FALSE); 00483 OCI_CHECK_PTR(OCI_IPC_INT, min, FALSE); 00484 OCI_CHECK_PTR(OCI_IPC_INT, sec, FALSE); 00485 00486 *hour = 0; 00487 *min = 0; 00488 *sec = 0; 00489 00490 OCIDateGetTime(date->handle, &hr, &mn, &sc); 00491 00492 *hour = (int) hr; 00493 *min = (int) mn; 00494 *sec = (int) sc; 00495 00496 OCI_RESULT(TRUE); 00497 00498 return TRUE; 00499 } 00500 00501 /* --------------------------------------------------------------------------------------------- * 00502 * OCI_DateGetDateTime 00503 * --------------------------------------------------------------------------------------------- */ 00504 00505 boolean OCI_API OCI_DateGetDateTime 00506 ( 00507 OCI_Date *date, 00508 int *year, 00509 int *month, 00510 int *day, 00511 int *hour, 00512 int *min, 00513 int *sec 00514 ) 00515 { 00516 return (OCI_DateGetDate(date, year, month, day) && OCI_DateGetTime(date, hour, min, sec)); 00517 } 00518 00519 /* --------------------------------------------------------------------------------------------- * 00520 * OCI_DateLastDay 00521 * --------------------------------------------------------------------------------------------- */ 00522 00523 boolean OCI_API OCI_DateLastDay 00524 ( 00525 OCI_Date *date 00526 ) 00527 { 00528 boolean res = TRUE; 00529 00530 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00531 00532 OCI_CALL4 00533 ( 00534 res, date->err, date->con, 00535 00536 OCIDateLastDay(date->err, date->handle, date->handle) 00537 ) 00538 00539 OCI_RESULT(res); 00540 00541 return res; 00542 } 00543 00544 /* --------------------------------------------------------------------------------------------- * 00545 * OCI_DateNextDay 00546 * --------------------------------------------------------------------------------------------- */ 00547 00548 boolean OCI_API OCI_DateNextDay 00549 ( 00550 OCI_Date *date, 00551 const mtext *day 00552 ) 00553 { 00554 boolean res = TRUE; 00555 void *ostr = NULL; 00556 int osize = -1; 00557 00558 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00559 OCI_CHECK_PTR(OCI_IPC_STRING, day, FALSE); 00560 00561 ostr = OCI_GetInputMetaString(day, &osize); 00562 00563 OCI_CALL4 00564 ( 00565 res, date->err, date->con, 00566 00567 OCIDateNextDay(date->err, date->handle, (oratext *) ostr, (ub4) osize, date->handle) 00568 ) 00569 00570 OCI_ReleaseMetaString(ostr); 00571 00572 OCI_RESULT(res); 00573 00574 return res; 00575 } 00576 00577 /* --------------------------------------------------------------------------------------------- * 00578 * OCI_DateSetDate 00579 * --------------------------------------------------------------------------------------------- */ 00580 00581 boolean OCI_API OCI_DateSetDate 00582 ( 00583 OCI_Date *date, 00584 int year, 00585 int month, 00586 int day 00587 ) 00588 { 00589 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00590 00591 OCIDateSetDate(date->handle, (sb2) year, (ub1) month, (ub1) day); 00592 00593 OCI_RESULT(TRUE); 00594 00595 return TRUE; 00596 } 00597 00598 /* --------------------------------------------------------------------------------------------- * 00599 * OCI_DateSetTime 00600 * --------------------------------------------------------------------------------------------- */ 00601 00602 boolean OCI_API OCI_DateSetTime 00603 ( 00604 OCI_Date *date, 00605 int hour, 00606 int min, 00607 int sec 00608 ) 00609 { 00610 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00611 00612 OCIDateSetTime(date->handle, (ub1) hour, (ub1) min, (ub1) sec); 00613 00614 OCI_RESULT(TRUE); 00615 00616 return TRUE; 00617 } 00618 00619 /* --------------------------------------------------------------------------------------------- * 00620 * OCI_DateSetDateTime 00621 * --------------------------------------------------------------------------------------------- */ 00622 00623 boolean OCI_API OCI_DateSetDateTime 00624 ( 00625 OCI_Date *date, 00626 int year, 00627 int month, 00628 int day, 00629 int hour, 00630 int min, 00631 int sec 00632 ) 00633 { 00634 return (OCI_DateSetDate(date, year, month, day) && OCI_DateSetTime(date, hour, min, sec)); 00635 } 00636 00637 /* --------------------------------------------------------------------------------------------- * 00638 * OCI_DateSysDate 00639 * --------------------------------------------------------------------------------------------- */ 00640 00641 boolean OCI_API OCI_DateSysDate 00642 ( 00643 OCI_Date *date 00644 ) 00645 { 00646 boolean res = TRUE; 00647 00648 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00649 00650 OCI_CALL4 00651 ( 00652 res, date->err, date->con, 00653 00654 OCIDateSysDate(date->err, date->handle) 00655 ) 00656 00657 OCI_RESULT(res); 00658 00659 return res; 00660 } 00661 00662 /* --------------------------------------------------------------------------------------------- * 00663 * OCI_DateToText 00664 * --------------------------------------------------------------------------------------------- */ 00665 00666 boolean OCI_API OCI_DateToText 00667 ( 00668 OCI_Date *date, 00669 const mtext *fmt, 00670 int size, 00671 mtext *str 00672 ) 00673 { 00674 void *ostr1 = NULL; 00675 void *ostr2 = NULL; 00676 int osize1 = size * (int) sizeof(mtext); 00677 int osize2 = -1; 00678 boolean res = TRUE; 00679 00680 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00681 OCI_CHECK_PTR(OCI_IPC_STRING, str, FALSE); 00682 OCI_CHECK_PTR(OCI_IPC_STRING, fmt, FALSE); 00683 00684 /* init output buffer in case of OCI failure */ 00685 00686 str[0] = 0; 00687 00688 ostr1 = OCI_GetInputMetaString(str, &osize1); 00689 ostr2 = OCI_GetInputMetaString(fmt, &osize2); 00690 00691 OCI_CALL4 00692 ( 00693 res, date->err, date->con, 00694 00695 OCIDateToText(date->err, date->handle, (oratext *) ostr2, 00696 (ub1) osize2, (oratext *) NULL, (ub4) 0, 00697 (ub4*) &osize1, (oratext *) ostr1) 00698 ) 00699 00700 OCI_GetOutputMetaString(ostr1, str, &osize1); 00701 00702 OCI_ReleaseMetaString(ostr1); 00703 OCI_ReleaseMetaString(ostr2); 00704 00705 /* set null string terminator*/ 00706 00707 osize1 /= (int) sizeof(mtext); 00708 00709 str[osize1] = 0; 00710 00711 OCI_RESULT(res); 00712 00713 return res; 00714 } 00715 00716 /* --------------------------------------------------------------------------------------------- * 00717 * OCI_DateZoneToZone 00718 * --------------------------------------------------------------------------------------------- */ 00719 00720 boolean OCI_API OCI_DateZoneToZone 00721 ( 00722 OCI_Date *date, 00723 const mtext *zone1, 00724 const mtext *zone2 00725 ) 00726 { 00727 void *ostr1 = NULL; 00728 void *ostr2 = NULL; 00729 int osize1 = -1; 00730 int osize2 = -1; 00731 boolean res = TRUE; 00732 00733 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00734 OCI_CHECK_PTR(OCI_IPC_STRING, zone1, FALSE); 00735 OCI_CHECK_PTR(OCI_IPC_STRING, zone2, FALSE); 00736 00737 ostr1 = OCI_GetInputMetaString(zone1, &osize1); 00738 ostr2 = OCI_GetInputMetaString(zone2, &osize2); 00739 00740 OCI_CALL4 00741 ( 00742 res, date->err, date->con, 00743 00744 OCIDateZoneToZone(date->err, date->handle, 00745 (oratext *) ostr1, (ub4) osize1, 00746 (oratext *) ostr2, (ub4) osize2, 00747 date->handle) 00748 ) 00749 00750 OCI_ReleaseMetaString(ostr1); 00751 OCI_ReleaseMetaString(ostr2); 00752 00753 OCI_RESULT(res); 00754 00755 return res; 00756 } 00757 00758 /* --------------------------------------------------------------------------------------------- * 00759 * OCI_DateToCTime 00760 * --------------------------------------------------------------------------------------------- */ 00761 00762 boolean OCI_API OCI_DateToCTime 00763 ( 00764 OCI_Date *date, 00765 struct tm *ptm, 00766 time_t *pt 00767 ) 00768 { 00769 time_t time = (time_t) -1; 00770 struct tm t; 00771 00772 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00773 00774 t.tm_year = date->handle->OCIDateYYYY - 1900; 00775 t.tm_mon = date->handle->OCIDateMM - 1; 00776 t.tm_mday = date->handle->OCIDateDD; 00777 00778 t.tm_hour = date->handle->OCIDateTime.OCITimeHH; 00779 t.tm_min = date->handle->OCIDateTime.OCITimeMI; 00780 t.tm_sec = date->handle->OCIDateTime.OCITimeSS; 00781 00782 t.tm_wday = 0; 00783 t.tm_yday = 0; 00784 t.tm_isdst = -1; 00785 00786 time = mktime(&t); 00787 00788 if (ptm != NULL) 00789 { 00790 memcpy(ptm, &t, sizeof(t)); 00791 } 00792 00793 if (pt != NULL) 00794 { 00795 *pt = time; 00796 } 00797 00798 OCI_RESULT(TRUE); 00799 00800 return (time != (time_t) -1); 00801 } 00802 00803 /* --------------------------------------------------------------------------------------------- * 00804 * OCI_DateFromCTime 00805 * --------------------------------------------------------------------------------------------- */ 00806 00807 boolean OCI_API OCI_DateFromCTime 00808 ( 00809 OCI_Date *date, 00810 struct tm *ptm, 00811 time_t t 00812 ) 00813 { 00814 boolean res = TRUE; 00815 00816 OCI_CHECK_PTR(OCI_IPC_DATE, date, FALSE); 00817 00818 if ((ptm == NULL) && (t == (time_t) 0)) 00819 { 00820 OCI_ExceptionNullPointer(OCI_IPC_TM); 00821 } 00822 00823 if (ptm == NULL) 00824 { 00825 ptm = localtime(&t); 00826 } 00827 00828 if (ptm != NULL) 00829 { 00830 date->handle->OCIDateYYYY = (sb2) ptm->tm_year + 1900; 00831 date->handle->OCIDateMM = (ub1) ptm->tm_mon + 1; 00832 date->handle->OCIDateDD = (ub1) ptm->tm_mday; 00833 00834 date->handle->OCIDateTime.OCITimeHH = (ub1) ptm->tm_hour; 00835 date->handle->OCIDateTime.OCITimeMI = (ub1) ptm->tm_min; 00836 date->handle->OCIDateTime.OCITimeSS = (ub1) ptm->tm_sec; 00837 } 00838 else 00839 { 00840 OCI_ExceptionNullPointer(OCI_IPC_TM); 00841 00842 res = FALSE; 00843 } 00844 00845 OCI_RESULT(res); 00846 00847 return res; 00848 }