PostgreSQL Source Code  git master
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
 

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 23 of file pgtypes_interval.h.

Function Documentation

◆ PGTYPESinterval_copy()

int PGTYPESinterval_copy ( interval ,
interval  
)

Definition at line 1084 of file interval.c.

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

Referenced by ecpg_get_data(), and main().

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

◆ PGTYPESinterval_free()

void PGTYPESinterval_free ( interval )

Definition at line 999 of file interval.c.

References free.

Referenced by main().

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

◆ PGTYPESinterval_from_asc()

interval* PGTYPESinterval_from_asc ( char *  ,
char **   
)

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

1006 {
1007  interval *result = NULL;
1008  fsec_t fsec;
1009  struct tm tt,
1010  *tm = &tt;
1011  int dtype;
1012  int nf;
1013  char *field[MAXDATEFIELDS];
1014  int ftype[MAXDATEFIELDS];
1015  char lowstr[MAXDATELEN + MAXDATEFIELDS];
1016  char *realptr;
1017  char **ptr = (endptr != NULL) ? endptr : &realptr;
1018 
1019  tm->tm_year = 0;
1020  tm->tm_mon = 0;
1021  tm->tm_mday = 0;
1022  tm->tm_hour = 0;
1023  tm->tm_min = 0;
1024  tm->tm_sec = 0;
1025  fsec = 0;
1026 
1027  if (strlen(str) > MAXDATELEN)
1028  {
1030  return NULL;
1031  }
1032 
1033  if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
1034  (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
1035  DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
1036  {
1038  return NULL;
1039  }
1040 
1041  result = (interval *) pgtypes_alloc(sizeof(interval));
1042  if (!result)
1043  return NULL;
1044 
1045  if (dtype != DTK_DELTA)
1046  {
1048  free(result);
1049  return NULL;
1050  }
1051 
1052  if (tm2interval(tm, fsec, result) != 0)
1053  {
1055  free(result);
1056  return NULL;
1057  }
1058 
1059  errno = 0;
1060  return result;
1061 }
#define MAXDATELEN
Definition: datetime.h:203
int DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec)
Definition: interval.c:324
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:974
#define DTK_DELTA
Definition: datetime.h:162
static struct pg_tm tm
Definition: localtime.c:107
char * pgtypes_alloc(long size)
Definition: common.c:9
int32 fsec_t
Definition: timestamp.h:41
#define free(a)
Definition: header.h:65
#define MAXDATEFIELDS
Definition: datetime.h:205
#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:546

◆ PGTYPESinterval_new()

interval* PGTYPESinterval_new ( void  )

Definition at line 989 of file interval.c.

References pgtypes_alloc().

Referenced by main().

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

◆ PGTYPESinterval_to_asc()

char* PGTYPESinterval_to_asc ( interval )

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

1065 {
1066  struct tm tt,
1067  *tm = &tt;
1068  fsec_t fsec;
1069  char buf[MAXDATELEN + 1];
1071 
1072  if (interval2tm(*span, tm, &fsec) != 0)
1073  {
1075  return NULL;
1076  }
1077 
1078  EncodeInterval(tm, fsec, IntervalStyle, buf);
1079 
1080  return pgtypes_strdup(buf);
1081 }
#define MAXDATELEN
Definition: datetime.h:203
#define INTSTYLE_POSTGRES_VERBOSE
Definition: miscadmin.h:233
int IntervalStyle
Definition: globals.c:118
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str)
Definition: interval.c:761
static struct pg_tm tm
Definition: localtime.c:107
char * pgtypes_strdup(const char *str)
Definition: common.c:19
static char * buf
Definition: pg_test_fsync.c:67
int32 fsec_t
Definition: timestamp.h:41
static int interval2tm(interval span, struct tm *tm, fsec_t *fsec)
Definition: interval.c:943
#define PGTYPES_INTVL_BAD_INTERVAL
Definition: pgtypes_error.h:18