Commit e693e97d authored by Tom Lane's avatar Tom Lane

Support replacing MODULE_PATHNAME during extension script file execution.

This avoids the need to find a way to make PGXS' .sql.in-to-.sql rule
insert the right thing.  We'll just deprecate use of that hack for
extensions.
parent 27d5d7ab
...@@ -427,23 +427,38 @@ ...@@ -427,23 +427,38 @@
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>requires</varname> (<type>string</type>)</term> <term><varname>encoding</varname> (<type>string</type>)</term>
<listitem> <listitem>
<para> <para>
A list of names of extensions that this extension depends on, The character set encoding used by the script file(s). This should
for example <literal>requires = 'foo, bar'</literal>. Those be specified if the script files contain any non-ASCII characters.
extensions must be installed before this one can be installed. Otherwise the files will be assumed to be in the database encoding.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>encoding</varname> (<type>string</type>)</term> <term><varname>module_pathname</varname> (<type>string</type>)</term>
<listitem> <listitem>
<para> <para>
The character set encoding used by the script file(s). This should The value of this parameter will be substituted for each occurrence
be specified if the script files contain any non-ASCII characters. of <literal>MODULE_PATHNAME</> in the script file(s). If it is not
Otherwise the files will be assumed to be in the database encoding. set, no substitution is made. Typically, this is set to
<literal>$libdir/<replaceable>shared_library_name</></literal> and
then <literal>MODULE_PATHNAME</> is used in <command>CREATE
FUNCTION</> commands for C-language functions, so that the script
files do not need to hard-wire the name of the shared library.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>requires</varname> (<type>string</type>)</term>
<listitem>
<para>
A list of names of extensions that this extension depends on,
for example <literal>requires = 'foo, bar'</literal>. Those
extensions must be installed before this one can be installed.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -65,6 +65,7 @@ typedef struct ExtensionControlFile ...@@ -65,6 +65,7 @@ typedef struct ExtensionControlFile
char *name; /* name of the extension */ char *name; /* name of the extension */
char *directory; /* directory for script files */ char *directory; /* directory for script files */
char *default_version; /* default install target version, if any */ char *default_version; /* default install target version, if any */
char *module_pathname; /* string to substitute for MODULE_PATHNAME */
char *comment; /* comment, if any */ char *comment; /* comment, if any */
char *schema; /* target schema (allowed if !relocatable) */ char *schema; /* target schema (allowed if !relocatable) */
bool relocatable; /* is ALTER EXTENSION SET SCHEMA supported? */ bool relocatable; /* is ALTER EXTENSION SET SCHEMA supported? */
...@@ -493,6 +494,10 @@ parse_extension_control_file(ExtensionControlFile *control, ...@@ -493,6 +494,10 @@ parse_extension_control_file(ExtensionControlFile *control,
control->default_version = pstrdup(item->value); control->default_version = pstrdup(item->value);
} }
else if (strcmp(item->name, "module_pathname") == 0)
{
control->module_pathname = pstrdup(item->value);
}
else if (strcmp(item->name, "comment") == 0) else if (strcmp(item->name, "comment") == 0)
{ {
control->comment = pstrdup(item->value); control->comment = pstrdup(item->value);
...@@ -836,7 +841,20 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, ...@@ -836,7 +841,20 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
CStringGetTextDatum(sql), CStringGetTextDatum(sql),
CStringGetTextDatum("@extschema@"), CStringGetTextDatum("@extschema@"),
CStringGetTextDatum(qSchemaName)))); CStringGetTextDatum(qSchemaName))));
}
/*
* If module_pathname was set in the control file, substitute its
* value for occurrences of MODULE_PATHNAME.
*/
if (control->module_pathname)
{
sql = text_to_cstring(
DatumGetTextPP(
DirectFunctionCall3(replace_text,
CStringGetTextDatum(sql),
CStringGetTextDatum("MODULE_PATHNAME"),
CStringGetTextDatum(control->module_pathname))));
} }
execute_sql_string(sql, filename); execute_sql_string(sql, filename);
......
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