PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

#define HAVE_INT64_TIMESTAMP

Definition at line 23 of file pgtypes_interval.h.

Function Documentation

int PGTYPESinterval_copy ( interval ,
interval  
)

Definition at line 1104 of file interval.c.

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

Referenced by ecpg_get_data(), and main().

1105 {
1106  intvldest->time = intvlsrc->time;
1107  intvldest->month = intvlsrc->month;
1108 
1109  return 0;
1110 }
void PGTYPESinterval_free ( interval )

Definition at line 1015 of file interval.c.

References free.

Referenced by main().

1016 {
1017  free(intvl);
1018 }
#define free(a)
Definition: header.h:65
interval* PGTYPESinterval_from_asc ( char *  ,
char **   
)

Definition at line 1021 of file interval.c.

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

Referenced by ecpg_get_data(), and main().

1022 {
1023  interval *result = NULL;
1024  fsec_t fsec;
1025  struct tm tt,
1026  *tm = &tt;
1027  int dtype;
1028  int nf;
1029  char *field[MAXDATEFIELDS];
1030  int ftype[MAXDATEFIELDS];
1031  char lowstr[MAXDATELEN + MAXDATEFIELDS];
1032  char *realptr;
1033  char **ptr = (endptr != NULL) ? endptr : &realptr;
1034 
1035  tm->tm_year = 0;
1036  tm->tm_mon = 0;
1037  tm->tm_mday = 0;
1038  tm->tm_hour = 0;
1039  tm->tm_min = 0;
1040  tm->tm_sec = 0;
1041  fsec = 0;
1042 
1043  if (strlen(str) > MAXDATELEN)
1044  {
1046  return NULL;
1047  }
1048 
1049  if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
1050  (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
1051  DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
1052  {
1054  return NULL;
1055  }
1056 
1057  result = (interval *) pgtypes_alloc(sizeof(interval));
1058  if (!result)
1059  return NULL;
1060 
1061  if (dtype != DTK_DELTA)
1062  {
1064  free(result);
1065  return NULL;
1066  }
1067 
1068  if (tm2interval(tm, fsec, result) != 0)
1069  {
1071  free(result);
1072  return NULL;
1073  }
1074 
1075  errno = 0;
1076  return result;
1077 }
#define MAXDATELEN
Definition: datetime.h:203
static int tm2interval(struct tm *tm, fsec_t fsec, interval *span)
Definition: interval.c:990
#define DTK_DELTA
Definition: datetime.h:162
int DecodeInterval(char **field, int *ftype, int nf, int *dtype, structtm *tm, fsec_t *fsec)
Definition: interval.c:338
static struct pg_tm tm
Definition: localtime.c:103
char * pgtypes_alloc(long size)
Definition: common.c:9
static int DecodeISO8601Interval(char *str, int *dtype, structtm *tm, fsec_t *fsec)
Definition: interval.c:124
int32 fsec_t
Definition: timestamp.h:41
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
#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
interval* PGTYPESinterval_new ( void  )

Definition at line 1005 of file interval.c.

References pgtypes_alloc().

Referenced by main().

1006 {
1007  interval *result;
1008 
1009  result = (interval *) pgtypes_alloc(sizeof(interval));
1010  /* result can be NULL if we run out of memory */
1011  return result;
1012 }
char * pgtypes_alloc(long size)
Definition: common.c:9
char* PGTYPESinterval_to_asc ( interval )

Definition at line 1080 of file interval.c.

References buf, EncodeInterval(), interval2tm(), IntervalStyle, INTSTYLE_POSTGRES_VERBOSE, MAXDATELEN, NULL, PGTYPES_INTVL_BAD_INTERVAL, pgtypes_strdup(), and tm.

Referenced by ecpg_store_input(), intoasc(), and main().

1081 {
1082  struct tm tt,
1083  *tm = &tt;
1084  fsec_t fsec;
1085  char buf[MAXDATELEN + 1];
1087 
1088  if (interval2tm(*span, tm, &fsec) != 0)
1089  {
1091  return NULL;
1092  }
1093 
1094  if (EncodeInterval(tm, fsec, IntervalStyle, buf) != 0)
1095  {
1097  return NULL;
1098  }
1099 
1100  return pgtypes_strdup(buf);
1101 }
#define MAXDATELEN
Definition: datetime.h:203
#define INTSTYLE_POSTGRES_VERBOSE
Definition: miscadmin.h:231
int IntervalStyle
Definition: globals.c:108
static struct pg_tm tm
Definition: localtime.c:103
char * pgtypes_strdup(const char *str)
Definition: common.c:19
static char * buf
Definition: pg_test_fsync.c:65
int32 fsec_t
Definition: timestamp.h:41
int EncodeInterval(structtm *tm, fsec_t fsec, int style, char *str)
Definition: interval.c:775
#define NULL
Definition: c.h:229
static int interval2tm(interval span, struct tm *tm, fsec_t *fsec)
Definition: interval.c:959
#define PGTYPES_INTVL_BAD_INTERVAL
Definition: pgtypes_error.h:18