MCPcopy Create free account
hub / github.com/apache/cloudberry / orafce_replace_empty_strings

Function orafce_replace_empty_strings

gpcontrib/orafce/replace_empty_string.c:80–179  ·  view source on GitHub ↗

* Detects emty strings in type text based fields and replaces them by NULL. */

Source from the content-addressed store, hash-verified

78 * Detects emty strings in type text based fields and replaces them by NULL.
79 */
80Datum
81orafce_replace_empty_strings(PG_FUNCTION_ARGS)
82{
83 TriggerData *trigdata = (TriggerData *) fcinfo->context;
84 HeapTuple rettuple = NULL;
85 TupleDesc tupdesc;
86 int *resetcols = NULL;
87 Datum *values = NULL;
88 bool *nulls = NULL;
89 Oid prev_typid = InvalidOid;
90 bool is_string = false;
91 int nresetcols = 0;
92 int attnum;
93 bool raise_warning = false;
94 char *relname = NULL;
95
96 trigger_sanity_check(fcinfo, "replace_empty_strings");
97 raise_warning = should_raise_warnings(fcinfo);
98
99 rettuple = get_rettuple(fcinfo);
100 tupdesc = trigdata->tg_relation->rd_att;
101
102 /* iterate over record's fields */
103 for (attnum = 1; attnum <= tupdesc->natts; attnum++)
104 {
105 Oid typid;
106
107 /* simple cache - lot of time columns with same type is side by side */
108 typid = SPI_gettypeid(tupdesc, attnum);
109 if (typid != prev_typid)
110 {
111 TYPCATEGORY category;
112 bool ispreferred;
113 Oid base_typid;
114
115 base_typid = getBaseType(typid);
116 get_type_category_preferred(base_typid, &category, &ispreferred);
117
118 is_string = (category == TYPCATEGORY_STRING);
119 prev_typid = typid;
120 }
121
122 if (is_string)
123 {
124 Datum value;
125 bool isnull;
126
127 value = SPI_getbinval(rettuple, tupdesc, attnum, &isnull);
128 if (!isnull)
129 {
130 text *txt = DatumGetTextP(value);
131
132 /* is it empty string (has zero length */
133 if (VARSIZE_ANY_EXHDR(txt) == 0)
134 {
135 if (!resetcols)
136 {
137 /* lazy allocation of dynamic memory */

Callers

nothing calls this directly

Calls 12

trigger_sanity_checkFunction · 0.85
should_raise_warningsFunction · 0.85
get_rettupleFunction · 0.85
SPI_gettypeidFunction · 0.85
getBaseTypeFunction · 0.85
SPI_getbinvalFunction · 0.85
SPI_getrelnameFunction · 0.85
SPI_fnameFunction · 0.85
palloc0Function · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected