postgres.git / summary / log / commit / refs
commit 64deed0dbad9c96842e541c5edd249c9fa9815bc
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Fri Feb 27 16:35:47 2009 +0000
First released in: 8.4.0, 7.4.25, 8.0.21, 8.1.17, 8.2.13, 8.3.7
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.
src/backend/commands/conversioncmds.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c
index 17f0859cce2..9e70a76fc64 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.16.4.1 2005/05/03 19:18:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.16.4.2 2009/02/27 16:35:47 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,
@@ -86,6 +87,19 @@ CreateConversionCommand(CreateConversionStmt *stmt)
aclcheck_error(aclresult, ACL_KIND_PROC,
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)
[parent: 287e6acae8a4]