PostgreSQL Source Code git master
pgtypes_interval.h File Reference
#include <stdint.h>
#include <ecpg_config.h>
#include <pgtypes.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
 

Macros

#define HAVE_INT64_TIMESTAMP
 

Typedefs

typedef int64_t int64
 

Functions

intervalPGTYPESinterval_new (void)
 
void PGTYPESinterval_free (interval *intvl)
 
intervalPGTYPESinterval_from_asc (char *str, char **endptr)
 
char * PGTYPESinterval_to_asc (interval *span)
 
int PGTYPESinterval_copy (interval *intvlsrc, interval *intvldest)
 

Macro Definition Documentation

◆ HAVE_INT64_TIMESTAMP

#define HAVE_INT64_TIMESTAMP

Definition at line 15 of file pgtypes_interval.h.

Typedef Documentation

◆ int64

typedef int64_t int64

Definition at line 13 of file pgtypes_interval.h.

Function Documentation

◆ PGTYPESinterval_copy()

int PGTYPESinterval_copy ( interval intvlsrc,
interval intvldest 
)

Definition at line 1082 of file interval.c.

1083{
1084 intvldest->time = intvlsrc->time;
1085 intvldest->month = intvlsrc->month;
1086
1087 return 0;
1088}

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

Referenced by ecpg_get_data(), and main().

◆ PGTYPESinterval_free()

void PGTYPESinterval_free ( interval intvl)

Definition at line 997 of file interval.c.

998{
999 free(intvl);
1000}
#define free(a)
Definition: header.h:65

References free.

Referenced by main().

◆ PGTYPESinterval_from_asc()

interval * PGTYPESinterval_from_asc ( char *  str,
char **  endptr 
)

Definition at line 1003 of file interval.c.

1004{
1005 interval *result = NULL;
1006 fsec_t fsec;
1007 struct tm tt,
1008 *tm = &tt;
1009 int dtype;
1010 int nf;
1011 char *field[MAXDATEFIELDS];
1012 int ftype[MAXDATEFIELDS];
1013 char lowstr[MAXDATELEN + MAXDATEFIELDS];
1014 char *realptr;
1015 char **ptr = (endptr != NULL) ? endptr : &realptr;
1016
1017 tm->tm_year = 0;
1018 tm->tm_mon = 0;
1019 tm->tm_mday = 0;
1020 tm->tm_hour = 0;
1021 tm->tm_min = 0;
1022 tm->tm_sec = 0;
1023 fsec = 0;
1024
1025 if (strlen(str) > MAXDATELEN)
1026 {
1028 return NULL;
1029 }
1030
1031 if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
1032 (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
1033 DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
1034 {
1036 return NULL;
1037 }
1038
1039 result = (interval *) pgtypes_alloc(sizeof(interval));
1040 if (!result)
1041 return NULL;
1042
1043 if (dtype != DTK_DELTA)
1044 {
1046 free(result);
1047 return NULL;
1048 }
1049
1050 if (tm2interval(tm, fsec, result) != 0)
1051 {
1053 free(result);
1054 return NULL;
1055 }
1056
1057 errno = 0;
1058 return result;
1059}
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:764
int32 fsec_t
Definition: timestamp.h:41
const char * str
#define MAXDATEFIELDS
Definition: datetime.h:202
#define DTK_DELTA
Definition: datetime.h:159
#define MAXDATELEN
Definition: datetime.h:200
char * pgtypes_alloc(long size)
Definition: common.c:10
static int DecodeISO8601Interval(char *str, int *dtype, struct tm *tm, fsec_t *fsec)
Definition: interval.c:112
static int tm2interval(struct tm *tm, fsec_t fsec, interval *span)
Definition: interval.c:972
int DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec)
Definition: interval.c:326
static struct pg_tm tm
Definition: localtime.c:104
#define PGTYPES_INTVL_BAD_INTERVAL
Definition: pgtypes_error.h:18
int tm_hour
Definition: pgtime.h:38
int tm_mday
Definition: pgtime.h:39
int tm_mon
Definition: pgtime.h:40
int tm_min
Definition: pgtime.h:37
int tm_sec
Definition: pgtime.h:36
int tm_year
Definition: pgtime.h:41

References DecodeInterval(), DecodeISO8601Interval(), DTK_DELTA, free, MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), pgtypes_alloc(), PGTYPES_INTVL_BAD_INTERVAL, str, tm, tm2interval(), pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, and pg_tm::tm_year.

Referenced by ecpg_get_data(), and main().

◆ PGTYPESinterval_new()

interval * PGTYPESinterval_new ( void  )

Definition at line 987 of file interval.c.

988{
989 interval *result;
990
991 result = (interval *) pgtypes_alloc(sizeof(interval));
992 /* result can be NULL if we run out of memory */
993 return result;
994}

References pgtypes_alloc().

Referenced by main().

◆ PGTYPESinterval_to_asc()

char * PGTYPESinterval_to_asc ( interval span)

Definition at line 1062 of file interval.c.

1063{
1064 struct tm tt,
1065 *tm = &tt;
1066 fsec_t fsec;
1067 char buf[MAXDATELEN + 1];
1069
1070 if (interval2tm(*span, tm, &fsec) != 0)
1071 {
1073 return NULL;
1074 }
1075
1077
1078 return pgtypes_strdup(buf);
1079}
int IntervalStyle
Definition: globals.c:126
char * pgtypes_strdup(const char *str)
Definition: common.c:20
static int interval2tm(interval span, struct tm *tm, fsec_t *fsec)
Definition: interval.c:942
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str)
Definition: interval.c:759
#define INTSTYLE_POSTGRES_VERBOSE
Definition: miscadmin.h:257
static char * buf
Definition: pg_test_fsync.c:72

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

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