aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/conversioncmds.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-02-27 16:35:26 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-02-27 16:35:26 +0000
commit5c4ca3b6321794ab95487a6a6ebc23af150bf9e9 (patch)
treecc2fce1ee6337f3f0dae5bfe98b6145d25a29c8c /src/backend/commands/conversioncmds.c
parent92fc8b41e51425773a8947bd9da5cd671a83d238 (diff)
downloadpostgresql-5c4ca3b6321794ab95487a6a6ebc23af150bf9e9.tar.gz
postgresql-5c4ca3b6321794ab95487a6a6ebc23af150bf9e9.zip
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.
Diffstat (limited to 'src/backend/commands/conversioncmds.c')
-rw-r--r--src/backend/commands/conversioncmds.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c
index a02b98f73d7..13c55d51bff 100644
--- a/src/backend/commands/conversioncmds.c
+++ b/src/backend/commands/conversioncmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.37 2009/01/01 17:23:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.38 2009/02/27 16:35:26 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -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)
*/