Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite693e97

Browse files
committed
Support replacing MODULE_PATHNAME during extension script file execution.
This avoids the need to find a way to make PGXS' .sql.in-to-.sql ruleinsert the right thing. We'll just deprecate use of that hack forextensions.
1 parent27d5d7a commite693e97

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

‎doc/src/sgml/extend.sgml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,23 +427,38 @@
427427
</varlistentry>
428428

429429
<varlistentry>
430-
<term><varname>requires</varname> (<type>string</type>)</term>
430+
<term><varname>encoding</varname> (<type>string</type>)</term>
431431
<listitem>
432432
<para>
433-
A list of names of extensions that this extension depends on,
434-
for example <literal>requires = 'foo, bar'</literal>. Those
435-
extensions mustbeinstalled before this one can be installed.
433+
The character set encoding used by the script file(s). This should
434+
be specified if the script files contain any non-ASCII characters.
435+
Otherwise the files willbeassumed to be in the database encoding.
436436
</para>
437437
</listitem>
438438
</varlistentry>
439439

440440
<varlistentry>
441-
<term><varname>encoding</varname> (<type>string</type>)</term>
441+
<term><varname>module_pathname</varname> (<type>string</type>)</term>
442442
<listitem>
443443
<para>
444-
The character set encoding used by the script file(s). This should
445-
be specified if the script files contain any non-ASCII characters.
446-
Otherwise the files will be assumed to be in the database encoding.
444+
The value of this parameter will be substituted for each occurrence
445+
of <literal>MODULE_PATHNAME</> in the script file(s). If it is not
446+
set, no substitution is made. Typically, this is set to
447+
<literal>$libdir/<replaceable>shared_library_name</></literal> and
448+
then <literal>MODULE_PATHNAME</> is used in <command>CREATE
449+
FUNCTION</> commands for C-language functions, so that the script
450+
files do not need to hard-wire the name of the shared library.
451+
</para>
452+
</listitem>
453+
</varlistentry>
454+
455+
<varlistentry>
456+
<term><varname>requires</varname> (<type>string</type>)</term>
457+
<listitem>
458+
<para>
459+
A list of names of extensions that this extension depends on,
460+
for example <literal>requires = 'foo, bar'</literal>. Those
461+
extensions must be installed before this one can be installed.
447462
</para>
448463
</listitem>
449464
</varlistentry>

‎src/backend/commands/extension.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef struct ExtensionControlFile
6565
char*name;/* name of the extension */
6666
char*directory;/* directory for script files */
6767
char*default_version;/* default install target version, if any */
68+
char*module_pathname;/* string to substitute for MODULE_PATHNAME */
6869
char*comment;/* comment, if any */
6970
char*schema;/* target schema (allowed if !relocatable) */
7071
boolrelocatable;/* is ALTER EXTENSION SET SCHEMA supported? */
@@ -493,6 +494,10 @@ parse_extension_control_file(ExtensionControlFile *control,
493494

494495
control->default_version=pstrdup(item->value);
495496
}
497+
elseif (strcmp(item->name,"module_pathname")==0)
498+
{
499+
control->module_pathname=pstrdup(item->value);
500+
}
496501
elseif (strcmp(item->name,"comment")==0)
497502
{
498503
control->comment=pstrdup(item->value);
@@ -836,7 +841,20 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
836841
CStringGetTextDatum(sql),
837842
CStringGetTextDatum("@extschema@"),
838843
CStringGetTextDatum(qSchemaName))));
844+
}
839845

846+
/*
847+
* If module_pathname was set in the control file, substitute its
848+
* value for occurrences of MODULE_PATHNAME.
849+
*/
850+
if (control->module_pathname)
851+
{
852+
sql=text_to_cstring(
853+
DatumGetTextPP(
854+
DirectFunctionCall3(replace_text,
855+
CStringGetTextDatum(sql),
856+
CStringGetTextDatum("MODULE_PATHNAME"),
857+
CStringGetTextDatum(control->module_pathname))));
840858
}
841859

842860
execute_sql_string(sql,filename);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp