Commit 02138357 authored by Andrew Dunstan's avatar Andrew Dunstan

Remove "convert 'blah' using conversion_name" facility, because if it

produces text it is an encoding hole and if not it's incompatible
with the spec, whatever the spec means (which we're not sure about anyway).
parent c3b193a5
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.397 2007/09/19 03:13:57 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.398 2007/09/24 01:29:27 adunstan Exp $ -->
<chapter id="functions">
<title>Functions and Operators</title>
......@@ -1022,9 +1022,6 @@
<indexterm>
<primary>char_length</primary>
</indexterm>
<indexterm>
<primary>convert</primary>
</indexterm>
<indexterm>
<primary>lower</primary>
</indexterm>
......@@ -1119,22 +1116,6 @@
<entry><literal>4</literal></entry>
</row>
<row>
<entry><literal><function>convert</function>(<parameter>string</parameter>
using <parameter>conversion_name</parameter>)</literal></entry>
<entry><type>bytea</type></entry>
<entry>
Change encoding using specified conversion name. Conversions
can be defined by <command>CREATE CONVERSION</command>. Also
there are some pre-defined conversion names. See <xref
linkend="conversion-names"> for available conversion
names. The <parameter>string</parameter> must be valid in the
source encoding.
</entry>
<entry><literal>convert('PostgreSQL' using iso_8859_1_to_utf8)</literal></entry>
<entry><literal>'PostgreSQL'</literal> in UTF8 (Unicode, 8-bit) encoding</entry>
</row>
<row>
<entry><literal><function>lower</function>(<parameter>string</parameter>)</literal></entry>
<entry><type>text</type></entry>
......@@ -1245,6 +1226,9 @@
<indexterm>
<primary>chr</primary>
</indexterm>
<indexterm>
<primary>convert</primary>
</indexterm>
<indexterm>
<primary>convert_from</primary>
</indexterm>
......@@ -1374,6 +1358,9 @@
original encoding is specified by
<parameter>src_encoding</parameter>. The
<parameter>string</parameter> must be valid in this encoding.
Conversions can be defined by <command>CREATE CONVERSION</command>.
Also there are some pre-defined conversions. See <xref
linkend="conversion-names"> for available conversions.
</entry>
<entry><literal>convert( 'text_in_utf8', 'UTF8', 'LATIN1')</literal></entry>
<entry><literal>text_in_utf8</literal> represented in ISO 8859-1 encoding</entry>
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/create_conversion.sgml,v 1.19 2007/01/31 23:26:03 momjian Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/create_conversion.sgml,v 1.20 2007/09/24 01:29:28 adunstan Exp $ -->
<refentry id="SQL-CREATECONVERSION">
<refmeta>
......@@ -27,9 +27,7 @@ CREATE [ DEFAULT ] CONVERSION <replaceable>name</replaceable>
<para>
<command>CREATE CONVERSION</command> defines a new conversion between
character set encodings. Conversion names can be used in the
<function>convert</function> function
to specify a particular encoding conversion. Also, conversions that
character set encodings. Also, conversions that
are marked <literal>DEFAULT</> can be used for automatic encoding
conversion between
client and server. For this purpose, two conversions, from encoding A to
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.37 2007/09/18 17:41:17 adunstan Exp $
* $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.38 2007/09/24 01:29:28 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -276,76 +276,3 @@ FindConversion(const char *conname, Oid connamespace)
return conoid;
}
/*
* Execute SQL99's CONVERT function.
*
* CONVERT <left paren> <character value expression>
* USING <form-of-use conversion name> <right paren>
*
* BYTEA convert_using(TEXT string, TEXT conversion_name)
*
* bytea is returned so we don't give a value that is
* not valid in the database encoding.
*/
Datum
pg_convert_using(PG_FUNCTION_ARGS)
{
text *string = PG_GETARG_TEXT_P(0);
text *conv_name = PG_GETARG_TEXT_P(1);
text *retval;
List *parsed_name;
Oid convoid;
HeapTuple tuple;
Form_pg_conversion body;
char *str;
char *result;
int len;
/* Convert input string to null-terminated form */
len = VARSIZE(string) - VARHDRSZ;
str = palloc(len + 1);
memcpy(str, VARDATA(string), len);
*(str + len) = '\0';
/* Look up the conversion name */
parsed_name = textToQualifiedNameList(conv_name);
convoid = FindConversionByName(parsed_name);
if (!OidIsValid(convoid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("conversion \"%s\" does not exist",
NameListToString(parsed_name))));
tuple = SearchSysCache(CONVOID,
ObjectIdGetDatum(convoid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for conversion %u", convoid);
body = (Form_pg_conversion) GETSTRUCT(tuple);
/* Temporary result area should be more than big enough */
result = palloc(len * 4 + 1);
OidFunctionCall5(body->conproc,
Int32GetDatum(body->conforencoding),
Int32GetDatum(body->contoencoding),
CStringGetDatum(str),
CStringGetDatum(result),
Int32GetDatum(len));
ReleaseSysCache(tuple);
/*
* build text result structure. we cannot use textin() here, since textin
* assumes that input string encoding is same as database encoding.
*/
len = strlen(result) + VARHDRSZ;
retval = palloc(len);
SET_VARSIZE(retval, len);
memcpy(VARDATA(retval), result, len - VARHDRSZ);
pfree(result);
pfree(str);
PG_RETURN_BYTEA_P(retval);
}
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.602 2007/09/03 18:46:30 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.603 2007/09/24 01:29:28 adunstan Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
......@@ -377,7 +377,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT
COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
CONTENT_P CONVERSION_P CONVERT COPY COST CREATE CREATEDB
CONTENT_P CONVERSION_P COPY COST CREATE CREATEDB
CREATEROLE CREATEUSER CROSS CSV CURRENT_P CURRENT_DATE CURRENT_ROLE
CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
......@@ -8218,31 +8218,6 @@ func_expr: func_name '(' ')'
n->location = @1;
$$ = (Node *)n;
}
| CONVERT '(' a_expr USING any_name ')'
{
FuncCall *n = makeNode(FuncCall);
A_Const *c = makeNode(A_Const);
c->val.type = T_String;
c->val.val.str = NameListToQuotedString($5);
n->funcname = SystemFuncName("convert_using");
n->args = list_make2($3, c);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
n->location = @1;
$$ = (Node *)n;
}
| CONVERT '(' expr_list ')'
{
FuncCall *n = makeNode(FuncCall);
n->funcname = SystemFuncName("convert");
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
n->location = @1;
$$ = (Node *)n;
}
| NULLIF '(' a_expr ',' a_expr ')'
{
$$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
......@@ -9291,7 +9266,6 @@ col_name_keyword:
| CHAR_P
| CHARACTER
| COALESCE
| CONVERT
| DEC
| DECIMAL_P
| EXISTS
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.191 2007/08/21 15:13:42 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.192 2007/09/24 01:29:29 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -93,7 +93,6 @@ static const ScanKeyword ScanKeywords[] = {
{"constraints", CONSTRAINTS, UNRESERVED_KEYWORD},
{"content", CONTENT_P, UNRESERVED_KEYWORD},
{"conversion", CONVERSION_P, UNRESERVED_KEYWORD},
{"convert", CONVERT, COL_NAME_KEYWORD},
{"copy", COPY, UNRESERVED_KEYWORD},
{"cost", COST, UNRESERVED_KEYWORD},
{"create", CREATE, RESERVED_KEYWORD},
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.471 2007/09/20 17:56:32 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.472 2007/09/24 01:29:29 adunstan Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
......@@ -2244,9 +2244,6 @@ DESCR("convert string with specified destination encoding name");
DATA(insert OID = 1813 ( convert PGNSP PGUID 12 1 0 f f t f s 3 17 "17 19 19" _null_ _null_ _null_ pg_convert - _null_ _null_ ));
DESCR("convert string with specified encoding names");
DATA(insert OID = 1619 ( convert_using PGNSP PGUID 12 1 0 f f t f s 2 17 "25 25" _null_ _null_ _null_ pg_convert_using - _null_ _null_ ));
DESCR("convert string with specified conversion name");
DATA(insert OID = 1264 ( pg_char_to_encoding PGNSP PGUID 12 1 0 f f t f s 1 23 "19" _null_ _null_ _null_ PG_char_to_encoding - _null_ _null_ ));
DESCR("convert encoding name to encoding id");
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.303 2007/09/18 17:41:17 adunstan Exp $
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.304 2007/09/24 01:29:30 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -941,9 +941,6 @@ extern Datum pg_advisory_unlock_all(PG_FUNCTION_ARGS);
/* access/transam/twophase.c */
extern Datum pg_prepared_xact(PG_FUNCTION_ARGS);
/* catalog/pg_conversion.c */
extern Datum pg_convert_using(PG_FUNCTION_ARGS);
/* commands/prepare.c */
extern Datum pg_prepared_statement(PG_FUNCTION_ARGS);
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment