33{
35 char *conversion_name;
37 int from_encoding;
38 int to_encoding;
40 const char *from_encoding_name =
stmt->for_encoding_name;
41 const char *to_encoding_name =
stmt->to_encoding_name;
43 static const Oid funcargs[] = {INT4OID, INT4OID, CSTRINGOID, INTERNALOID, INT4OID, BOOLOID};
44 char result[1];
46
47 /* Convert list of names to a name and namespace */
49 &conversion_name);
50
51 /* Check we have creation rights in target namespace */
56
57 /* Check the encoding names */
59 if (from_encoding < 0)
61 (
errcode(ERRCODE_UNDEFINED_OBJECT),
62 errmsg(
"source encoding \"%s\" does not exist",
63 from_encoding_name)));
64
66 if (to_encoding < 0)
68 (
errcode(ERRCODE_UNDEFINED_OBJECT),
69 errmsg(
"destination encoding \"%s\" does not exist",
70 to_encoding_name)));
71
72 /*
73 * We consider conversions to or from SQL_ASCII to be meaningless. (If
74 * you wish to change this, note that pg_do_encoding_conversion() and its
75 * sister functions have hard-wired fast paths for any conversion in which
76 * the source or target encoding is SQL_ASCII, so that an encoding
77 * conversion function declared for such a case will never be used.)
78 */
81 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
82 errmsg(
"encoding conversion to or from \"SQL_ASCII\" is not supported")));
83
84 /*
85 * Check the existence of the conversion function. Function name could be
86 * a qualified name.
87 */
89 funcargs, false);
90
91 /* Check it returns int4, else it's probably the wrong function */
94 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
95 errmsg(
"encoding conversion function %s must return type %s",
97
98 /* Check we have EXECUTE rights for the function */
103
104 /*
105 * Check that the conversion function is suitable for the requested source
106 * and target encodings. We do that by calling the function with an empty
107 * string; the conversion function should throw an error if it can't
108 * perform the requested conversion.
109 */
117
118 /*
119 * The function should return 0 for empty input. Might as well check that,
120 * too.
121 */
124 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
125 errmsg(
"encoding conversion function %s returned incorrect result for empty input",
127
128 /*
129 * All seem ok, go ahead (possible failure would be a duplicate conversion
130 * name)
131 */
133 from_encoding, to_encoding, funcoid,
stmt->def);
134}
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define OidFunctionCall6(functionId, arg1, arg2, arg3, arg4, arg5, arg6)
char * get_namespace_name(Oid nspid)
Oid get_func_rettype(Oid funcid)
char * NameListToString(const List *names)
Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
ObjectAddress ConversionCreate(const char *conname, Oid connamespace, Oid conowner, int32 conforencoding, int32 contoencoding, Oid conproc, bool def)
#define pg_char_to_encoding
static Datum BoolGetDatum(bool X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)