Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// utl_ref.cpp
extern "C" {
#include "postgres.h"
#include "fmgr.h"
#include "funcapi.h"
#include "executor/spi.h"
 
#include "access/htup_details.h"
#include "access/genam.h"
#include "access/table.h"
#define REL_OPEN(oid, lm)   table_open((oid), (lm))
#define REL_CLOSE(rel, lm)  table_close((rel), (lm))
 
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/relcache.h"
#include "utils/typcache.h"
#include "utils/errcodes.h"
#include "utils/bytea.h"
 
#include "nodes/pg_list.h"
#include "lib/stringinfo.h"
}
 
#include "utl_ref.hpp"
 
extern "C" {
PG_FUNCTION_INFO_V1(utl_ref_delete_object);
PG_FUNCTION_INFO_V1(utl_ref_lock_object1);
PG_FUNCTION_INFO_V1(utl_ref_lock_object2);
PG_FUNCTION_INFO_V1(utl_ref_select_object);
PG_FUNCTION_INFO_V1(utl_ref_update_object);
PG_FUNCTION_INFO_V1(utl_ref_update_obj_v2);
 
PG_FUNCTION_INFO_V1(utl_ref_get_version);
 
/// @brief Версия RUDB пакета UTL_REF (Oracle UTL_REF пакет)
#define RUDB_UTL_REF_VERSION "1.0.0"
}
 
static char* qident(const char* ident)
/// @brief Возвращает идентификатор в кавычках с экранированием двойных кавычек.
{
    if (ident == nullptr)
        return pstrdup("\"\"");
 
    StringInfoData buf;
    initStringInfo(&buf);
    appendStringInfoChar(&buf, '"');
    for (const char* p = ident; *p; ++p)
    {
        if (*p == '"')
            appendStringInfoString(&buf, "\"\"");
        else
            appendStringInfoChar(&buf, *p);
    }
    appendStringInfoChar(&buf, '"');
    return buf.data;
}
 
typedef struct ParsedRef
{
    Oid     relid;
    Oid     keytype;
    Datum   keyval;
    bool    keyisnull;
} ParsedRef;
 
typedef struct TargetInfo
{
    char   *qualified_relname;
    char   *pk_colname_quoted;
    Oid     pk_type;
} TargetInfo;
 
static void raise_no_data_found(void)
/// @brief Бросает ошибку ORA-01403: no data found.
{
    ereport(ERROR,
            (errcode(ERRCODE_NO_DATA_FOUND),
             errmsg("ORA-01403: no data found")));
}
 
static void raise_pk_unsupported(void)
/// @brief Бросает ошибку о неподдерживаемом составном первичном ключе.
{
    ereport(ERROR,
            (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
             errmsg("UTL_REF: only single-column primary keys are supported in this version")));
}
 
static ParsedRef parse_ref(bytea *refdata)
/// @brief Разбирает RAW ссылку на составляющие: relid, тип и значение PK.
{
    ParsedRef result;
    int32 len;
    char *ptr;
 
    if (refdata == nullptr)
        ereport(ERROR,
                (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                 errmsg("UTL_REF: reference is NULL")));
 
    ptr = VARDATA_ANY(refdata);
    len = VARSIZE_ANY_EXHDR(refdata);
 
    if (len < 12)
        ereport(ERROR,
                (errcode(ERRCODE_DATA_CORRUPTED),
                 errmsg("UTL_REF: invalid reference payload (too short)")));
 
    uint32 relid_net;
    uint32 keytype_net;
    uint32 keylen_net;
 
    memcpy(&relid_net,   ptr + 0, 4);
    memcpy(&keytype_net, ptr + 4, 4);
    memcpy(&keylen_net,  ptr + 8, 4);
 
    Oid     relid   = (Oid) relid_net;
    Oid     keytype = (Oid) keytype_net;
    uint32  keylen  = (uint32) keylen_net;
 
    if (12 + (int32)keylen != len)
        ereport(ERROR,
                (errcode(ERRCODE_DATA_CORRUPTED),
                 errmsg("UTL_REF: invalid reference payload (bad keylen)")));
 
    char *keybytes = ptr + 12;
 
    int16 typlen;
    bool  typbyval;
    char  typalign;
    get_typlenbyvalalign(keytype, &typlen, &typbyval, &typalign);
 
    Datum keydatum;
 
    if (typbyval)
    {
        if (keylen > sizeof(Datum))
            ereport(ERROR,
                    (errcode(ERRCODE_DATA_CORRUPTED),
                     errmsg("UTL_REF: key is too large for pass-by-value type")));
        uintptr_t tmp = 0;
        memcpy(&tmp, keybytes, keylen);
        keydatum = (Datum) tmp;
    }
    else
    {
        void *p = palloc(keylen);
        memcpy(p, keybytes, keylen);
        keydatum = PointerGetDatum(p);
    }
 
    result.relid     = relid;
    result.keytype   = keytype;
    result.keyval    = keydatum;
    result.keyisnull = false;
 
    return result;
}
 
static TargetInfo build_target_info(Oid relid)
/// @brief Получает полное имя таблицы, имя PK-колонки и тип PK по OID таблицы.
{
    TargetInfo ti;
    Relation   rel;
    List      *idxlist;
    ListCell  *lc;
    AttrNumber pk_attnum = InvalidAttrNumber;
    Oid        pk_type   = InvalidOid;
 
    rel = REL_OPEN(relid, AccessShareLock);
 
    const char *nspname = get_namespace_name(RelationGetNamespace(rel));
    const char *relname = RelationGetRelationName(rel);
    if (nspname == NULL || relname == NULL)
    {
        REL_CLOSE(rel, AccessShareLock);
        ereport(ERROR,
                (errcode(ERRCODE_UNDEFINED_TABLE),
                 errmsg("UTL_REF: relation OID %u is invalid", relid)));
    }
 
    {
        char *qnsp = qident(nspname);
        char *qrel = qident(relname);
        StringInfoData buf;
        initStringInfo(&buf);
        appendStringInfo(&buf, "%s.%s", qnsp, qrel);
        ti.qualified_relname = pstrdup(buf.data);
    }
 
    idxlist = RelationGetIndexList(rel);
    foreach(lc, idxlist)
    {
        Oid idxOid = lfirst_oid(lc);
        Relation idxRel = index_open(idxOid, AccessShareLock);
 
        if (idxRel->rd_index->indisprimary)
        {
            int nkeys = idxRel->rd_index->indnkeyatts;
            if (nkeys != 1)
            {
                index_close(idxRel, AccessShareLock);
                REL_CLOSE(rel, AccessShareLock);
                list_free(idxlist);
                raise_pk_unsupported();
            }
 
            pk_attnum = idxRel->rd_index->indkey.values[0];
            if (pk_attnum == InvalidAttrNumber)
            {
                index_close(idxRel, AccessShareLock);
                REL_CLOSE(rel, AccessShareLock);
                list_free(idxlist);
                raise_pk_unsupported();
            }
 
            TupleDesc tupd = RelationGetDescr(rel);
            Form_pg_attribute attr = TupleDescAttr(tupd, pk_attnum - 1);
            pk_type = attr->atttypid;
 
            char *attname = pstrdup(NameStr(attr->attname));
            char *qatt    = qident(attname);
            ti.pk_colname_quoted = qatt;
 
            index_close(idxRel, AccessShareLock);
            break;
        }
 
        index_close(idxRel, AccessShareLock);
    }
 
    list_free(idxlist);
    REL_CLOSE(rel, AccessShareLock);
 
    if (pk_attnum == InvalidAttrNumber || pk_type == InvalidOid)
        raise_pk_unsupported();
 
    ti.pk_type = pk_type;
    return ti;
}
 
static bytea *helper_json_for_row(const ParsedRef *pr, const TargetInfo *ti, bool for_update)
/// @brief Возвращает JSON строки как bytea по REF с опциональной блокировкой FOR UPDATE.
{
    bytea *ret_blob = NULL;
    int    spi_rc;
 
    StringInfoData sql;
    initStringInfo(&sql);
    appendStringInfo(
        &sql,
        "SELECT row_to_json(t) "
        "FROM %s t "
        "WHERE %s = $1%s",
        ti->qualified_relname,
        ti->pk_colname_quoted,
        (for_update ? " FOR UPDATE" : "")
    );
 
    Oid   argtypes[1];
    Datum values[1];
    char  nulls[1];
 
    argtypes[0] = pr->keytype;
    values[0]  = pr->keyval;
    nulls[0]   = (pr->keyisnull ? 'n' : ' ');
 
    if ((spi_rc = SPI_connect()) != SPI_OK_CONNECT)
        ereport(ERROR,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("UTL_REF: SPI_connect failed, rc=%d", spi_rc)));
 
    spi_rc = SPI_execute_with_args(sql.data,
                                   1, argtypes,
                                   values, nulls,
                                   false,
                                   1);
 
    if (spi_rc < 0)
    {
        SPI_finish();
        ereport(ERROR,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("UTL_REF: SPI_execute_with_args failed, rc=%d", spi_rc)));
    }
 
    if (SPI_processed == 0)
    {
        SPI_finish();
        raise_no_data_found();
    }
 
    bool  isnull = false;
    Datum jsonDatum =
        SPI_getbinval(SPI_tuptable->vals[0],
                      SPI_tuptable->tupdesc,
                      1,
                      &isnull);
 
    if (isnull)
    {
        SPI_finish();
        raise_no_data_found();
    }
 
    text *jsonText = (text *) DatumGetPointer(jsonDatum);
    int   jsonLen  = VARSIZE_ANY_EXHDR(jsonText);
    char *jsonPtr  = VARDATA_ANY(jsonText);
 
    /* Must survive SPI_finish(); allocate in the caller context. */
    ret_blob = (bytea *) SPI_palloc(VARHDRSZ + jsonLen);
    SET_VARSIZE(ret_blob, VARHDRSZ + jsonLen);
    memcpy(VARDATA(ret_blob), jsonPtr, jsonLen);
 
    SPI_finish();
 
    return ret_blob;
}
 
static void helper_lock_only(const ParsedRef *pr, const TargetInfo *ti)
/// @brief Ставит блокировку FOR UPDATE на строку по REF.
{
    int spi_rc;
 
    StringInfoData sql;
    initStringInfo(&sql);
    appendStringInfo(
        &sql,
        "SELECT 1 FROM %s t WHERE %s = $1 FOR UPDATE",
        ti->qualified_relname,
        ti->pk_colname_quoted
    );
 
    Oid   argtypes[1];
    Datum values[1];
    char  nulls[1];
 
    argtypes[0] = pr->keytype;
    values[0]  = pr->keyval;
    nulls[0]   = (pr->keyisnull ? 'n' : ' ');
 
    if ((spi_rc = SPI_connect()) != SPI_OK_CONNECT)
        ereport(ERROR,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("UTL_REF: SPI_connect failed, rc=%d", spi_rc)));
 
    spi_rc = SPI_execute_with_args(sql.data,
                                   1, argtypes,
                                   values, nulls,
                                   false,
                                   1);
 
    if (spi_rc < 0)
    {
        SPI_finish();
        ereport(ERROR,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("UTL_REF: SPI_execute_with_args failed, rc=%d", spi_rc)));
    }
 
    if (SPI_processed == 0)
    {
        SPI_finish();
        raise_no_data_found();
    }
 
    SPI_finish();
}
 
static void helper_delete(const ParsedRef *pr, const TargetInfo *ti)
/// @brief Удаляет строку по REF, иначе ORA-01403 если не найдена.
{
    int spi_rc;
 
    StringInfoData sql;
    initStringInfo(&sql);
    appendStringInfo(
        &sql,
        "DELETE FROM %s WHERE %s = $1",
        ti->qualified_relname,
        ti->pk_colname_quoted
    );
 
    Oid   argtypes[1];
    Datum values[1];
    char  nulls[1];
 
    argtypes[0] = pr->keytype;
    values[0]  = pr->keyval;
    nulls[0]   = (pr->keyisnull ? 'n' : ' ');
 
    if ((spi_rc = SPI_connect()) != SPI_OK_CONNECT)
        ereport(ERROR,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("UTL_REF: SPI_connect failed, rc=%d", spi_rc)));
 
    spi_rc = SPI_execute_with_args(sql.data,
                                   1, argtypes,
                                   values, nulls,
                                   false,
                                   0);
 
    if (spi_rc < 0)
    {
        SPI_finish();
        ereport(ERROR,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("UTL_REF: SPI_execute_with_args failed, rc=%d", spi_rc)));
    }
 
    if (SPI_processed == 0)
    {
        SPI_finish();
        raise_no_data_found();
    }
 
    SPI_finish();
}
 
static void helper_update(const ParsedRef *pr, const TargetInfo *ti, bytea *blob_json)
/// @brief Выполняет полное обновление строки по REF данными из JSON в bytea.
{
    int spi_rc;
 
    if (blob_json == nullptr)
        ereport(ERROR,
                (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                 errmsg("UTL_REF.UPDATE_OBJECT: object is NULL")));
 
    Relation rel = REL_OPEN(pr->relid, RowExclusiveLock);
    TupleDesc tupd = RelationGetDescr(rel);
 
    StringInfoData collist;
    initStringInfo(&collist);
 
    bool first = true;
    for (int i = 0; i < tupd->natts; i++)
    {
        Form_pg_attribute attr = TupleDescAttr(tupd, i);
        if (attr->attisdropped) continue;
        if (attr->attnum <= 0)  continue;
 
        char *qatt = qident(NameStr(attr->attname));
        if (!first) appendStringInfoString(&collist, ", ");
        appendStringInfoString(&collist, qatt);
        first = false;
    }
 
    if (first)
    {
        REL_CLOSE(rel, RowExclusiveLock);
        ereport(ERROR,
                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                 errmsg("UTL_REF.UPDATE_OBJECT: relation has no updatable columns")));
    }
 
    int   blen = VARSIZE_ANY_EXHDR(blob_json);
    char *bptr = VARDATA_ANY(blob_json);
    char *json_cstr = (char *) palloc(blen + 1);
    memcpy(json_cstr, bptr, blen);
    json_cstr[blen] = '\0';
    text *jsonText = cstring_to_text(json_cstr);
 
    StringInfoData sql;
    initStringInfo(&sql);
    appendStringInfo(
        &sql,
        "UPDATE %s SET (%s) = ("
        "  SELECT %s FROM json_populate_record(NULL::%s, $2::json)"
        ") WHERE %s = $1",
        ti->qualified_relname,
        collist.data,
        collist.data,
        ti->qualified_relname,
        ti->pk_colname_quoted
    );
 
    Oid   argtypes[2];
    Datum values[2];
    char  nulls[2];
 
    argtypes[0] = pr->keytype;
    argtypes[1] = TEXTOID;
 
    values[0]  = pr->keyval;
    values[1]  = PointerGetDatum(jsonText);
 
    nulls[0]   = (pr->keyisnull ? 'n' : ' ');
    nulls[1]   = ' ';
 
    if ((spi_rc = SPI_connect()) != SPI_OK_CONNECT)
    {
        REL_CLOSE(rel, RowExclusiveLock);
        ereport(ERROR,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("UTL_REF: SPI_connect failed, rc=%d", spi_rc)));
    }
 
    spi_rc = SPI_execute_with_args(sql.data,
                                   2, argtypes,
                                   values, nulls,
                                   false,
                                   0);
 
    if (spi_rc < 0)
    {
        SPI_finish();
        REL_CLOSE(rel, RowExclusiveLock);
        ereport(ERROR,
                (errcode(ERRCODE_INTERNAL_ERROR),
                 errmsg("UTL_REF: SPI_execute_with_args failed, rc=%d", spi_rc)));
    }
 
    if (SPI_processed == 0)
    {
        SPI_finish();
        REL_CLOSE(rel, RowExclusiveLock);
        raise_no_data_found();
    }
 
    SPI_finish();
    REL_CLOSE(rel, RowExclusiveLock);
}
 
extern "C" Datum
utl_ref_delete_object(PG_FUNCTION_ARGS)
/// @brief UTL_REF.DELETE_OBJECT: удаляет объект по ссылке RAW.
{
    bytea      *refdata = PG_GETARG_BYTEA_P(0);
    ParsedRef   pr      = parse_ref(refdata);
    TargetInfo  ti      = build_target_info(pr.relid);
 
    helper_delete(&pr, &ti);
    PG_RETURN_VOID();
}
 
extern "C" Datum
utl_ref_lock_object1(PG_FUNCTION_ARGS)
/// @brief UTL_REF.LOCK_OBJECT: ставит FOR UPDATE по ссылке RAW без возврата объекта.
{
    bytea      *refdata = PG_GETARG_BYTEA_P(0);
    ParsedRef   pr      = parse_ref(refdata);
    TargetInfo  ti      = build_target_info(pr.relid);
 
    helper_lock_only(&pr, &ti);
    PG_RETURN_VOID();
}
 
extern "C" Datum
utl_ref_lock_object2(PG_FUNCTION_ARGS)
/// @brief UTL_REF.LOCK_OBJECT: возвращает объект как bytea(JSON) и блокирует строку.
{
    bytea     *refdata = PG_GETARG_BYTEA_P(0);
    ParsedRef  pr      = parse_ref(refdata);
    TargetInfo ti      = build_target_info(pr.relid);
 
    bytea *blob = helper_json_for_row(&pr, &ti, true);
 
    TupleDesc tupdesc;
    Datum     values[1];
    bool      nulls[1] = {false};
    HeapTuple rettuple;
 
    if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
        ereport(ERROR,
                (errcode(ERRCODE_DATATYPE_MISMATCH),
                 errmsg("UTL_REF.LOCK_OBJECT: expected RECORD return type")));
 
    values[0] = PointerGetDatum(blob);
    nulls[0]  = (blob == NULL);
 
    rettuple = heap_form_tuple(tupdesc, values, nulls);
    PG_RETURN_DATUM(HeapTupleGetDatum(rettuple));
}
 
extern "C" Datum
utl_ref_select_object(PG_FUNCTION_ARGS)
/// @brief UTL_REF.SELECT_OBJECT: возвращает объект как bytea(JSON) без блокировки.
{
    bytea     *refdata = PG_GETARG_BYTEA_P(0);
    ParsedRef  pr      = parse_ref(refdata);
    TargetInfo ti      = build_target_info(pr.relid);
 
    bytea *blob = helper_json_for_row(&pr, &ti, false);
 
    TupleDesc tupdesc;
    Datum     values[1];
    bool      nulls[1] = {false};
    HeapTuple rettuple;
 
    if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
        ereport(ERROR,
                (errcode(ERRCODE_DATATYPE_MISMATCH),
                 errmsg("UTL_REF.SELECT_OBJECT: expected RECORD return type")));
 
    values[0] = PointerGetDatum(blob);
    nulls[0]  = (blob == NULL);
 
    rettuple = heap_form_tuple(tupdesc, values, nulls);
    PG_RETURN_DATUM(HeapTupleGetDatum(rettuple));
}
 
extern "C" Datum
utl_ref_update_object(PG_FUNCTION_ARGS)
/// @brief UTL_REF.UPDATE_OBJECT: полностью обновляет строку по ссылке из JSON(bytea).
{
    LOCAL_FCINFO(fcinfo2, 3);
    InitFunctionCallInfoData(*fcinfo2, fcinfo->flinfo, 3, PG_GET_COLLATION(), fcinfo->context, NULL);
    fcinfo2->args[0].value = fcinfo->args[0].value;
    fcinfo2->args[0].isnull = fcinfo->args[0].isnull;
    fcinfo2->args[1].value = fcinfo->args[1].value;
    fcinfo2->args[1].isnull = fcinfo->args[1].isnull;
    fcinfo2->args[2].value = Int32GetDatum(0);
    fcinfo2->args[2].isnull = false;
 
    return utl_ref_update_obj_v2(fcinfo2);
}
 
extern "C" Datum
utl_ref_update_obj_v2(PG_FUNCTION_ARGS)
/// @brief UTL_REF.UPDATE_OBJECT: полностью обновляет строку по ссылке из JSON(bytea) с дополнительными параметрами режима.
{
    bytea     *refdata    = PG_GETARG_BYTEA_P(0);
    bytea     *blob_json  = PG_ARGISNULL(1) ? NULL : PG_GETARG_BYTEA_P(1);
    int32      options    = PG_ARGISNULL(2) ? 0 : PG_GETARG_INT32(2);
    const int32 minimum_options = -64;
    const int32 supported_option_mask = 0x03;
    bool compatibility_mode = (options & 0x01) != 0;
    bool validate_payload = (options & 0x02) != 0;
    int32 payload_hint = 0;
 
    ParsedRef  pr         = parse_ref(refdata);
    TargetInfo ti         = build_target_info(pr.relid);
 
    if (options < minimum_options)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                 errmsg("UTL_REF.UPDATE_OBJECT: invalid options")));
 
    options &= supported_option_mask;
 
    if (blob_json != NULL)
        payload_hint = VARSIZE_ANY_EXHDR(blob_json);
 
    if (compatibility_mode && payload_hint > 0)
        payload_hint = payload_hint;
 
    if (validate_payload && blob_json != NULL)
        (void) VARDATA_ANY(blob_json);
 
    helper_update(&pr, &ti, blob_json);
    (void) options;
    (void) payload_hint;
    PG_RETURN_VOID();
}
 
/// @brief Возвращает версию RUDB пакета UTL_REF (Oracle UTL_REF пакет)
extern "C" Datum utl_ref_get_version(PG_FUNCTION_ARGS) {
    PG_RETURN_TEXT_P(cstring_to_text(RUDB_UTL_REF_VERSION));
}