-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg_dms_family.c
191 lines (187 loc) · 4.77 KB
/
pg_dms_family.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "postgres.h"
#include "fmgr.h"
#include "utils/fmgrprotos.h"
#include "utils/uuid.h"
#include "utils/timestamp.h"
#include "utils/lsyscache.h"
#include "utils/builtins.h"
#include "utils/array.h"
#include "access/xact.h"
#include "access/htup_details.h"
#include "miscadmin.h"
#include "funcapi.h"
#include "pg_dms.h"
//
//
// family type
//
//
PG_FUNCTION_INFO_V1(pg_dms_family_in);
PG_FUNCTION_INFO_V1(pg_dms_family_out);
Datum
pg_dms_family_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
pg_dms_family *result = palloc(sizeof(pg_dms_family));
result->family = *DatumGetUUIDP(DirectFunctionCall1(uuid_in, CStringGetDatum(strtok (str, "_"))));
PG_RETURN_POINTER(result);
}
Datum
pg_dms_family_out(PG_FUNCTION_ARGS)
{
pg_dms_family *id = PG_GETARG_PGDMSFAMILY_P(0);
char *f = DatumGetCString(DirectFunctionCall1(uuid_out, UUIDPGetDatum(&id->family)));
char *result = psprintf("%s", f);
PG_RETURN_CSTRING(result);
};
//
//
// family uuid
//
//
PG_FUNCTION_INFO_V1(pg_dms_uuid2family);
Datum
pg_dms_uuid2family(PG_FUNCTION_ARGS)
{
pg_uuid_t *a = PG_GETARG_UUID_P(0);
pg_dms_family *result = palloc(sizeof(pg_dms_family));
result->family = *a;
PG_RETURN_POINTER(result);
}
//
//
// family <-> family
//
//
PG_FUNCTION_INFO_V1(pg_dms_family_cmp);
PG_FUNCTION_INFO_V1(pg_dms_familygt);
PG_FUNCTION_INFO_V1(pg_dms_familyge);
PG_FUNCTION_INFO_V1(pg_dms_familyeq);
PG_FUNCTION_INFO_V1(pg_dms_familylt);
PG_FUNCTION_INFO_V1(pg_dms_familyle);
//
static int family_cmp (pg_dms_family *a, pg_dms_family *b)
{
return memcmp(&(a->family), &(b->family),UUID_LEN);
};
Datum
pg_dms_family_cmp(PG_FUNCTION_ARGS)
{
PG_RETURN_INT32(family_cmp(PG_GETARG_PGDMSFAMILY_P(0), PG_GETARG_PGDMSFAMILY_P(1)));
};
Datum
pg_dms_familygt(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(family_cmp(PG_GETARG_PGDMSFAMILY_P(0), PG_GETARG_PGDMSFAMILY_P(1))>0);
};
Datum
pg_dms_familyge(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(family_cmp(PG_GETARG_PGDMSFAMILY_P(0), PG_GETARG_PGDMSFAMILY_P(1))>=0);
};
Datum
pg_dms_familyeq(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(family_cmp(PG_GETARG_PGDMSFAMILY_P(0), PG_GETARG_PGDMSFAMILY_P(1))==0);
};
Datum
pg_dms_familyle(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(family_cmp(PG_GETARG_PGDMSFAMILY_P(0), PG_GETARG_PGDMSFAMILY_P(1))<=0);
};
Datum
pg_dms_familylt(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(family_cmp(PG_GETARG_PGDMSFAMILY_P(0), PG_GETARG_PGDMSFAMILY_P(1))<0);
};
//
//
// id <-> family
//
//
PG_FUNCTION_INFO_V1(pg_dms_idfamily_cmp);
PG_FUNCTION_INFO_V1(pg_dms_idfamilygt);
PG_FUNCTION_INFO_V1(pg_dms_idfamilyge);
PG_FUNCTION_INFO_V1(pg_dms_idfamilyeq);
PG_FUNCTION_INFO_V1(pg_dms_idfamilylt);
PG_FUNCTION_INFO_V1(pg_dms_idfamilyle);
//
static int idfamily_cmp (pg_dms_id *a, pg_dms_family *b)
{
return memcmp(&(a->family), &(b->family), UUID_LEN);
}
Datum
pg_dms_idfamily_cmp(PG_FUNCTION_ARGS)
{
PG_RETURN_INT32(idfamily_cmp(PG_GETARG_PGDMSID_P(0), PG_GETARG_PGDMSFAMILY_P(1)));
};
Datum
pg_dms_idfamilygt(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(idfamily_cmp(PG_GETARG_PGDMSID_P(0), PG_GETARG_PGDMSFAMILY_P(1))>0);
};
Datum
pg_dms_idfamilyge(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(idfamily_cmp(PG_GETARG_PGDMSID_P(0), PG_GETARG_PGDMSFAMILY_P(1))>=0);
};
Datum
pg_dms_idfamilyeq(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(idfamily_cmp(PG_GETARG_PGDMSID_P(0), PG_GETARG_PGDMSFAMILY_P(1))==0);
};
Datum
pg_dms_idfamilyle(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(idfamily_cmp(PG_GETARG_PGDMSID_P(0), PG_GETARG_PGDMSFAMILY_P(1))<=0);
};
Datum
pg_dms_idfamilylt(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(idfamily_cmp(PG_GETARG_PGDMSID_P(0), PG_GETARG_PGDMSFAMILY_P(1))<0);
};
//
//
// family <-> id
//
//
PG_FUNCTION_INFO_V1(pg_dms_familyid_cmp);
PG_FUNCTION_INFO_V1(pg_dms_familyidgt);
PG_FUNCTION_INFO_V1(pg_dms_familyidge);
PG_FUNCTION_INFO_V1(pg_dms_familyideq);
PG_FUNCTION_INFO_V1(pg_dms_familyidlt);
PG_FUNCTION_INFO_V1(pg_dms_familyidle);
static int familyid_cmp (pg_dms_family *a, pg_dms_id *b)
{
return memcmp( &(a->family), &(b->family), UUID_LEN);
}
Datum
pg_dms_familyid_cmp(PG_FUNCTION_ARGS)
{
PG_RETURN_INT32(familyid_cmp(PG_GETARG_PGDMSFAMILY_P(0),PG_GETARG_PGDMSID_P(1)));
};
Datum
pg_dms_familyidgt(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(familyid_cmp(PG_GETARG_PGDMSFAMILY_P(0),PG_GETARG_PGDMSID_P(1))>0);
};
Datum
pg_dms_familyidge(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(familyid_cmp(PG_GETARG_PGDMSFAMILY_P(0),PG_GETARG_PGDMSID_P(1))>=0);
};
Datum
pg_dms_familyideq(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(familyid_cmp(PG_GETARG_PGDMSFAMILY_P(0),PG_GETARG_PGDMSID_P(1))==0);
};
Datum
pg_dms_familyidle(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(familyid_cmp(PG_GETARG_PGDMSFAMILY_P(0),PG_GETARG_PGDMSID_P(1))<=0);
};
Datum
pg_dms_familyidlt(PG_FUNCTION_ARGS)
{
PG_RETURN_BOOL(familyid_cmp(PG_GETARG_PGDMSFAMILY_P(0),PG_GETARG_PGDMSID_P(1))<0);
};