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

Commit66c2cc2

Browse files
committed
Add --psqlrc=FILENAME parameter to psql, to process an explicitly named
file instead of ~/.psqlrc on startup.
1 parentb8b34b7 commit66c2cc2

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.239 2010/02/19 14:36:45 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.240 2010/03/06 15:28:09 mha Exp $
33
PostgreSQL documentation
44
-->
55

@@ -481,6 +481,16 @@ PostgreSQL documentation
481481
</listitem>
482482
</varlistentry>
483483

484+
<varlistentry>
485+
<term><option>--psqlrc=<replaceable class="parameter">FILENAME</></></term>
486+
<listitem>
487+
<para>
488+
Read the start-up file from <replaceable class="parameter">FILENAME</>
489+
instead of <filename>~/.psqlrc</>.
490+
</para>
491+
</listitem>
492+
</varlistentry>
493+
484494
<varlistentry>
485495
<term><option>-1</option></term>
486496
<term><option>--single-transaction</option></term>

‎src/bin/psql/help.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.155 2010/01/02 16:57:59 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.156 2010/03/06 15:28:09 mha Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -99,6 +99,7 @@ usage(void)
9999
printf(_(" -v, --set=, --variable=NAME=VALUE\n"
100100
" set psql variable NAME to VALUE\n"));
101101
printf(_(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
102+
printf(_(" --psqlrc=FILENAME read startup commands from file (instead of ~/.psqlrc)\n"));
102103
printf(_(" -1 (\"one\"), --single-transaction\n"
103104
" execute command file as a single transaction\n"));
104105
printf(_(" --help show this help, then exit\n"));

‎src/bin/psql/startup.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.162 2010/02/26 02:01:19 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.163 2010/03/06 15:28:09 mha Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -68,11 +68,12 @@ struct adhoc_opts
6868
boolno_readline;
6969
boolno_psqlrc;
7070
boolsingle_txn;
71+
char*psqlrc;
7172
};
7273

7374
staticvoidparse_psql_options(intargc,char*argv[],
7475
structadhoc_opts*options);
75-
staticvoidprocess_psqlrc(char*argv0);
76+
staticvoidprocess_psqlrc(char*argv0,structadhoc_opts*options);
7677
staticvoidprocess_psqlrc_file(char*filename);
7778
staticvoidshowVersion(void);
7879
staticvoidEstablishVariableSpace(void);
@@ -247,8 +248,7 @@ main(int argc, char *argv[])
247248
*/
248249
if (options.action==ACT_FILE)
249250
{
250-
if (!options.no_psqlrc)
251-
process_psqlrc(argv[0]);
251+
process_psqlrc(argv[0],&options);
252252

253253
successResult=process_file(options.action_string,options.single_txn);
254254
}
@@ -291,8 +291,7 @@ main(int argc, char *argv[])
291291
*/
292292
else
293293
{
294-
if (!options.no_psqlrc)
295-
process_psqlrc(argv[0]);
294+
process_psqlrc(argv[0],&options);
296295

297296
connection_warnings(true);
298297
if (!pset.quiet&& !pset.notty)
@@ -355,6 +354,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
355354
{"password",no_argument,NULL,'W'},
356355
{"expanded",no_argument,NULL,'x'},
357356
{"no-psqlrc",no_argument,NULL,'X'},
357+
{"psqlrc",required_argument,NULL,1},
358358
{"help",no_argument,NULL,'?'},
359359
{NULL,0,NULL,0}
360360
};
@@ -515,6 +515,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
515515
case'X':
516516
options->no_psqlrc= true;
517517
break;
518+
case1:
519+
options->psqlrc=pg_strdup(optarg);
520+
break;
518521
case'1':
519522
options->single_txn= true;
520523
break;
@@ -563,20 +566,27 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
563566
* Load .psqlrc file, if found.
564567
*/
565568
staticvoid
566-
process_psqlrc(char*argv0)
569+
process_psqlrc(char*argv0,structadhoc_opts*options)
567570
{
568571
charhome[MAXPGPATH];
569572
charrc_file[MAXPGPATH];
570573
charmy_exec_path[MAXPGPATH];
571574
charetc_path[MAXPGPATH];
572575

576+
if (options->no_psqlrc)
577+
return;
578+
573579
find_my_exec(argv0,my_exec_path);
574580
get_etc_path(my_exec_path,etc_path);
575581

576582
snprintf(rc_file,MAXPGPATH,"%s/%s",etc_path,SYSPSQLRC);
577583
process_psqlrc_file(rc_file);
578584

579-
if (get_home_path(home))
585+
if (options->psqlrc)
586+
{
587+
process_psqlrc_file(options->psqlrc);
588+
}
589+
elseif (get_home_path(home))
580590
{
581591
snprintf(rc_file,MAXPGPATH,"%s/%s",home,PSQLRC);
582592
process_psqlrc_file(rc_file);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp