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

1079{
1080 intvldest->time = intvlsrc->time;
1081 intvldest->month = intvlsrc->month;
1082
1083 return 0;
1084}
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 993 of file interval.c.

994{
995 free(intvl);
996}
#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 999 of file interval.c.

1000{
1001 interval *result = NULL;
1002 fsec_t fsec;
1003 struct tm tt,
1004 *tm = &tt;
1005 int dtype;
1006 int nf;
1007 char *field[MAXDATEFIELDS];
1008 int ftype[MAXDATEFIELDS];
1010 char *realptr;
1011 char **ptr = (endptr != NULL) ? endptr : &realptr;
1012
1013 tm->tm_year = 0;
1014 tm->tm_mon = 0;
1015 tm->tm_mday = 0;
1016 tm->tm_hour = 0;
1017 tm->tm_min = 0;
1018 tm->tm_sec = 0;
1019 fsec = 0;
1020
1021 if (strlen(str) > MAXDATELEN)
1022 {
1024 return NULL;
1025 }
1026
1027 if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
1028 (DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
1029 DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0))
1030 {
1032 return NULL;
1033 }
1034
1035 result = (interval *) pgtypes_alloc(sizeof(interval));
1036 if (!result)
1037 return NULL;
1038
1039 if (dtype != DTK_DELTA)
1040 {
1042 free(result);
1043 return NULL;
1044 }
1045
1046 if (tm2interval(tm, fsec, result) != 0)
1047 {
1049 free(result);
1050 return NULL;
1051 }
1052
1053 errno = 0;
1054 return result;
1055}
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition datetime.c:774
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:108
static int tm2interval(struct tm *tm, fsec_t fsec, interval *span)
Definition interval.c:968
int DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec)
Definition interval.c:322
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, 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 983 of file interval.c.

984{
985 interval *result;
986
987 result = (interval *) pgtypes_alloc(sizeof(interval));
988 /* result can be NULL if we run out of memory */
989 return result;
990}

References pgtypes_alloc().

Referenced by main().

◆ PGTYPESinterval_to_asc()

char * PGTYPESinterval_to_asc ( interval span)
extern

Definition at line 1058 of file interval.c.

1059{
1060 struct tm tt,
1061 *tm = &tt;
1062 fsec_t fsec;
1063 char buf[MAXDATELEN + 1];
1065
1066 if (interval2tm(*span, tm, &fsec) != 0)
1067 {
1069 return NULL;
1070 }
1071
1073
1074 return pgtypes_strdup(buf);
1075}
int IntervalStyle
Definition globals.c:127
char * pgtypes_strdup(const char *str)
Definition common.c:20
static int interval2tm(interval span, struct tm *tm, fsec_t *fsec)
Definition interval.c:938
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str)
Definition interval.c:755
#define INTSTYLE_POSTGRES_VERBOSE
Definition miscadmin.h:258
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().