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 1087 of file interval.c.

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

Referenced by ecpg_get_data(), and main().

1088 {
1089  intvldest->time = intvlsrc->time;
1090  intvldest->month = intvlsrc->month;
1091 
1092  return 0;
1093 }

◆ PGTYPESinterval_free()

void PGTYPESinterval_free ( interval )

Definition at line 1002 of file interval.c.

References free.

Referenced by main().

1003 {
1004  free(intvl);
1005 }
#define free(a)
Definition: header.h:65

◆ PGTYPESinterval_from_asc()

interval* PGTYPESinterval_from_asc ( char *  ,
char **   
)

Definition at line 1008 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().

1009 {
1010  interval *result = NULL;
1011  fsec_t fsec;
1012  struct tm tt,
1013  *tm = &tt;
1014  int dtype;
1015  int nf;
1016  char *field[MAXDATEFIELDS];
1017  int ftype[MAXDATEFIELDS];
1018  char lowstr[MAXDATELEN + MAXDATEFIELDS];
1019  char *realptr;
1020  char **ptr = (endptr != NULL) ? endptr : &realptr;
1021 
1022  tm->tm_year = 0;
1023  tm->tm_mon = 0;
1024  tm->tm_mday = 0;
1025  tm->tm_hour = 0;
1026  tm->tm_min = 0;
1027  tm->tm_sec = 0;
1028  fsec = 0;
1029 
1030  if (strlen(str) > MAXDATELEN)
1031  {
1033  return NULL;
1034  }
1035 
1036  if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
1037  (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
1038  DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
1039  {
1041  return NULL;
1042  }
1043 
1044  result = (interval *) pgtypes_alloc(sizeof(interval));
1045  if (!result)
1046  return NULL;
1047 
1048  if (dtype != DTK_DELTA)
1049  {
1051  free(result);
1052  return NULL;
1053  }
1054 
1055  if (tm2interval(tm, fsec, result) != 0)
1056  {
1058  free(result);
1059  return NULL;
1060  }
1061 
1062  errno = 0;
1063  return result;
1064 }
#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:977
#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:32
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 992 of file interval.c.

References pgtypes_alloc().

Referenced by main().

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

◆ PGTYPESinterval_to_asc()

char* PGTYPESinterval_to_asc ( interval )

Definition at line 1067 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().

1068 {
1069  struct tm tt,
1070  *tm = &tt;
1071  fsec_t fsec;
1072  char buf[MAXDATELEN + 1];
1074 
1075  if (interval2tm(*span, tm, &fsec) != 0)
1076  {
1078  return NULL;
1079  }
1080 
1081  EncodeInterval(tm, fsec, IntervalStyle, buf);
1082 
1083  return pgtypes_strdup(buf);
1084 }
#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:763
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:946
#define PGTYPES_INTVL_BAD_INTERVAL
Definition: pgtypes_error.h:18