|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -49,6 +49,7 @@ CreateConversionCommand(CreateConversionStmt *stmt)
|
49 | 49 | const char *to_encoding_name = stmt->to_encoding_name;
|
50 | 50 | List *func_name = stmt->func_name;
|
51 | 51 | static Oid funcargs[] = {INT4OID, INT4OID, CSTRINGOID, INTERNALOID, INT4OID};
|
| 52 | + char result[1]; |
52 | 53 |
|
53 | 54 | /* Convert list of names to a name and namespace */
|
54 | 55 | namespaceId = QualifiedNameGetCreationNamespace(stmt->conversion_name,
|
@@ -95,6 +96,19 @@ CreateConversionCommand(CreateConversionStmt *stmt)
|
95 | 96 | aclcheck_error(aclresult, ACL_KIND_PROC,
|
96 | 97 | NameListToString(func_name));
|
97 | 98 |
|
| 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 | + |
98 | 112 | /*
|
99 | 113 | * All seem ok, go ahead (possible failure would be a duplicate conversion
|
100 | 114 | * name)
|
|
0 commit comments