Line 0
Link Here
|
|
|
1 |
--- src/plpl.c.orig 2019-08-04 04:35:14 UTC |
2 |
+++ src/plpl.c |
3 |
@@ -137,12 +137,21 @@ pl_query_name(VALUE obj) |
4 |
} |
5 |
res = rb_ary_new2(tpl->dsc->natts); |
6 |
for (i = 0; i < tpl->dsc->natts; i++) { |
7 |
+#if PG_VERSION_NUM < 110000 |
8 |
if (tpl->dsc->attrs[i]->attisdropped) { |
9 |
attname = ""; |
10 |
} |
11 |
else { |
12 |
attname = NameStr(tpl->dsc->attrs[i]->attname); |
13 |
} |
14 |
+#else |
15 |
+ if (tpl->dsc->attrs[i].attisdropped) { |
16 |
+ attname = ""; |
17 |
+ } |
18 |
+ else { |
19 |
+ attname = NameStr(tpl->dsc->attrs[i].attname); |
20 |
+ } |
21 |
+#endif |
22 |
rb_ary_push(res, rb_tainted_str_new2(attname)); |
23 |
} |
24 |
return res; |
25 |
@@ -178,6 +187,7 @@ pl_query_type(VALUE obj) |
26 |
} |
27 |
res = rb_ary_new2(tpl->dsc->natts); |
28 |
for (i = 0; i < tpl->dsc->natts; i++) { |
29 |
+#if PG_VERSION_NUM < 110000 |
30 |
if (tpl->dsc->attrs[i]->attisdropped) |
31 |
continue; |
32 |
PLRUBY_BEGIN(1); |
33 |
@@ -189,6 +199,19 @@ pl_query_type(VALUE obj) |
34 |
rb_raise(pl_ePLruby, "Cache lookup for attribute '%s' type %ld failed", |
35 |
attname, OidGD(tpl->dsc->attrs[i]->atttypid)); |
36 |
} |
37 |
+#else |
38 |
+ if (tpl->dsc->attrs[i].attisdropped) |
39 |
+ continue; |
40 |
+ PLRUBY_BEGIN(1); |
41 |
+ attname = NameStr(tpl->dsc->attrs[i].attname); |
42 |
+ typeTup = SearchSysCache(TYPEOID, OidGD(tpl->dsc->attrs[i].atttypid), |
43 |
+ 0, 0, 0); |
44 |
+ PLRUBY_END; |
45 |
+ if (!HeapTupleIsValid(typeTup)) { |
46 |
+ rb_raise(pl_ePLruby, "Cache lookup for attribute '%s' type %ld failed", |
47 |
+ attname, OidGD(tpl->dsc->attrs[i].atttypid)); |
48 |
+ } |
49 |
+#endif |
50 |
fpgt = (Form_pg_type) GETSTRUCT(typeTup); |
51 |
rb_ary_push(res, rb_tainted_str_new2(NameStr(fpgt->typname))); |
52 |
ReleaseSysCache(typeTup); |
53 |
@@ -588,14 +611,23 @@ pl_tuple_heap(VALUE c, VALUE tuple) |
54 |
MEMZERO(nulls, char, RARRAY_LEN(c)); |
55 |
for (i = 0; i < RARRAY_LEN(c); i++) { |
56 |
if (NIL_P(RARRAY_PTR(c)[i]) || |
57 |
+#if PG_VERSION_NUM < 110000 |
58 |
tupdesc->attrs[i]->attisdropped) { |
59 |
+#else |
60 |
+ tupdesc->attrs[i].attisdropped) { |
61 |
+#endif |
62 |
dvalues[i] = (Datum)0; |
63 |
nulls[i] = 'n'; |
64 |
} |
65 |
else { |
66 |
nulls[i] = ' '; |
67 |
+#if PG_VERSION_NUM < 110000 |
68 |
typid = tupdesc->attrs[i]->atttypid; |
69 |
if (tupdesc->attrs[i]->attndims != 0 || |
70 |
+#else |
71 |
+ typid = tupdesc->attrs[i].atttypid; |
72 |
+ if (tupdesc->attrs[i].attndims != 0 || |
73 |
+#endif |
74 |
tpl->att->attinfuncs[i].fn_addr == (PGFunction)array_in) { |
75 |
pl_proc_desc prodesc; |
76 |
FmgrInfo func; |
77 |
@@ -1088,6 +1120,7 @@ plruby_build_tuple(HeapTuple tuple, TupleDesc tupdesc, |
78 |
} |
79 |
|
80 |
for (i = 0; i < tupdesc->natts; i++) { |
81 |
+#if PG_VERSION_NUM < 110000 |
82 |
if (tupdesc->attrs[i]->attisdropped) |
83 |
continue; |
84 |
PLRUBY_BEGIN(1); |
85 |
@@ -1101,7 +1134,21 @@ plruby_build_tuple(HeapTuple tuple, TupleDesc tupdesc, |
86 |
rb_raise(pl_ePLruby, "Cache lookup for attribute '%s' type %ld failed", |
87 |
attname, OidGD(tupdesc->attrs[i]->atttypid)); |
88 |
} |
89 |
+#else |
90 |
+ if (tupdesc->attrs[i].attisdropped) |
91 |
+ continue; |
92 |
+ PLRUBY_BEGIN(1); |
93 |
+ attname = NameStr(tupdesc->attrs[i].attname); |
94 |
+ attr = heap_getattr(tuple, i + 1, tupdesc, &isnull); |
95 |
+ typeTup = SearchSysCache(TYPEOID, OidGD(tupdesc->attrs[i].atttypid), |
96 |
+ 0, 0, 0); |
97 |
+ PLRUBY_END; |
98 |
|
99 |
+ if (!HeapTupleIsValid(typeTup)) { |
100 |
+ rb_raise(pl_ePLruby, "Cache lookup for attribute '%s' type %ld failed", |
101 |
+ attname, OidGD(tupdesc->attrs[i].atttypid)); |
102 |
+ } |
103 |
+#endif |
104 |
fpgt = (Form_pg_type) GETSTRUCT(typeTup); |
105 |
typoutput = (Oid) (fpgt->typoutput); |
106 |
#if PG_PL_VERSION >= 75 |
107 |
@@ -1115,6 +1162,7 @@ plruby_build_tuple(HeapTuple tuple, TupleDesc tupdesc, |
108 |
int alen; |
109 |
|
110 |
typname = NameStr(fpgt->typname); |
111 |
+#if PG_VERSION_NUM < 110000 |
112 |
alen = tupdesc->attrs[i]->attlen; |
113 |
typeid = tupdesc->attrs[i]->atttypid; |
114 |
if (strcmp(typname, "text") == 0) { |
115 |
@@ -1129,6 +1177,22 @@ plruby_build_tuple(HeapTuple tuple, TupleDesc tupdesc, |
116 |
alen = tupdesc->attrs[i]->atttypmod - 4; |
117 |
} |
118 |
} |
119 |
+#else |
120 |
+ alen = tupdesc->attrs[i].attlen; |
121 |
+ typeid = tupdesc->attrs[i].atttypid; |
122 |
+ if (strcmp(typname, "text") == 0) { |
123 |
+ alen = -1; |
124 |
+ } |
125 |
+ else if (strcmp(typname, "bpchar") == 0 || |
126 |
+ strcmp(typname, "varchar") == 0) { |
127 |
+ if (tupdesc->attrs[i].atttypmod == -1) { |
128 |
+ alen = 0; |
129 |
+ } |
130 |
+ else { |
131 |
+ alen = tupdesc->attrs[i].atttypmod - 4; |
132 |
+ } |
133 |
+ } |
134 |
+#endif |
135 |
if ((type_ret & RET_DESC_ARR) == RET_DESC_ARR) { |
136 |
res = rb_ary_new(); |
137 |
rb_ary_push(res, rb_tainted_str_new2(attname)); |
138 |
@@ -1190,8 +1254,13 @@ plruby_build_tuple(HeapTuple tuple, TupleDesc tupdesc, |
139 |
|
140 |
fmgr_info(typoutput, &finfo); |
141 |
|
142 |
+#if PG_VERSION_NUM < 110000 |
143 |
s = pl_convert_arg(attr, tupdesc->attrs[i]->atttypid, |
144 |
&finfo, typelem,tupdesc->attrs[i]->attlen); |
145 |
+#else |
146 |
+ s = pl_convert_arg(attr, tupdesc->attrs[i].atttypid, |
147 |
+ &finfo, typelem,tupdesc->attrs[i].attlen); |
148 |
+#endif |
149 |
} |
150 |
PLRUBY_END_PROTECT; |
151 |
|