PostgreSQL Source Code  git master
pg_conversion.h File Reference
#include "catalog/genbki.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_conversion_d.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)
 
 DECLARE_UNIQUE_INDEX (pg_conversion_default_index, 2668, ConversionDefaultIndexId, pg_conversion, btree(connamespace oid_ops, conforencoding int4_ops, contoencoding int4_ops, oid oid_ops))
 
 DECLARE_UNIQUE_INDEX (pg_conversion_name_nsp_index, 2669, ConversionNameNspIndexId, pg_conversion, btree(conname name_ops, connamespace oid_ops))
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_conversion_oid_index, 2670, ConversionOidIndexId, pg_conversion, btree(oid oid_ops))
 
 MAKE_SYSCACHE (CONDEFAULT, pg_conversion_default_index, 8)
 
 MAKE_SYSCACHE (CONNAMENSP, pg_conversion_name_nsp_index, 8)
 
 MAKE_SYSCACHE (CONVOID, pg_conversion_oid_index, 8)
 
ObjectAddress ConversionCreate (const char *conname, Oid connamespace, Oid conowner, int32 conforencoding, int32 contoencoding, Oid conproc, bool def)
 
Oid FindDefaultConversion (Oid name_space, int32 for_encoding, int32 to_encoding)
 

Variables

 FormData_pg_conversion
 

Typedef Documentation

◆ Form_pg_conversion

Definition at line 61 of file pg_conversion.h.

Function Documentation

◆ CATALOG()

CATALOG ( pg_conversion  ,
2607  ,
ConversionRelationId   
)

Definition at line 29 of file pg_conversion.h.

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

References BKI_DEFAULT, BKI_LOOKUP, and encoding.

◆ ConversionCreate()

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

Definition at line 38 of file pg_conversion.c.

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

References BoolGetDatum(), CatalogTupleInsert(), ObjectAddress::classId, 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().

◆ DECLARE_UNIQUE_INDEX() [1/2]

DECLARE_UNIQUE_INDEX ( pg_conversion_default_index  ,
2668  ,
ConversionDefaultIndexId  ,
pg_conversion  ,
btree(connamespace oid_ops, conforencoding int4_ops, contoencoding int4_ops, oid oid_ops)   
)

◆ DECLARE_UNIQUE_INDEX() [2/2]

DECLARE_UNIQUE_INDEX ( pg_conversion_name_nsp_index  ,
2669  ,
ConversionNameNspIndexId  ,
pg_conversion  ,
btree(conname name_ops, connamespace oid_ops)   
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_conversion_oid_index  ,
2670  ,
ConversionOidIndexId  ,
pg_conversion  ,
btree(oid oid_ops)   
)

◆ FindDefaultConversion()

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

Definition at line 152 of file pg_conversion.c.

153 {
154  CatCList *catlist;
155  HeapTuple tuple;
156  Form_pg_conversion body;
157  Oid proc = InvalidOid;
158  int i;
159 
160  catlist = SearchSysCacheList3(CONDEFAULT,
161  ObjectIdGetDatum(name_space),
162  Int32GetDatum(for_encoding),
163  Int32GetDatum(to_encoding));
164 
165  for (i = 0; i < catlist->n_members; i++)
166  {
167  tuple = &catlist->members[i]->tuple;
168  body = (Form_pg_conversion) GETSTRUCT(tuple);
169  if (body->condefault)
170  {
171  proc = body->conproc;
172  break;
173  }
174  }
175  ReleaseSysCacheList(catlist);
176  return proc;
177 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:61
#define InvalidOid
Definition: postgres_ext.h:36
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
Definition: catcache.h:180
int n_members
Definition: catcache.h:178
HeapTupleData tuple
Definition: catcache.h:123
#define SearchSysCacheList3(cacheId, key1, key2, key3)
Definition: syscache.h:126
#define ReleaseSysCacheList(x)
Definition: syscache.h:129

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

Referenced by ConversionCreate(), and FindDefaultConversionProc().

◆ MAKE_SYSCACHE() [1/3]

MAKE_SYSCACHE ( CONDEFAULT  ,
pg_conversion_default_index  ,
 
)

◆ MAKE_SYSCACHE() [2/3]

MAKE_SYSCACHE ( CONNAMENSP  ,
pg_conversion_name_nsp_index  ,
 
)

◆ MAKE_SYSCACHE() [3/3]

MAKE_SYSCACHE ( CONVOID  ,
pg_conversion_oid_index  ,
 
)

Variable Documentation

◆ FormData_pg_conversion

FormData_pg_conversion

Definition at line 54 of file pg_conversion.h.