• Main Page
  • Modules
  • Data Structures
  • Files
  • File List

D:/Perso/dev/ocilib/ocilib/src/date.c

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

Generated on Mon Dec 13 2010 22:32:01 for OCILIB (C Driver for Oracle) by  doxygen 1.7.2