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

Functions

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

Macro Definition Documentation

◆ HAVE_INT64_TIMESTAMP

#define HAVE_INT64_TIMESTAMP

Definition at line 24 of file pgtypes_interval.h.

Function Documentation

◆ PGTYPESinterval_copy()

int PGTYPESinterval_copy ( interval ,
interval  
)

Definition at line 1083 of file interval.c.

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

Referenced by ecpg_get_data(), and main().

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

◆ PGTYPESinterval_free()

void PGTYPESinterval_free ( interval )

Definition at line 998 of file interval.c.

References free.

Referenced by main().

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

◆ PGTYPESinterval_from_asc()

interval* PGTYPESinterval_from_asc ( char *  ,
char **   
)

Definition at line 1004 of file interval.c.

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

Referenced by ecpg_get_data(), and main().

1005 {
1006  interval *result = NULL;
1007  fsec_t fsec;
1008  struct tm tt,
1009  *tm = &tt;
1010  int dtype;
1011  int nf;
1012  char *field[MAXDATEFIELDS];
1013  int ftype[MAXDATEFIELDS];
1014  char lowstr[MAXDATELEN + MAXDATEFIELDS];
1015  char *realptr;
1016  char **ptr = (endptr != NULL) ? endptr : &realptr;
1017 
1018  tm->tm_year = 0;
1019  tm->tm_mon = 0;
1020  tm->tm_mday = 0;
1021  tm->tm_hour = 0;
1022  tm->tm_min = 0;
1023  tm->tm_sec = 0;
1024  fsec = 0;
1025 
1026  if (strlen(str) > MAXDATELEN)
1027  {
1029  return NULL;
1030  }
1031 
1032  if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
1033  (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
1034  DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
1035  {
1037  return NULL;
1038  }
1039 
1040  result = (interval *) pgtypes_alloc(sizeof(interval));
1041  if (!result)
1042  return NULL;
1043 
1044  if (dtype != DTK_DELTA)
1045  {
1047  free(result);
1048  return NULL;
1049  }
1050 
1051  if (tm2interval(tm, fsec, result) != 0)
1052  {
1054  free(result);
1055  return NULL;
1056  }
1057 
1058  errno = 0;
1059  return result;
1060 }
#define MAXDATELEN
Definition: datetime.h:201
int DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec)
Definition: interval.c:326
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:973
#define DTK_DELTA
Definition: datetime.h:160
static struct pg_tm tm
Definition: localtime.c:102
char * pgtypes_alloc(long size)
Definition: common.c:10
int32 fsec_t
Definition: timestamp.h:41
#define free(a)
Definition: header.h:65
#define MAXDATEFIELDS
Definition: datetime.h:203
#define PGTYPES_INTVL_BAD_INTERVAL
Definition: pgtypes_error.h:18
int tm_year
Definition: pgtime.h:39
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:582

◆ PGTYPESinterval_new()

interval* PGTYPESinterval_new ( void  )

Definition at line 988 of file interval.c.

References pgtypes_alloc().

Referenced by main().

989 {
990  interval *result;
991 
992  result = (interval *) pgtypes_alloc(sizeof(interval));
993  /* result can be NULL if we run out of memory */
994  return result;
995 }
char * pgtypes_alloc(long size)
Definition: common.c:10

◆ PGTYPESinterval_to_asc()

char* PGTYPESinterval_to_asc ( interval )

Definition at line 1063 of file interval.c.

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().

1064 {
1065  struct tm tt,
1066  *tm = &tt;
1067  fsec_t fsec;
1068  char buf[MAXDATELEN + 1];
1070 
1071  if (interval2tm(*span, tm, &fsec) != 0)
1072  {
1074  return NULL;
1075  }
1076 
1077  EncodeInterval(tm, fsec, IntervalStyle, buf);
1078 
1079  return pgtypes_strdup(buf);
1080 }
#define MAXDATELEN
Definition: datetime.h:201
#define INTSTYLE_POSTGRES_VERBOSE
Definition: miscadmin.h:250
int IntervalStyle
Definition: globals.c:120
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str)
Definition: interval.c:759
static struct pg_tm tm
Definition: localtime.c:102
char * pgtypes_strdup(const char *str)
Definition: common.c:20
static char * buf
Definition: pg_test_fsync.c:68
int32 fsec_t
Definition: timestamp.h:41
static int interval2tm(interval span, struct tm *tm, fsec_t *fsec)
Definition: interval.c:942
#define PGTYPES_INTVL_BAD_INTERVAL
Definition: pgtypes_error.h:18