Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5c4ca3b

Browse files
committed
In CREATE CONVERSION, test that the given function is a valid conversion
function for the specified source and destination encodings. We do that by calling the function with an empty string. If it can't perform the requested conversion, it will throw an error. Backport to 7.4 - 8.3. Per bug report #4680 by Denis Afonin.
1 parent 92fc8b4 commit 5c4ca3b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/backend/commands/conversioncmds.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.37 2009/01/01 17:23:37 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.38 2009/02/27 16:35:26 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -49,6 +49,7 @@ CreateConversionCommand(CreateConversionStmt *stmt)
4949
const char *to_encoding_name = stmt->to_encoding_name;
5050
List *func_name = stmt->func_name;
5151
static Oid funcargs[] = {INT4OID, INT4OID, CSTRINGOID, INTERNALOID, INT4OID};
52+
char result[1];
5253

5354
/* Convert list of names to a name and namespace */
5455
namespaceId = QualifiedNameGetCreationNamespace(stmt->conversion_name,
@@ -95,6 +96,19 @@ CreateConversionCommand(CreateConversionStmt *stmt)
9596
aclcheck_error(aclresult, ACL_KIND_PROC,
9697
NameListToString(func_name));
9798

99+
/*
100+
* Check that the conversion function is suitable for the requested
101+
* source and target encodings. We do that by calling the function with
102+
* an empty string; the conversion function should throw an error if it
103+
* can't perform the requested conversion.
104+
*/
105+
OidFunctionCall5(funcoid,
106+
Int32GetDatum(from_encoding),
107+
Int32GetDatum(to_encoding),
108+
CStringGetDatum(""),
109+
CStringGetDatum(result),
110+
Int32GetDatum(0));
111+
98112
/*
99113
* All seem ok, go ahead (possible failure would be a duplicate conversion
100114
* name)

0 commit comments

Comments
 (0)