summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-02-27 16:35:53 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-02-27 16:35:53 +0000
commit17485e504d6d1c9c921e30d417002e2c281d4f42 (patch)
treeef29c4e6fa19f63cfc454ae2d711fd262cb87dc2
parentcedefbdf13a1e5ed4aa2e85600340200cc07b097 (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.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c
index 0aa8a8cae5c..f4af8c185d2 100644
--- a/src/backend/commands/conversioncmds.c
+++ b/src/backend/commands/conversioncmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/conversioncmds.c,v 1.11.4.1 2005/05/03 19:18:31 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/conversioncmds.c,v 1.11.4.2 2009/02/27 16:35:53 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -47,6 +47,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,
@@ -87,6 +88,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)
*/