PostgreSQL Source Code  git master
pg_conversion.h File Reference
#include "catalog/genbki.h"
#include "catalog/pg_conversion_d.h"
#include "catalog/objectaddress.h"
Include dependency graph for pg_conversion.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef FormData_pg_conversionForm_pg_conversion
 

Functions

 CATALOG (pg_conversion, 2607, ConversionRelationId)
 
ObjectAddress ConversionCreate (const char *conname, Oid connamespace, Oid conowner, int32 conforencoding, int32 contoencoding, Oid conproc, bool def)
 
void RemoveConversionById (Oid conversionOid)
 
Oid FindDefaultConversion (Oid connamespace, int32 for_encoding, int32 to_encoding)
 

Variables

 FormData_pg_conversion
 

Typedef Documentation

◆ Form_pg_conversion

Definition at line 62 of file pg_conversion.h.

Function Documentation

◆ CATALOG()

CATALOG ( pg_conversion  ,
2607  ,
ConversionRelationId   
)

Definition at line 30 of file pg_conversion.h.

References BKI_DEFAULT, BKI_LOOKUP, and encoding.

31 {
32  /* oid */
33  Oid oid;
34 
35  /* name of the conversion */
36  NameData conname;
37 
38  /* namespace that the conversion belongs to */
39  Oid connamespace BKI_DEFAULT(PGNSP);
40 
41  /* owner of the conversion */
42  Oid conowner BKI_DEFAULT(PGUID);
43 
44  /* FOR encoding id */
45  int32 conforencoding BKI_LOOKUP(encoding);
46 
47  /* TO encoding id */
48  int32 contoencoding BKI_LOOKUP(encoding);
49 
50  /* OID of the conversion proc */
51  regproc conproc BKI_LOOKUP(pg_proc);
52 
53  /* true if this is a default conversion */
54  bool condefault BKI_DEFAULT(t);
FormData_pg_conversion
Definition: pg_conversion.h:55
unsigned int Oid
Definition: postgres_ext.h:31
#define BKI_DEFAULT(value)
Definition: genbki.h:35
signed int int32
Definition: c.h:346
Definition: c.h:603
#define BKI_LOOKUP(catalog)
Definition: genbki.h:42
int32 encoding
Definition: pg_database.h:41
Oid regproc
Definition: c.h:504

◆ ConversionCreate()

ObjectAddress ConversionCreate ( const char *  conname,
Oid  connamespace,
Oid  conowner,
int32  conforencoding,
int32  contoencoding,
Oid  conproc,
bool  def 
)

Definition at line 41 of file pg_conversion.c.

References BoolGetDatum, CatalogTupleInsert(), ObjectAddress::classId, CONNAMENSP, ConversionOidIndexId, DEPENDENCY_NORMAL, elog, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, FindDefaultConversion(), GetNewOidWithIndex(), heap_form_tuple(), heap_freetuple(), i, Int32GetDatum, InvokeObjectPostCreateHook, NameGetDatum, namestrcpy(), ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, pg_encoding_to_char(), PointerGetDatum, RelationData::rd_att, recordDependencyOn(), recordDependencyOnCurrentExtension(), recordDependencyOnOwner(), RowExclusiveLock, SearchSysCacheExists2, table_close(), table_open(), and values.

Referenced by CreateConversionCommand().

45 {
46  int i;
47  Relation rel;
48  TupleDesc tupDesc;
49  HeapTuple tup;
50  Oid oid;
51  bool nulls[Natts_pg_conversion];
52  Datum values[Natts_pg_conversion];
54  ObjectAddress myself,
55  referenced;
56 
57  /* sanity checks */
58  if (!conname)
59  elog(ERROR, "no conversion name supplied");
60 
61  /* make sure there is no existing conversion of same name */
63  PointerGetDatum(conname),
64  ObjectIdGetDatum(connamespace)))
65  ereport(ERROR,
67  errmsg("conversion \"%s\" already exists", conname)));
68 
69  if (def)
70  {
71  /*
72  * make sure there is no existing default <for encoding><to encoding>
73  * pair in this name space
74  */
75  if (FindDefaultConversion(connamespace,
76  conforencoding,
77  contoencoding))
78  ereport(ERROR,
80  errmsg("default conversion for %s to %s already exists",
81  pg_encoding_to_char(conforencoding),
82  pg_encoding_to_char(contoencoding))));
83  }
84 
85  /* open pg_conversion */
86  rel = table_open(ConversionRelationId, RowExclusiveLock);
87  tupDesc = rel->rd_att;
88 
89  /* initialize nulls and values */
90  for (i = 0; i < Natts_pg_conversion; i++)
91  {
92  nulls[i] = false;
93  values[i] = (Datum) NULL;
94  }
95 
96  /* form a tuple */
97  namestrcpy(&cname, conname);
99  Anum_pg_conversion_oid);
100  values[Anum_pg_conversion_oid - 1] = ObjectIdGetDatum(oid);
101  values[Anum_pg_conversion_conname - 1] = NameGetDatum(&cname);
102  values[Anum_pg_conversion_connamespace - 1] = ObjectIdGetDatum(connamespace);
103  values[Anum_pg_conversion_conowner - 1] = ObjectIdGetDatum(conowner);
104  values[Anum_pg_conversion_conforencoding - 1] = Int32GetDatum(conforencoding);
105  values[Anum_pg_conversion_contoencoding - 1] = Int32GetDatum(contoencoding);
106  values[Anum_pg_conversion_conproc - 1] = ObjectIdGetDatum(conproc);
107  values[Anum_pg_conversion_condefault - 1] = BoolGetDatum(def);
108 
109  tup = heap_form_tuple(tupDesc, values, nulls);
110 
111  /* insert a new tuple */
112  CatalogTupleInsert(rel, tup);
113 
114  myself.classId = ConversionRelationId;
115  myself.objectId = oid;
116  myself.objectSubId = 0;
117 
118  /* create dependency on conversion procedure */
119  referenced.classId = ProcedureRelationId;
120  referenced.objectId = conproc;
121  referenced.objectSubId = 0;
122  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
123 
124  /* create dependency on namespace */
125  referenced.classId = NamespaceRelationId;
126  referenced.objectId = connamespace;
127  referenced.objectSubId = 0;
128  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
129 
130  /* create dependency on owner */
131  recordDependencyOnOwner(ConversionRelationId, oid, conowner);
132 
133  /* dependency on extension */
134  recordDependencyOnCurrentExtension(&myself, false);
135 
136  /* Post creation hook for new conversion */
137  InvokeObjectPostCreateHook(ConversionRelationId, oid, 0);
138 
139  heap_freetuple(tup);
141 
142  return myself;
143 }
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:323
#define NameGetDatum(X)
Definition: postgres.h:595
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:145
#define PointerGetDatum(X)
Definition: postgres.h:556
int errcode(int sqlerrcode)
Definition: elog.c:570
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:43
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:165
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
int namestrcpy(Name name, const char *str)
Definition: name.c:250
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
Definition: c.h:603
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel, rest)
Definition: elog.h:141
uintptr_t Datum
Definition: postgres.h:367
TupleDesc rd_att
Definition: rel.h:84
#define BoolGetDatum(X)
Definition: postgres.h:402
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:607
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:138
#define ConversionOidIndexId
Definition: indexing.h:141
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition: syscache.h:185
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define Int32GetDatum(X)
Definition: postgres.h:479
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
int i
Oid FindDefaultConversion(Oid name_space, int32 for_encoding, int32 to_encoding)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:33
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:183

◆ FindDefaultConversion()

Oid FindDefaultConversion ( Oid  connamespace,
int32  for_encoding,
int32  to_encoding 
)

Definition at line 188 of file pg_conversion.c.

References CONDEFAULT, GETSTRUCT, i, Int32GetDatum, InvalidOid, catclist::members, catclist::n_members, ObjectIdGetDatum, ReleaseSysCacheList, SearchSysCacheList3, and catctup::tuple.

Referenced by ConversionCreate(), and FindDefaultConversionProc().

189 {
190  CatCList *catlist;
191  HeapTuple tuple;
192  Form_pg_conversion body;
193  Oid proc = InvalidOid;
194  int i;
195 
197  ObjectIdGetDatum(name_space),
198  Int32GetDatum(for_encoding),
199  Int32GetDatum(to_encoding));
200 
201  for (i = 0; i < catlist->n_members; i++)
202  {
203  tuple = &catlist->members[i]->tuple;
204  body = (Form_pg_conversion) GETSTRUCT(tuple);
205  if (body->condefault)
206  {
207  proc = body->conproc;
208  break;
209  }
210  }
211  ReleaseSysCacheList(catlist);
212  return proc;
213 }
int n_members
Definition: catcache.h:176
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
unsigned int Oid
Definition: postgres_ext.h:31
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
Definition: catcache.h:178
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ReleaseSysCacheList(x)
Definition: syscache.h:217
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:62
#define InvalidOid
Definition: postgres_ext.h:36
#define Int32GetDatum(X)
Definition: postgres.h:479
#define SearchSysCacheList3(cacheId, key1, key2, key3)
Definition: syscache.h:214
int i
HeapTupleData tuple
Definition: catcache.h:121

◆ RemoveConversionById()

void RemoveConversionById ( Oid  conversionOid)

Definition at line 152 of file pg_conversion.c.

References BTEqualStrategyNumber, CatalogTupleDelete(), elog, ERROR, ForwardScanDirection, heap_getnext(), HeapTupleIsValid, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), HeapTupleData::t_self, table_beginscan_catalog(), table_close(), table_endscan(), and table_open().

Referenced by doDeletion().

153 {
154  Relation rel;
155  HeapTuple tuple;
156  TableScanDesc scan;
157  ScanKeyData scanKeyData;
158 
159  ScanKeyInit(&scanKeyData,
160  Anum_pg_conversion_oid,
161  BTEqualStrategyNumber, F_OIDEQ,
162  ObjectIdGetDatum(conversionOid));
163 
164  /* open pg_conversion */
165  rel = table_open(ConversionRelationId, RowExclusiveLock);
166 
167  scan = table_beginscan_catalog(rel, 1, &scanKeyData);
168 
169  /* search for the target tuple */
171  CatalogTupleDelete(rel, &tuple->t_self);
172  else
173  elog(ERROR, "could not find tuple for conversion %u", conversionOid);
174  table_endscan(scan);
176 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:98
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:269
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1290
#define RowExclusiveLock
Definition: lockdefs.h:38
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:831
#define elog(elevel,...)
Definition: elog.h:226
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define BTEqualStrategyNumber
Definition: stratnum.h:31

Variable Documentation

◆ FormData_pg_conversion

FormData_pg_conversion

Definition at line 55 of file pg_conversion.h.