Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Functions

pgtypes_interval.h File Reference

#include <ecpg_config.h>
Include dependency graph for pgtypes_interval.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  interval

Functions

intervalPGTYPESinterval_new (void)
void PGTYPESinterval_free (interval *)
intervalPGTYPESinterval_from_asc (char *, char **)
char * PGTYPESinterval_to_asc (interval *)
int PGTYPESinterval_copy (interval *, interval *)

Function Documentation

int PGTYPESinterval_copy ( interval ,
interval  
)

Definition at line 1156 of file interval.c.

References interval::month, and interval::time.

Referenced by ecpg_get_data(), and main().

{
    intvldest->time = intvlsrc->time;
    intvldest->month = intvlsrc->month;

    return 0;
}

void PGTYPESinterval_free ( interval  ) 

Definition at line 1067 of file interval.c.

References free.

Referenced by main().

{
    free(intvl);
}

interval* PGTYPESinterval_from_asc ( char *  ,
char **   
)

Definition at line 1073 of file interval.c.

References DecodeInterval(), DecodeISO8601Interval(), DTK_DELTA, free, MAXDATELEN, ParseDateTime(), pgtypes_alloc(), tm, tm2interval(), and pg_tm::tm_year.

Referenced by ecpg_get_data(), and main().

{
    interval   *result = NULL;
    fsec_t      fsec;
    struct tm   tt,
               *tm = &tt;
    int         dtype;
    int         nf;
    char       *field[MAXDATEFIELDS];
    int         ftype[MAXDATEFIELDS];
    char        lowstr[MAXDATELEN + MAXDATEFIELDS];
    char       *realptr;
    char      **ptr = (endptr != NULL) ? endptr : &realptr;

    tm->tm_year = 0;
    tm->tm_mon = 0;
    tm->tm_mday = 0;
    tm->tm_hour = 0;
    tm->tm_min = 0;
    tm->tm_sec = 0;
    fsec = 0;

    if (strlen(str) >= sizeof(lowstr))
    {
        errno = PGTYPES_INTVL_BAD_INTERVAL;
        return NULL;
    }

    if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
        (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
         DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
    {
        errno = PGTYPES_INTVL_BAD_INTERVAL;
        return NULL;
    }

    result = (interval *) pgtypes_alloc(sizeof(interval));
    if (!result)
        return NULL;

    if (dtype != DTK_DELTA)
    {
        errno = PGTYPES_INTVL_BAD_INTERVAL;
        free(result);
        return NULL;
    }

    if (tm2interval(tm, fsec, result) != 0)
    {
        errno = PGTYPES_INTVL_BAD_INTERVAL;
        free(result);
        return NULL;
    }

    errno = 0;
    return result;
}

interval* PGTYPESinterval_new ( void   ) 

Definition at line 1057 of file interval.c.

References pgtypes_alloc().

Referenced by main().

{
    interval   *result;

    result = (interval *) pgtypes_alloc(sizeof(interval));
    /* result can be NULL if we run out of memory */
    return result;
}

char* PGTYPESinterval_to_asc ( interval  ) 

Definition at line 1132 of file interval.c.

References buf, EncodeInterval(), interval2tm(), IntervalStyle, MAXDATELEN, pgtypes_strdup(), and tm.

Referenced by ecpg_store_input(), intoasc(), and main().

{
    struct tm   tt,
               *tm = &tt;
    fsec_t      fsec;
    char        buf[MAXDATELEN + 1];
    int         IntervalStyle = INTSTYLE_POSTGRES_VERBOSE;

    if (interval2tm(*span, tm, &fsec) != 0)
    {
        errno = PGTYPES_INTVL_BAD_INTERVAL;
        return NULL;
    }

    if (EncodeInterval(tm, fsec, IntervalStyle, buf) != 0)
    {
        errno = PGTYPES_INTVL_BAD_INTERVAL;
        return NULL;
    }

    return pgtypes_strdup(buf);
}