|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.37 2007/09/18 17:41:17 adunstan Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.38 2007/09/24 01:29:28 adunstan Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -276,76 +276,3 @@ FindConversion(const char *conname, Oid connamespace) |
276 | 276 | returnconoid; |
277 | 277 | } |
278 | 278 |
|
279 | | -/* |
280 | | - * Execute SQL99's CONVERT function. |
281 | | - * |
282 | | - * CONVERT <left paren> <character value expression> |
283 | | - * USING <form-of-use conversion name> <right paren> |
284 | | - * |
285 | | - * BYTEA convert_using(TEXT string, TEXT conversion_name) |
286 | | - * |
287 | | - * bytea is returned so we don't give a value that is |
288 | | - * not valid in the database encoding. |
289 | | - */ |
290 | | -Datum |
291 | | -pg_convert_using(PG_FUNCTION_ARGS) |
292 | | -{ |
293 | | -text*string=PG_GETARG_TEXT_P(0); |
294 | | -text*conv_name=PG_GETARG_TEXT_P(1); |
295 | | -text*retval; |
296 | | -List*parsed_name; |
297 | | -Oidconvoid; |
298 | | -HeapTupletuple; |
299 | | -Form_pg_conversionbody; |
300 | | -char*str; |
301 | | -char*result; |
302 | | -intlen; |
303 | | - |
304 | | -/* Convert input string to null-terminated form */ |
305 | | -len=VARSIZE(string)-VARHDRSZ; |
306 | | -str=palloc(len+1); |
307 | | -memcpy(str,VARDATA(string),len); |
308 | | -*(str+len)='\0'; |
309 | | - |
310 | | -/* Look up the conversion name */ |
311 | | -parsed_name=textToQualifiedNameList(conv_name); |
312 | | -convoid=FindConversionByName(parsed_name); |
313 | | -if (!OidIsValid(convoid)) |
314 | | -ereport(ERROR, |
315 | | -(errcode(ERRCODE_UNDEFINED_OBJECT), |
316 | | -errmsg("conversion \"%s\" does not exist", |
317 | | -NameListToString(parsed_name)))); |
318 | | - |
319 | | -tuple=SearchSysCache(CONVOID, |
320 | | -ObjectIdGetDatum(convoid), |
321 | | -0,0,0); |
322 | | -if (!HeapTupleIsValid(tuple)) |
323 | | -elog(ERROR,"cache lookup failed for conversion %u",convoid); |
324 | | -body= (Form_pg_conversion)GETSTRUCT(tuple); |
325 | | - |
326 | | -/* Temporary result area should be more than big enough */ |
327 | | -result=palloc(len*4+1); |
328 | | - |
329 | | -OidFunctionCall5(body->conproc, |
330 | | -Int32GetDatum(body->conforencoding), |
331 | | -Int32GetDatum(body->contoencoding), |
332 | | -CStringGetDatum(str), |
333 | | -CStringGetDatum(result), |
334 | | -Int32GetDatum(len)); |
335 | | - |
336 | | -ReleaseSysCache(tuple); |
337 | | - |
338 | | -/* |
339 | | - * build text result structure. we cannot use textin() here, since textin |
340 | | - * assumes that input string encoding is same as database encoding. |
341 | | - */ |
342 | | -len=strlen(result)+VARHDRSZ; |
343 | | -retval=palloc(len); |
344 | | -SET_VARSIZE(retval,len); |
345 | | -memcpy(VARDATA(retval),result,len-VARHDRSZ); |
346 | | - |
347 | | -pfree(result); |
348 | | -pfree(str); |
349 | | - |
350 | | -PG_RETURN_BYTEA_P(retval); |
351 | | -} |