Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ba0c93a

Browse files
committed
Convert createlang/droplang to use CREATE/DROP EXTENSION.
In createlang this is a one-line change. In droplang there's a whole lot of cruft that can be discarded since the extension mechanism now manages removal of the language's support functions. Also, add deprecation notices to these two programs' reference pages, since per discussion we may toss them overboard altogether in a release or two.
1 parent c0f2b2e commit ba0c93a

File tree

4 files changed

+46
-174
lines changed

4 files changed

+46
-174
lines changed

doc/src/sgml/ref/createlang.sgml

+17-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PostgreSQL documentation
1212

1313
<refnamediv>
1414
<refname>createlang</refname>
15-
<refpurpose>define a new <productname>PostgreSQL</productname> procedural language</refpurpose>
15+
<refpurpose>install a <productname>PostgreSQL</productname> procedural language</refpurpose>
1616
</refnamediv>
1717

1818
<indexterm zone="app-createlang">
@@ -40,12 +40,22 @@ PostgreSQL documentation
4040
<title>Description</title>
4141

4242
<para>
43-
<application>createlang</application> is a utility for adding a new
44-
programming language to a <productname>PostgreSQL</productname> database.
43+
<application>createlang</application> is a utility for adding a
44+
procedural language to a <productname>PostgreSQL</productname> database.
45+
</para>
46+
47+
<para>
4548
<application>createlang</application> is just a wrapper around the
46-
<xref linkend="sql-createlanguage">
47-
command.
49+
<xref linkend="sql-createextension"> SQL command.
4850
</para>
51+
52+
<caution>
53+
<para>
54+
<application>createlang</application> is deprecated and may be removed
55+
in a future <productname>PostgreSQL</productname> release. Direct use
56+
of the <command>CREATE EXTENSION</> command is recommended instead.
57+
</para>
58+
</caution>
4959
</refsect1>
5060

5161

@@ -60,8 +70,7 @@ PostgreSQL documentation
6070
<term><replaceable class="parameter">langname</replaceable></term>
6171
<listitem>
6272
<para>
63-
Specifies the name of the procedural programming language to be
64-
defined.
73+
Specifies the name of the procedural language to be installed.
6574
</para>
6675
</listitem>
6776
</varlistentry>
@@ -273,6 +282,7 @@ PostgreSQL documentation
273282

274283
<simplelist type="inline">
275284
<member><xref linkend="app-droplang"></member>
285+
<member><xref linkend="sql-createextension"></member>
276286
<member><xref linkend="sql-createlanguage"></member>
277287
</simplelist>
278288
</refsect1>

doc/src/sgml/ref/droplang.sgml

+14-10
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,22 @@ PostgreSQL documentation
4242

4343
<para>
4444
<application>droplang</application> is a utility for removing an
45-
existing programming language from a
45+
existing procedural language from a
4646
<productname>PostgreSQL</productname> database.
47-
<application>droplang</application> can drop any procedural language,
48-
even those not supplied by the <productname>PostgreSQL</> distribution.
4947
</para>
48+
5049
<para>
51-
Although backend programming languages can be removed directly using
52-
several <acronym>SQL</acronym> commands, it is recommended to use
53-
<application>droplang</application> because it performs a number
54-
of checks and is much easier to use. See
55-
<xref linkend="sql-droplanguage">
56-
for more.
50+
<application>droplang</application> is just a wrapper around the
51+
<xref linkend="sql-dropextension"> SQL command.
5752
</para>
53+
54+
<caution>
55+
<para>
56+
<application>droplang</application> is deprecated and may be removed
57+
in a future <productname>PostgreSQL</productname> release. Direct use
58+
of the <command>DROP EXTENSION</> command is recommended instead.
59+
</para>
60+
</caution>
5861
</refsect1>
5962

6063

@@ -69,7 +72,7 @@ PostgreSQL documentation
6972
<term><replaceable class="parameter">langname</replaceable></term>
7073
<listitem>
7174
<para>
72-
Specifies the name of the backend programming language to be removed.
75+
Specifies the name of the procedural language to be removed.
7376
</para>
7477
</listitem>
7578
</varlistentry>
@@ -277,6 +280,7 @@ PostgreSQL documentation
277280

278281
<simplelist type="inline">
279282
<member><xref linkend="app-createlang"></member>
283+
<member><xref linkend="sql-dropextension"></member>
280284
<member><xref linkend="sql-droplanguage"></member>
281285
</simplelist>
282286
</refsect1>

src/bin/scripts/createlang.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,15 @@ main(int argc, char *argv[])
188188
}
189189
PQclear(result);
190190

191-
printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";\n", langname);
191+
/*
192+
* In 9.1 and up, assume that languages should be installed using CREATE
193+
* EXTENSION. However, it's possible this tool could be used against an
194+
* older server, and it's easy enough to continue supporting the old way.
195+
*/
196+
if (PQserverVersion(conn) >= 90100)
197+
printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";\n", langname);
198+
else
199+
printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";\n", langname);
192200

193201
if (echo)
194202
printf("%s", sql.data);

src/bin/scripts/droplang.c

+6-156
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*
1010
*-------------------------------------------------------------------------
1111
*/
12-
1312
#include "postgres_fe.h"
13+
1414
#include "common.h"
1515
#include "print.h"
1616

@@ -47,18 +47,6 @@ main(int argc, char *argv[])
4747
bool echo = false;
4848
char *langname = NULL;
4949
char *p;
50-
Oid lanplcallfoid;
51-
Oid laninline;
52-
Oid lanvalidator;
53-
char *handler;
54-
char *inline_handler;
55-
char *validator;
56-
char *handler_ns;
57-
char *inline_ns;
58-
char *validator_ns;
59-
bool keephandler;
60-
bool keepinline;
61-
bool keepvalidator;
6250
PQExpBufferData sql;
6351
PGconn *conn;
6452
PGresult *result;
@@ -190,10 +178,9 @@ main(int argc, char *argv[])
190178
executeCommand(conn, "SET search_path = pg_catalog;", progname, echo);
191179

192180
/*
193-
* Make sure the language is installed and find the OIDs of the language
194-
* support functions
181+
* Make sure the language is installed
195182
*/
196-
printfPQExpBuffer(&sql, "SELECT lanplcallfoid, laninline, lanvalidator "
183+
printfPQExpBuffer(&sql, "SELECT oid "
197184
"FROM pg_language WHERE lanname = '%s' AND lanispl;",
198185
langname);
199186
result = executeQuery(conn, sql.data, progname, echo);
@@ -205,151 +192,14 @@ main(int argc, char *argv[])
205192
progname, langname, dbname);
206193
exit(1);
207194
}
208-
lanplcallfoid = atooid(PQgetvalue(result, 0, 0));
209-
laninline = atooid(PQgetvalue(result, 0, 1));
210-
lanvalidator = atooid(PQgetvalue(result, 0, 2));
211-
PQclear(result);
212-
213-
/*
214-
* Check that there are no functions left defined in that language
215-
*/
216-
printfPQExpBuffer(&sql, "SELECT count(proname) FROM pg_proc P, "
217-
"pg_language L WHERE P.prolang = L.oid "
218-
"AND L.lanname = '%s';", langname);
219-
result = executeQuery(conn, sql.data, progname, echo);
220-
if (strcmp(PQgetvalue(result, 0, 0), "0") != 0)
221-
{
222-
PQfinish(conn);
223-
fprintf(stderr,
224-
_("%s: still %s functions declared in language \"%s\"; "
225-
"language not removed\n"),
226-
progname, PQgetvalue(result, 0, 0), langname);
227-
exit(1);
228-
}
229195
PQclear(result);
230196

231197
/*
232-
* Check that the handler function isn't used by some other language
198+
* Attempt to drop the language. We do not use CASCADE, so that
199+
* the drop will fail if there are any functions in the language.
233200
*/
234-
printfPQExpBuffer(&sql, "SELECT count(*) FROM pg_language "
235-
"WHERE lanplcallfoid = %u AND lanname <> '%s';",
236-
lanplcallfoid, langname);
237-
result = executeQuery(conn, sql.data, progname, echo);
238-
if (strcmp(PQgetvalue(result, 0, 0), "0") == 0)
239-
keephandler = false;
240-
else
241-
keephandler = true;
242-
PQclear(result);
201+
printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";\n", langname);
243202

244-
/*
245-
* Find the handler name
246-
*/
247-
if (!keephandler)
248-
{
249-
printfPQExpBuffer(&sql, "SELECT proname, (SELECT nspname "
250-
"FROM pg_namespace ns WHERE ns.oid = pronamespace) "
251-
"AS prons FROM pg_proc WHERE oid = %u;",
252-
lanplcallfoid);
253-
result = executeQuery(conn, sql.data, progname, echo);
254-
handler = strdup(PQgetvalue(result, 0, 0));
255-
handler_ns = strdup(PQgetvalue(result, 0, 1));
256-
PQclear(result);
257-
}
258-
else
259-
{
260-
handler = NULL;
261-
handler_ns = NULL;
262-
}
263-
264-
/*
265-
* Check that the inline function isn't used by some other language
266-
*/
267-
if (OidIsValid(laninline))
268-
{
269-
printfPQExpBuffer(&sql, "SELECT count(*) FROM pg_language "
270-
"WHERE laninline = %u AND lanname <> '%s';",
271-
laninline, langname);
272-
result = executeQuery(conn, sql.data, progname, echo);
273-
if (strcmp(PQgetvalue(result, 0, 0), "0") == 0)
274-
keepinline = false;
275-
else
276-
keepinline = true;
277-
PQclear(result);
278-
}
279-
else
280-
keepinline = true; /* don't try to delete it */
281-
282-
/*
283-
* Find the inline handler name
284-
*/
285-
if (!keepinline)
286-
{
287-
printfPQExpBuffer(&sql, "SELECT proname, (SELECT nspname "
288-
"FROM pg_namespace ns WHERE ns.oid = pronamespace) "
289-
"AS prons FROM pg_proc WHERE oid = %u;",
290-
laninline);
291-
result = executeQuery(conn, sql.data, progname, echo);
292-
inline_handler = strdup(PQgetvalue(result, 0, 0));
293-
inline_ns = strdup(PQgetvalue(result, 0, 1));
294-
PQclear(result);
295-
}
296-
else
297-
{
298-
inline_handler = NULL;
299-
inline_ns = NULL;
300-
}
301-
302-
/*
303-
* Check that the validator function isn't used by some other language
304-
*/
305-
if (OidIsValid(lanvalidator))
306-
{
307-
printfPQExpBuffer(&sql, "SELECT count(*) FROM pg_language "
308-
"WHERE lanvalidator = %u AND lanname <> '%s';",
309-
lanvalidator, langname);
310-
result = executeQuery(conn, sql.data, progname, echo);
311-
if (strcmp(PQgetvalue(result, 0, 0), "0") == 0)
312-
keepvalidator = false;
313-
else
314-
keepvalidator = true;
315-
PQclear(result);
316-
}
317-
else
318-
keepvalidator = true; /* don't try to delete it */
319-
320-
/*
321-
* Find the validator name
322-
*/
323-
if (!keepvalidator)
324-
{
325-
printfPQExpBuffer(&sql, "SELECT proname, (SELECT nspname "
326-
"FROM pg_namespace ns WHERE ns.oid = pronamespace) "
327-
"AS prons FROM pg_proc WHERE oid = %u;",
328-
lanvalidator);
329-
result = executeQuery(conn, sql.data, progname, echo);
330-
validator = strdup(PQgetvalue(result, 0, 0));
331-
validator_ns = strdup(PQgetvalue(result, 0, 1));
332-
PQclear(result);
333-
}
334-
else
335-
{
336-
validator = NULL;
337-
validator_ns = NULL;
338-
}
339-
340-
/*
341-
* Drop the language and the functions
342-
*/
343-
printfPQExpBuffer(&sql, "DROP LANGUAGE \"%s\";\n", langname);
344-
if (!keephandler)
345-
appendPQExpBuffer(&sql, "DROP FUNCTION \"%s\".\"%s\" ();\n",
346-
handler_ns, handler);
347-
if (!keepinline)
348-
appendPQExpBuffer(&sql, "DROP FUNCTION \"%s\".\"%s\" (internal);\n",
349-
inline_ns, inline_handler);
350-
if (!keepvalidator)
351-
appendPQExpBuffer(&sql, "DROP FUNCTION \"%s\".\"%s\" (oid);\n",
352-
validator_ns, validator);
353203
if (echo)
354204
printf("%s", sql.data);
355205
result = PQexec(conn, sql.data);

0 commit comments

Comments
 (0)