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

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

Referenced by ecpg_get_data(), and main().

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

◆ PGTYPESinterval_free()

void PGTYPESinterval_free ( interval )

Definition at line 1001 of file interval.c.

References free.

Referenced by main().

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

◆ PGTYPESinterval_from_asc()

interval* PGTYPESinterval_from_asc ( char *  ,
char **   
)

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

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

References pgtypes_alloc().

Referenced by main().

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

◆ PGTYPESinterval_to_asc()

char* PGTYPESinterval_to_asc ( interval )

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

1067 {
1068  struct tm tt,
1069  *tm = &tt;
1070  fsec_t fsec;
1071  char buf[MAXDATELEN + 1];
1073 
1074  if (interval2tm(*span, tm, &fsec) != 0)
1075  {
1077  return NULL;
1078  }
1079 
1080  EncodeInterval(tm, fsec, IntervalStyle, buf);
1081 
1082  return pgtypes_strdup(buf);
1083 }
#define MAXDATELEN
Definition: datetime.h:203
#define INTSTYLE_POSTGRES_VERBOSE
Definition: miscadmin.h:233
int IntervalStyle
Definition: globals.c:116
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str)
Definition: interval.c:763
static struct pg_tm tm
Definition: localtime.c:106
char * pgtypes_strdup(const char *str)
Definition: common.c:20
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:945
#define PGTYPES_INTVL_BAD_INTERVAL
Definition: pgtypes_error.h:18