Пример #1
0
int main(void)
{
    OCI_Date *d1, *d2;

    char str[SIZE_STR+1];
   
    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    d1 = OCI_DateCreate(NULL);
    d2 = OCI_DateCreate(NULL);

    strcpy(str, "13041978 20:20:12");

    OCI_DateFromText(d1, str, "DDMMYYYY HH24:MI:SS");
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nDate is %s\n", str);

    OCI_DateSysDate(d1);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nSysdate is %s\n", str);

    OCI_DateAddDays(d1, 5);
    OCI_DateAddMonths(d1, 2);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nDate + 5 days and 2 months is %s\n", str);

    OCI_DateAssign(d2, d1);
    OCI_DateLastDay(d1);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nLast day of the month : %s\n", str);

    printf("\nNumber of days until the end of the months : %i\n",
            OCI_DateDaysBetween(d1, d2));

    OCI_DateFree(d1);
    OCI_DateFree(d2);

    OCI_Cleanup();
 
    return EXIT_SUCCESS;
}
Пример #2
0
OCI_Date * OCI_DateInit2(OCI_Library *pOCILib, OCI_Connection *con, OCI_Date **pdate, OCIDate *buffer,
                        boolean allocate, boolean ansi)
{
    OCI_Date *date = NULL;
    boolean res    = TRUE;

    OCI_CHECK(pdate == NULL, NULL);

    if (*pdate == NULL)
        *pdate = (OCI_Date *) OCI_MemAlloc2(pOCILib, OCI_IPC_DATE, sizeof(*date),
                                           (size_t) 1, TRUE);

    if (*pdate != NULL)
    {
        date = *pdate;

        date->con = con;

        /* get the right error handle */

        if (con != NULL)
            date->err = con->err;
        else
            date->err = pOCILib->err;

        /* allocate buffer if needed */

        if ((date->handle == NULL) && ((allocate == TRUE) || (ansi == TRUE)))
        {
            date->allocated = TRUE;

            if (allocate == TRUE)
                date->hstate = OCI_OBJECT_ALLOCATED;

            date->handle = (OCIDate *) OCI_MemAlloc2(pOCILib, OCI_IPC_OCIDATE,
                                                    sizeof(*date->handle),
                                                    (size_t) 1, TRUE);

            res = (date->handle != NULL);
        }
        else
        {
            if (date->hstate != OCI_OBJECT_ALLOCATED_ARRAY)
            {
                date->hstate = OCI_OBJECT_FETCHED_CLEAN;
            }

            date->handle = buffer;
        }

        /* if the input buffer is an SQLT_DAT buffer, we need to convert it */

        if ((ansi == TRUE) && (buffer != NULL))
        {
            unsigned char *d = (unsigned char *) buffer;

            date->handle->OCIDateYYYY = (sb2) (((d[0] - 100) * 100) + (d[1] - 100));
            date->handle->OCIDateMM   = (ub1) d[2];
            date->handle->OCIDateDD   = (ub1) d[3];

            date->handle->OCIDateTime.OCITimeHH = (ub1) (d[4] - 1);
            date->handle->OCIDateTime.OCITimeMI = (ub1) (d[5] - 1);
            date->handle->OCIDateTime.OCITimeSS = (ub1) (d[6] - 1);
        }
    }
    else
        res = FALSE;

   /* check for failure */

    if (res == FALSE)
    {
       OCI_DateFree(pOCILib, date);
        date = NULL;
    }

    return date;
}
Пример #3
0
OCI_Date * OCI_DateInit
(
    OCI_Connection *con,
    OCI_Date      **pdate,
    OCIDate        *buffer,
    boolean         allocate,
    boolean         ansi
)
{
    OCI_Date *date = NULL;
    boolean   res  = FALSE;

    OCI_CHECK(NULL == pdate, NULL);

    if (!*pdate)
    {
        *pdate = (OCI_Date *) OCI_MemAlloc(OCI_IPC_DATE, sizeof(*date), (size_t) 1, TRUE);
    }

    if (*pdate)
    {
        res = TRUE;

        date = *pdate;

        date->con = con;

        /* get the right error handle */

        if (con)
        {
            date->err = con->err;
            date->env = con->env;
        }
        else
        {
            date->err = OCILib.err;
            date->env = OCILib.env;
        }

        /* allocate buffer if needed */

        if (!date->handle && (allocate || ansi))
        {
            date->allocated = TRUE;

            if (allocate)
            {
                date->hstate = OCI_OBJECT_ALLOCATED;
            }

            date->handle = (OCIDate *) OCI_MemAlloc(OCI_IPC_OCIDATE, sizeof(*date->handle),
                                                    (size_t) 1, TRUE);

            res = (NULL != date->handle);
        }
        else
        {
            if (OCI_OBJECT_ALLOCATED_ARRAY != date->hstate)
            {
                date->hstate = OCI_OBJECT_FETCHED_CLEAN;
            }

            date->handle = buffer;
        }

        /* if the input buffer is an SQLT_DAT buffer, we need to convert it */

        if (ansi && buffer)
        {
            unsigned char *d = (unsigned char *) buffer;

            date->handle->OCIDateYYYY = (sb2) (((d[0] - 100) * 100) + (d[1] - 100));
            date->handle->OCIDateMM   = (ub1) d[2];
            date->handle->OCIDateDD   = (ub1) d[3];

            date->handle->OCIDateTime.OCITimeHH = (ub1) (d[4] - 1);
            date->handle->OCIDateTime.OCITimeMI = (ub1) (d[5] - 1);
            date->handle->OCIDateTime.OCITimeSS = (ub1) (d[6] - 1);
        }
    }

    /* check for failure */

    if (!res && date)
    {
        OCI_DateFree(date);
        *pdate = date = NULL;
    }

    return date;
}
Пример #4
0
boolean OCI_API OCI_ElemFree2(OCI_Library *pOCILib, OCI_Elem *elem, ExceptionSink* xsink)
{
   assert(elem);
   //OCI_CHECK_PTRQ(pOCILib, OCI_IPC_ELEMENT, elem, FALSE, xsink);

    OCI_CHECK_OBJECT_FETCHED(elem, FALSE);

    /* if the element has sub-objects that have been fetched, we need to free
       these objects */

    if (elem->obj != NULL)
    {
        OCI_Datatype * data = (OCI_Datatype *) elem->obj;

        if (data->hstate == OCI_OBJECT_FETCHED_CLEAN)
            data->hstate = OCI_OBJECT_FETCHED_DIRTY;

        switch (elem->typinf->cols[0].type)
        {
            case OCI_CDT_DATETIME:

                OCI_DateFree(pOCILib, (OCI_Date *) elem->obj);
                break;

            case OCI_CDT_LOB:

	       OCI_LobFree(pOCILib, (OCI_Lob *) elem->obj, xsink);
                break;

            case OCI_CDT_FILE:
	       assert(false);
	       //OCI_FileFree(pOCILib, (OCI_File *) elem->obj);
                break;

            case OCI_CDT_OBJECT:

	       OCI_ObjectFree2(pOCILib, (OCI_Object *) elem->obj, xsink);
                break;

            case OCI_CDT_COLLECTION:

	       OCI_CollFree2(pOCILib, (OCI_Coll *) elem->obj, xsink);
	       break;

            case OCI_CDT_TIMESTAMP:

	       OCI_TimestampFree2(pOCILib, (OCI_Timestamp *) elem->obj);
                break;

            case OCI_CDT_INTERVAL:

                OCI_IntervalFree2(pOCILib, (OCI_Interval *) elem->obj);
                break;
            
            case OCI_CDT_REF:
	       assert(false);
	       //OCI_RefFree(pOCILib, (OCI_Ref *) elem->obj);
                break;       
        }
    }
    
    if ((elem->hstate == OCI_OBJECT_ALLOCATED) && 
        (elem->typinf->cols[0].type == OCI_CDT_NUMERIC))
    {
        OCI_FREE(elem->handle);
    }

    OCI_FREE(elem->buf);
    OCI_FREE(elem);

    OCI_RESULT(pOCILib, TRUE);

    return TRUE;
}