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

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

Referenced by ecpg_get_data(), and main().

1097 {
1098  intvldest->time = intvlsrc->time;
1099  intvldest->month = intvlsrc->month;
1100 
1101  return 0;
1102 }

◆ PGTYPESinterval_free()

void PGTYPESinterval_free ( interval )

Definition at line 1011 of file interval.c.

References free.

Referenced by main().

1012 {
1013  free(intvl);
1014 }
#define free(a)
Definition: header.h:65

◆ PGTYPESinterval_from_asc()

interval* PGTYPESinterval_from_asc ( char *  ,
char **   
)

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

1018 {
1019  interval *result = NULL;
1020  fsec_t fsec;
1021  struct tm tt,
1022  *tm = &tt;
1023  int dtype;
1024  int nf;
1025  char *field[MAXDATEFIELDS];
1026  int ftype[MAXDATEFIELDS];
1027  char lowstr[MAXDATELEN + MAXDATEFIELDS];
1028  char *realptr;
1029  char **ptr = (endptr != NULL) ? endptr : &realptr;
1030 
1031  tm->tm_year = 0;
1032  tm->tm_mon = 0;
1033  tm->tm_mday = 0;
1034  tm->tm_hour = 0;
1035  tm->tm_min = 0;
1036  tm->tm_sec = 0;
1037  fsec = 0;
1038 
1039  if (strlen(str) > MAXDATELEN)
1040  {
1042  return NULL;
1043  }
1044 
1045  if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
1046  (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
1047  DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
1048  {
1050  return NULL;
1051  }
1052 
1053  result = (interval *) pgtypes_alloc(sizeof(interval));
1054  if (!result)
1055  return NULL;
1056 
1057  if (dtype != DTK_DELTA)
1058  {
1060  free(result);
1061  return NULL;
1062  }
1063 
1064  if (tm2interval(tm, fsec, result) != 0)
1065  {
1067  free(result);
1068  return NULL;
1069  }
1070 
1071  errno = 0;
1072  return result;
1073 }
#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:336
static int DecodeISO8601Interval(char *str, int *dtype, struct tm *tm, fsec_t *fsec)
Definition: interval.c:124
static int tm2interval(struct tm *tm, fsec_t fsec, interval *span)
Definition: interval.c:986
#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:562

◆ PGTYPESinterval_new()

interval* PGTYPESinterval_new ( void  )

Definition at line 1001 of file interval.c.

References pgtypes_alloc().

Referenced by main().

1002 {
1003  interval *result;
1004 
1005  result = (interval *) pgtypes_alloc(sizeof(interval));
1006  /* result can be NULL if we run out of memory */
1007  return result;
1008 }
char * pgtypes_alloc(long size)
Definition: common.c:9

◆ PGTYPESinterval_to_asc()

char* PGTYPESinterval_to_asc ( interval )

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

1077 {
1078  struct tm tt,
1079  *tm = &tt;
1080  fsec_t fsec;
1081  char buf[MAXDATELEN + 1];
1083 
1084  if (interval2tm(*span, tm, &fsec) != 0)
1085  {
1087  return NULL;
1088  }
1089 
1090  EncodeInterval(tm, fsec, IntervalStyle, buf);
1091 
1092  return pgtypes_strdup(buf);
1093 }
#define MAXDATELEN
Definition: datetime.h:203
#define INTSTYLE_POSTGRES_VERBOSE
Definition: miscadmin.h:232
int IntervalStyle
Definition: globals.c:109
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str)
Definition: interval.c:773
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:955
#define PGTYPES_INTVL_BAD_INTERVAL
Definition: pgtypes_error.h:18