PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgtypes_interval.h File Reference
#include <stdint.h>
#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
 

Typedefs

typedef int64_t int64
 

Functions

intervalPGTYPESinterval_new (void)
 
void PGTYPESinterval_free (interval *intvl)
 
intervalPGTYPESinterval_from_asc (char *str, char **endptr)
 
charPGTYPESinterval_to_asc (interval *span)
 
int PGTYPESinterval_copy (interval *intvlsrc, interval *intvldest)
 

Macro Definition Documentation

◆ HAVE_INT64_TIMESTAMP

#define HAVE_INT64_TIMESTAMP

Definition at line 15 of file pgtypes_interval.h.

Typedef Documentation

◆ int64

Definition at line 13 of file pgtypes_interval.h.

Function Documentation

◆ PGTYPESinterval_copy()

int PGTYPESinterval_copy ( interval intvlsrc,
interval intvldest 
)
extern

Definition at line 1085 of file interval.c.

1086{
1087 intvldest->time = intvlsrc->time;
1088 intvldest->month = intvlsrc->month;
1089
1090 return 0;
1091}
static int fb(int x)

References fb().

Referenced by ecpg_get_data(), and main().

◆ PGTYPESinterval_free()

void PGTYPESinterval_free ( interval intvl)
extern

Definition at line 1000 of file interval.c.

1001{
1002 free(intvl);
1003}
#define free(a)

References fb(), and free.

Referenced by main().

◆ PGTYPESinterval_from_asc()

interval * PGTYPESinterval_from_asc ( char str,
char **  endptr 
)
extern

Definition at line 1006 of file interval.c.

1007{
1008 interval *result = NULL;
1009 fsec_t fsec;
1010 struct tm tt,
1011 *tm = &tt;
1012 int dtype;
1013 int nf;
1014 char *field[MAXDATEFIELDS];
1015 int ftype[MAXDATEFIELDS];
1017 char *realptr;
1018 char **ptr = (endptr != NULL) ? endptr : &realptr;
1019
1020 tm->tm_year = 0;
1021 tm->tm_mon = 0;
1022 tm->tm_mday = 0;
1023 tm->tm_hour = 0;
1024 tm->tm_min = 0;
1025 tm->tm_sec = 0;
1026 fsec = 0;
1027
1028 if (strlen(str) > MAXDATELEN)
1029 {
1031 return NULL;
1032 }
1033
1034 if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
1035 (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
1036 DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
1037 {
1039 return NULL;
1040 }
1041
1042 result = (interval *) pgtypes_alloc(sizeof(interval));
1043 if (!result)
1044 return NULL;
1045
1046 if (dtype != DTK_DELTA)
1047 {
1049 free(result);
1050 return NULL;
1051 }
1052
1053 if (tm2interval(tm, fsec, result) != 0)
1054 {
1056 free(result);
1057 return NULL;
1058 }
1059
1060 errno = 0;
1061 return result;
1062}
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition datetime.c:775
uint32 result
int32 fsec_t
Definition timestamp.h:41
const char * str
#define MAXDATEFIELDS
Definition datetime.h:202
#define DTK_DELTA
Definition datetime.h:159
#define MAXDATELEN
Definition datetime.h:200
char * pgtypes_alloc(long size)
Definition common.c:10
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:975
int DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec)
Definition interval.c:327
static struct pg_tm tm
Definition localtime.c:104
#define PGTYPES_INTVL_BAD_INTERVAL
int tm_hour
Definition pgtime.h:38
int tm_mday
Definition pgtime.h:39
int tm_mon
Definition pgtime.h:40
int tm_min
Definition pgtime.h:37
int tm_sec
Definition pgtime.h:36
int tm_year
Definition pgtime.h:41

References DecodeInterval(), DecodeISO8601Interval(), DTK_DELTA, fb(), free, MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), pgtypes_alloc(), PGTYPES_INTVL_BAD_INTERVAL, result, str, tm, tm2interval(), pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, and pg_tm::tm_year.

Referenced by ecpg_get_data(), and main().

◆ PGTYPESinterval_new()

interval * PGTYPESinterval_new ( void  )
extern

Definition at line 990 of file interval.c.

991{
993
994 result = (interval *) pgtypes_alloc(sizeof(interval));
995 /* result can be NULL if we run out of memory */
996 return result;
997}

References pgtypes_alloc(), and result.

Referenced by main().

◆ PGTYPESinterval_to_asc()

char * PGTYPESinterval_to_asc ( interval span)
extern

Definition at line 1065 of file interval.c.

1066{
1067 struct tm tt,
1068 *tm = &tt;
1069 fsec_t fsec;
1070 char buf[MAXDATELEN + 1];
1072
1073 if (interval2tm(*span, tm, &fsec) != 0)
1074 {
1076 return NULL;
1077 }
1078
1080
1081 return pgtypes_strdup(buf);
1082}
int IntervalStyle
Definition globals.c:129
char * pgtypes_strdup(const char *str)
Definition common.c:20
static int interval2tm(interval span, struct tm *tm, fsec_t *fsec)
Definition interval.c:945
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str)
Definition interval.c:761
#define INTSTYLE_POSTGRES_VERBOSE
Definition miscadmin.h:261
static char buf[DEFAULT_XLOG_SEG_SIZE]

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

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