]> granicus.if.org Git - postgresql/blobdiff - src/backend/catalog/pg_conversion.c
Refactor the handling of the various DropStmt variants so that when multiple
[postgresql] / src / backend / catalog / pg_conversion.c
index 262d9f41fb70d7e1696c61a668bb260a96706e1e..753acb133df114b50b8e9b933c060eee487f2e84 100644 (file)
@@ -3,30 +3,32 @@
  * pg_conversion.c
  *       routines to support manipulation of the pg_conversion relation
  *
- * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.36 2007/02/27 23:48:07 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.44 2008/06/14 18:04:33 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
 
 #include "access/heapam.h"
+#include "access/sysattr.h"
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
-#include "catalog/namespace.h"
 #include "catalog/pg_conversion.h"
+#include "catalog/pg_conversion_fn.h"
 #include "catalog/pg_namespace.h"
 #include "catalog/pg_proc.h"
 #include "mb/pg_wchar.h"
+#include "miscadmin.h"
+#include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
 #include "utils/syscache.h"
-#include "utils/acl.h"
-#include "miscadmin.h"
+#include "utils/tqual.h"
 
 /*
  * ConversionCreate
@@ -135,40 +137,6 @@ ConversionCreate(const char *conname, Oid connamespace,
        return oid;
 }
 
-/*
- * ConversionDrop
- *
- * Drop a conversion after doing permission checks.
- */
-void
-ConversionDrop(Oid conversionOid, DropBehavior behavior)
-{
-       HeapTuple       tuple;
-       ObjectAddress object;
-
-       tuple = SearchSysCache(CONVOID,
-                                                  ObjectIdGetDatum(conversionOid),
-                                                  0, 0, 0);
-       if (!HeapTupleIsValid(tuple))
-               elog(ERROR, "cache lookup failed for conversion %u", conversionOid);
-
-       if (!superuser() &&
-               ((Form_pg_conversion) GETSTRUCT(tuple))->conowner != GetUserId())
-               aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CONVERSION,
-                                 NameStr(((Form_pg_conversion) GETSTRUCT(tuple))->conname));
-
-       ReleaseSysCache(tuple);
-
-       /*
-        * Do the deletion
-        */
-       object.classId = ConversionRelationId;
-       object.objectId = conversionOid;
-       object.objectSubId = 0;
-
-       performDeletion(&object, behavior);
-}
-
 /*
  * RemoveConversionById
  *
@@ -275,74 +243,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>
- *
- * TEXT convert_using(TEXT string, TEXT conversion_name)
- */
-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_TEXT_P(retval);
-}