diff options
author | Heikki Linnakangas | 2009-02-27 16:35:26 +0000 |
---|---|---|
committer | Heikki Linnakangas | 2009-02-27 16:35:26 +0000 |
commit | cbe3dc9fc260d86abcfb15551b836ec32957a4c2 (patch) | |
tree | dc3b64413d0b7c98d0003ae562a1b180a2de164e | |
parent | df527055d01d04894ce98e45e842695d0a27643e (diff) |
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.
-rw-r--r-- | src/backend/commands/conversioncmds.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c index f067da2983..b716dd8e4f 100644 --- a/src/backend/commands/conversioncmds.c +++ b/src/backend/commands/conversioncmds.c @@ -49,6 +49,7 @@ CreateConversionCommand(CreateConversionStmt *stmt) const char *to_encoding_name = stmt->to_encoding_name; List *func_name = stmt->func_name; static Oid funcargs[] = {INT4OID, INT4OID, CSTRINGOID, INTERNALOID, INT4OID}; + char result[1]; /* Convert list of names to a name and namespace */ namespaceId = QualifiedNameGetCreationNamespace(stmt->conversion_name, @@ -96,6 +97,19 @@ CreateConversionCommand(CreateConversionStmt *stmt) NameListToString(func_name)); /* + * Check that the conversion function is suitable for the requested + * source and target encodings. We do that by calling the function with + * an empty string; the conversion function should throw an error if it + * can't perform the requested conversion. + */ + OidFunctionCall5(funcoid, + Int32GetDatum(from_encoding), + Int32GetDatum(to_encoding), + CStringGetDatum(""), + CStringGetDatum(result), + Int32GetDatum(0)); + + /* * All seem ok, go ahead (possible failure would be a duplicate conversion * name) */ |