/Users/deen/code/yugabyte-db/src/postgres/src/bin/psql/help.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * psql - the PostgreSQL interactive terminal |
3 | | * |
4 | | * Copyright (c) 2000-2018, PostgreSQL Global Development Group |
5 | | * |
6 | | * src/bin/psql/help.c |
7 | | */ |
8 | | #include "postgres_fe.h" |
9 | | |
10 | | #ifndef WIN32 |
11 | | #include <unistd.h> /* for geteuid() */ |
12 | | #else |
13 | | #include <win32.h> |
14 | | #endif |
15 | | |
16 | | #ifndef WIN32 |
17 | | #include <sys/ioctl.h> /* for ioctl() */ |
18 | | #endif |
19 | | |
20 | | #ifdef HAVE_TERMIOS_H |
21 | | #include <termios.h> |
22 | | #endif |
23 | | |
24 | | #include "common.h" |
25 | | #include "common/username.h" |
26 | | #include "help.h" |
27 | | #include "input.h" |
28 | | #include "settings.h" |
29 | | #include "sql_help.h" |
30 | | |
31 | | |
32 | | /* |
33 | | * PLEASE: |
34 | | * If you change something in this file, also make the same changes |
35 | | * in the DocBook documentation, file ref/psql-ref.sgml. If you don't |
36 | | * know how to do it, please find someone who can help you. |
37 | | */ |
38 | | |
39 | | |
40 | | /* |
41 | | * usage |
42 | | * |
43 | | * print out command line arguments |
44 | | */ |
45 | 0 | #define ON(var) (var ? _("on") : _("off")) |
46 | | |
47 | | void |
48 | | usage(unsigned short int pager) |
49 | 0 | { |
50 | 0 | const char *env; |
51 | 0 | const char *user; |
52 | 0 | char *errstr; |
53 | 0 | FILE *output; |
54 | | |
55 | | /* Find default user, in case we need it. */ |
56 | 0 | user = getenv("PGUSER"); |
57 | 0 | if (!user) |
58 | 0 | { |
59 | 0 | user = get_user_name(&errstr); |
60 | 0 | if (!user) |
61 | 0 | { |
62 | 0 | psql_error("%s\n", errstr); |
63 | 0 | exit(EXIT_FAILURE); |
64 | 0 | } |
65 | 0 | } |
66 | | |
67 | | /* |
68 | | * Keep this line count in sync with the number of lines printed below! |
69 | | * Use "psql --help=options | wc" to count correctly. |
70 | | */ |
71 | 0 | output = PageOutput(61, pager ? &(pset.popt.topt) : NULL); |
72 | |
|
73 | 0 | fprintf(output, _("ysqlsh is the YSQL interactive terminal.\n\n")); |
74 | 0 | fprintf(output, _("Usage:\n")); |
75 | 0 | fprintf(output, _(" ysqlsh [OPTION]... [DBNAME [USERNAME]]\n\n")); |
76 | |
|
77 | 0 | fprintf(output, _("General options:\n")); |
78 | | /* Display default database */ |
79 | 0 | env = getenv("PGDATABASE"); |
80 | 0 | if (!env) |
81 | 0 | env = user; |
82 | 0 | fprintf(output, _(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n")); |
83 | 0 | fprintf(output, _(" -d, --dbname=DBNAME database name to connect to (default: \"yugabyte\")\n")); |
84 | 0 | fprintf(output, _(" -f, --file=FILENAME execute commands from file, then exit\n")); |
85 | 0 | fprintf(output, _(" -l, --list list available databases, then exit\n")); |
86 | 0 | fprintf(output, _(" -v, --set=, --variable=NAME=VALUE\n" |
87 | 0 | " set psql variable NAME to VALUE\n" |
88 | 0 | " (e.g., -v ON_ERROR_STOP=1)\n")); |
89 | 0 | fprintf(output, _(" -V, --version output version information, then exit\n")); |
90 | 0 | fprintf(output, _(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n")); |
91 | 0 | fprintf(output, _(" -1 (\"one\"), --single-transaction\n" |
92 | 0 | " execute as a single transaction (if non-interactive)\n")); |
93 | 0 | fprintf(output, _(" -?, --help[=options] show this help, then exit\n")); |
94 | 0 | fprintf(output, _(" --help=commands list backslash commands, then exit\n")); |
95 | 0 | fprintf(output, _(" --help=variables list special variables, then exit\n")); |
96 | |
|
97 | 0 | fprintf(output, _("\nInput and output options:\n")); |
98 | 0 | fprintf(output, _(" -a, --echo-all echo all input from script\n")); |
99 | 0 | fprintf(output, _(" -b, --echo-errors echo failed commands\n")); |
100 | 0 | fprintf(output, _(" -e, --echo-queries echo commands sent to server\n")); |
101 | 0 | fprintf(output, _(" -E, --echo-hidden display queries that internal commands generate\n")); |
102 | 0 | fprintf(output, _(" -L, --log-file=FILENAME send session log to file\n")); |
103 | 0 | fprintf(output, _(" -n, --no-readline disable enhanced command line editing (readline)\n")); |
104 | 0 | fprintf(output, _(" -o, --output=FILENAME send query results to file (or |pipe)\n")); |
105 | 0 | fprintf(output, _(" -q, --quiet run quietly (no messages, only query output)\n")); |
106 | 0 | fprintf(output, _(" -s, --single-step single-step mode (confirm each query)\n")); |
107 | 0 | fprintf(output, _(" -S, --single-line single-line mode (end of line terminates SQL command)\n")); |
108 | |
|
109 | 0 | fprintf(output, _("\nOutput format options:\n")); |
110 | 0 | fprintf(output, _(" -A, --no-align unaligned table output mode\n")); |
111 | 0 | fprintf(output, _(" -F, --field-separator=STRING\n" |
112 | 0 | " field separator for unaligned output (default: \"%s\")\n"), |
113 | 0 | DEFAULT_FIELD_SEP); |
114 | 0 | fprintf(output, _(" -H, --html HTML table output mode\n")); |
115 | 0 | fprintf(output, _(" -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \\pset command)\n")); |
116 | 0 | fprintf(output, _(" -R, --record-separator=STRING\n" |
117 | 0 | " record separator for unaligned output (default: newline)\n")); |
118 | 0 | fprintf(output, _(" -t, --tuples-only print rows only\n")); |
119 | 0 | fprintf(output, _(" -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)\n")); |
120 | 0 | fprintf(output, _(" -x, --expanded turn on expanded table output\n")); |
121 | 0 | fprintf(output, _(" -z, --field-separator-zero\n" |
122 | 0 | " set field separator for unaligned output to zero byte\n")); |
123 | 0 | fprintf(output, _(" -0, --record-separator-zero\n" |
124 | 0 | " set record separator for unaligned output to zero byte\n")); |
125 | |
|
126 | 0 | fprintf(output, _("\nConnection options:\n")); |
127 | | /* Display default host */ |
128 | 0 | env = getenv("PGHOST"); |
129 | | /* YugaByte use localhost instead of local socket */ |
130 | 0 | fprintf(output, _(" -h, --host=HOSTNAME database server host or socket directory (default: \"%s\")\n"), |
131 | 0 | env ? env : "localhost"); |
132 | | /* YugaByte end */ |
133 | | /* Display default port */ |
134 | 0 | env = getenv("PGPORT"); |
135 | | /* Use YugaByte default port */ |
136 | 0 | fprintf(output, _(" -p, --port=PORT database server port (default: \"%s\")\n"), |
137 | 0 | env ? env : DEF_YBPORT_STR); |
138 | | /* Display default user */ |
139 | 0 | env = getenv("PGUSER"); |
140 | 0 | if (!env) |
141 | 0 | env = user; |
142 | 0 | fprintf(output, _(" -U, --username=USERNAME database user name (default: \"yugabyte\")\n")); |
143 | 0 | fprintf(output, _(" -w, --no-password never prompt for password\n")); |
144 | 0 | fprintf(output, _(" -W, --password force password prompt (should happen automatically)\n")); |
145 | |
|
146 | 0 | fprintf(output, _("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n" |
147 | 0 | "commands) from within ysqlsh, or consult the ysqlsh section in YugabyteDB docs.\n\n")); |
148 | 0 | fprintf(output, _("Report bugs on GitHub at https://github.com/YugaByte/yugabyte-db/issues.\n")); |
149 | |
|
150 | 0 | ClosePager(output); |
151 | 0 | } |
152 | | |
153 | | |
154 | | /* |
155 | | * slashUsage |
156 | | * |
157 | | * print out help for the backslash commands |
158 | | */ |
159 | | void |
160 | | slashUsage(unsigned short int pager) |
161 | 0 | { |
162 | 0 | FILE *output; |
163 | 0 | char *currdb; |
164 | |
|
165 | 0 | currdb = PQdb(pset.db); |
166 | | |
167 | | /* |
168 | | * Keep this line count in sync with the number of lines printed below! |
169 | | * Use "psql --help=commands | wc" to count correctly. It's okay to count |
170 | | * the USE_READLINE line even in builds without that. |
171 | | */ |
172 | 0 | output = PageOutput(125, pager ? &(pset.popt.topt) : NULL); |
173 | |
|
174 | 0 | fprintf(output, _("General\n")); |
175 | 0 | fprintf(output, _(" \\copyright show PostgreSQL usage and distribution terms\n")); |
176 | 0 | fprintf(output, _(" \\crosstabview [COLUMNS] execute query and display results in crosstab\n")); |
177 | 0 | fprintf(output, _(" \\errverbose show most recent error message at maximum verbosity\n")); |
178 | 0 | fprintf(output, _(" \\g [FILE] or ; execute query (and send results to file or |pipe)\n")); |
179 | 0 | fprintf(output, _(" \\gdesc describe result of query, without executing it\n")); |
180 | 0 | fprintf(output, _(" \\gexec execute query, then execute each value in its result\n")); |
181 | 0 | fprintf(output, _(" \\gset [PREFIX] execute query and store results in psql variables\n")); |
182 | 0 | fprintf(output, _(" \\gx [FILE] as \\g, but forces expanded output mode\n")); |
183 | 0 | fprintf(output, _(" \\q quit psql\n")); |
184 | 0 | fprintf(output, _(" \\watch [SEC] execute query every SEC seconds\n")); |
185 | 0 | fprintf(output, "\n"); |
186 | |
|
187 | 0 | fprintf(output, _("Help\n")); |
188 | |
|
189 | 0 | fprintf(output, _(" \\? [commands] show help on backslash commands\n")); |
190 | 0 | fprintf(output, _(" \\? options show help on psql command-line options\n")); |
191 | 0 | fprintf(output, _(" \\? variables show help on special variables\n")); |
192 | 0 | fprintf(output, _(" \\h [NAME] help on syntax of SQL commands, * for all commands\n")); |
193 | 0 | fprintf(output, "\n"); |
194 | |
|
195 | 0 | fprintf(output, _("Query Buffer\n")); |
196 | 0 | fprintf(output, _(" \\e [FILE] [LINE] edit the query buffer (or file) with external editor\n")); |
197 | 0 | fprintf(output, _(" \\ef [FUNCNAME [LINE]] edit function definition with external editor\n")); |
198 | 0 | fprintf(output, _(" \\ev [VIEWNAME [LINE]] edit view definition with external editor\n")); |
199 | 0 | fprintf(output, _(" \\p show the contents of the query buffer\n")); |
200 | 0 | fprintf(output, _(" \\r reset (clear) the query buffer\n")); |
201 | 0 | #ifdef USE_READLINE |
202 | 0 | fprintf(output, _(" \\s [FILE] display history or save it to file\n")); |
203 | 0 | #endif |
204 | 0 | fprintf(output, _(" \\w FILE write query buffer to file\n")); |
205 | 0 | fprintf(output, "\n"); |
206 | |
|
207 | 0 | fprintf(output, _("Input/Output\n")); |
208 | 0 | fprintf(output, _(" \\copy ... perform SQL COPY with data stream to the client host\n")); |
209 | 0 | fprintf(output, _(" \\echo [STRING] write string to standard output\n")); |
210 | 0 | fprintf(output, _(" \\i FILE execute commands from file\n")); |
211 | 0 | fprintf(output, _(" \\ir FILE as \\i, but relative to location of current script\n")); |
212 | 0 | fprintf(output, _(" \\o [FILE] send all query results to file or |pipe\n")); |
213 | 0 | fprintf(output, _(" \\qecho [STRING] write string to query output stream (see \\o)\n")); |
214 | 0 | fprintf(output, "\n"); |
215 | |
|
216 | 0 | fprintf(output, _("Conditional\n")); |
217 | 0 | fprintf(output, _(" \\if EXPR begin conditional block\n")); |
218 | 0 | fprintf(output, _(" \\elif EXPR alternative within current conditional block\n")); |
219 | 0 | fprintf(output, _(" \\else final alternative within current conditional block\n")); |
220 | 0 | fprintf(output, _(" \\endif end conditional block\n")); |
221 | 0 | fprintf(output, "\n"); |
222 | |
|
223 | 0 | fprintf(output, _("Informational\n")); |
224 | 0 | fprintf(output, _(" (options: S = show system objects, + = additional detail)\n")); |
225 | 0 | fprintf(output, _(" \\d[S+] list tables, views, and sequences\n")); |
226 | 0 | fprintf(output, _(" \\d[S+] NAME describe table, view, sequence, or index\n")); |
227 | 0 | fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n")); |
228 | 0 | fprintf(output, _(" \\dA[+] [PATTERN] list access methods\n")); |
229 | 0 | fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n")); |
230 | 0 | fprintf(output, _(" \\dc[S+] [PATTERN] list conversions\n")); |
231 | 0 | fprintf(output, _(" \\dC[+] [PATTERN] list casts\n")); |
232 | 0 | fprintf(output, _(" \\dd[S] [PATTERN] show object descriptions not displayed elsewhere\n")); |
233 | 0 | fprintf(output, _(" \\dD[S+] [PATTERN] list domains\n")); |
234 | 0 | fprintf(output, _(" \\ddp [PATTERN] list default privileges\n")); |
235 | 0 | fprintf(output, _(" \\dE[S+] [PATTERN] list foreign tables\n")); |
236 | 0 | fprintf(output, _(" \\det[+] [PATTERN] list foreign tables\n")); |
237 | 0 | fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n")); |
238 | 0 | fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\n")); |
239 | 0 | fprintf(output, _(" \\dew[+] [PATTERN] list foreign-data wrappers\n")); |
240 | 0 | fprintf(output, _(" \\df[anptw][S+] [PATRN] list [only agg/normal/procedures/trigger/window] functions\n")); |
241 | 0 | fprintf(output, _(" \\dF[+] [PATTERN] list text search configurations\n")); |
242 | 0 | fprintf(output, _(" \\dFd[+] [PATTERN] list text search dictionaries\n")); |
243 | 0 | fprintf(output, _(" \\dFp[+] [PATTERN] list text search parsers\n")); |
244 | 0 | fprintf(output, _(" \\dFt[+] [PATTERN] list text search templates\n")); |
245 | 0 | fprintf(output, _(" \\dg[S+] [PATTERN] list roles\n")); |
246 | 0 | fprintf(output, _(" \\di[S+] [PATTERN] list indexes\n")); |
247 | 0 | fprintf(output, _(" \\dl list large objects, same as \\lo_list\n")); |
248 | 0 | fprintf(output, _(" \\dL[S+] [PATTERN] list procedural languages\n")); |
249 | 0 | fprintf(output, _(" \\dm[S+] [PATTERN] list materialized views\n")); |
250 | 0 | fprintf(output, _(" \\dn[S+] [PATTERN] list schemas\n")); |
251 | 0 | fprintf(output, _(" \\do[S] [PATTERN] list operators\n")); |
252 | 0 | fprintf(output, _(" \\dO[S+] [PATTERN] list collations\n")); |
253 | 0 | fprintf(output, _(" \\dp [PATTERN] list table, view, and sequence access privileges\n")); |
254 | 0 | fprintf(output, _(" \\drds [PATRN1 [PATRN2]] list per-database role settings\n")); |
255 | 0 | fprintf(output, _(" \\dRp[+] [PATTERN] list replication publications\n")); |
256 | 0 | fprintf(output, _(" \\dRs[+] [PATTERN] list replication subscriptions\n")); |
257 | 0 | fprintf(output, _(" \\ds[S+] [PATTERN] list sequences\n")); |
258 | 0 | fprintf(output, _(" \\dt[S+] [PATTERN] list tables\n")); |
259 | 0 | fprintf(output, _(" \\dT[S+] [PATTERN] list data types\n")); |
260 | 0 | fprintf(output, _(" \\du[S+] [PATTERN] list roles\n")); |
261 | 0 | fprintf(output, _(" \\dv[S+] [PATTERN] list views\n")); |
262 | 0 | fprintf(output, _(" \\dx[+] [PATTERN] list extensions\n")); |
263 | 0 | fprintf(output, _(" \\dy [PATTERN] list event triggers\n")); |
264 | 0 | fprintf(output, _(" \\l[+] [PATTERN] list databases\n")); |
265 | 0 | fprintf(output, _(" \\sf[+] FUNCNAME show a function's definition\n")); |
266 | 0 | fprintf(output, _(" \\sv[+] VIEWNAME show a view's definition\n")); |
267 | 0 | fprintf(output, _(" \\z [PATTERN] same as \\dp\n")); |
268 | 0 | fprintf(output, "\n"); |
269 | |
|
270 | 0 | fprintf(output, _("Formatting\n")); |
271 | 0 | fprintf(output, _(" \\a toggle between unaligned and aligned output mode\n")); |
272 | 0 | fprintf(output, _(" \\C [STRING] set table title, or unset if none\n")); |
273 | 0 | fprintf(output, _(" \\f [STRING] show or set field separator for unaligned query output\n")); |
274 | 0 | fprintf(output, _(" \\H toggle HTML output mode (currently %s)\n"), |
275 | 0 | ON(pset.popt.topt.format == PRINT_HTML)); |
276 | 0 | fprintf(output, _(" \\pset [NAME [VALUE]] set table output option\n" |
277 | 0 | " (NAME := {border|columns|expanded|fieldsep|fieldsep_zero|\n" |
278 | 0 | " footer|format|linestyle|null|numericlocale|pager|\n" |
279 | 0 | " pager_min_lines|recordsep|recordsep_zero|tableattr|title|\n" |
280 | 0 | " tuples_only|unicode_border_linestyle|\n" |
281 | 0 | " unicode_column_linestyle|unicode_header_linestyle})\n")); |
282 | 0 | fprintf(output, _(" \\t [on|off] show only rows (currently %s)\n"), |
283 | 0 | ON(pset.popt.topt.tuples_only)); |
284 | 0 | fprintf(output, _(" \\T [STRING] set HTML <table> tag attributes, or unset if none\n")); |
285 | 0 | fprintf(output, _(" \\x [on|off|auto] toggle expanded output (currently %s)\n"), |
286 | 0 | pset.popt.topt.expanded == 2 ? "auto" : ON(pset.popt.topt.expanded)); |
287 | 0 | fprintf(output, "\n"); |
288 | |
|
289 | 0 | fprintf(output, _("Connection\n")); |
290 | 0 | if (currdb) |
291 | 0 | fprintf(output, _(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n" |
292 | 0 | " connect to new database (currently \"%s\")\n"), |
293 | 0 | currdb); |
294 | 0 | else |
295 | 0 | fprintf(output, _(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n" |
296 | 0 | " connect to new database (currently no connection)\n")); |
297 | 0 | fprintf(output, _(" \\conninfo display information about current connection\n")); |
298 | 0 | fprintf(output, _(" \\encoding [ENCODING] show or set client encoding\n")); |
299 | 0 | fprintf(output, _(" \\password [USERNAME] securely change the password for a user\n")); |
300 | 0 | fprintf(output, "\n"); |
301 | |
|
302 | 0 | fprintf(output, _("Operating System\n")); |
303 | 0 | fprintf(output, _(" \\cd [DIR] change the current working directory\n")); |
304 | 0 | fprintf(output, _(" \\setenv NAME [VALUE] set or unset environment variable\n")); |
305 | 0 | fprintf(output, _(" \\timing [on|off] toggle timing of commands (currently %s)\n"), |
306 | 0 | ON(pset.timing)); |
307 | 0 | fprintf(output, _(" \\! [COMMAND] execute command in shell or start interactive shell\n")); |
308 | 0 | fprintf(output, "\n"); |
309 | |
|
310 | 0 | fprintf(output, _("Variables\n")); |
311 | 0 | fprintf(output, _(" \\prompt [TEXT] NAME prompt user to set internal variable\n")); |
312 | 0 | fprintf(output, _(" \\set [NAME [VALUE]] set internal variable, or list all if no parameters\n")); |
313 | 0 | fprintf(output, _(" \\unset NAME unset (delete) internal variable\n")); |
314 | 0 | fprintf(output, "\n"); |
315 | |
|
316 | 0 | fprintf(output, _("Large Objects\n")); |
317 | 0 | fprintf(output, _(" \\lo_export LOBOID FILE\n" |
318 | 0 | " \\lo_import FILE [COMMENT]\n" |
319 | 0 | " \\lo_list\n" |
320 | 0 | " \\lo_unlink LOBOID large object operations\n")); |
321 | |
|
322 | 0 | ClosePager(output); |
323 | 0 | } |
324 | | |
325 | | |
326 | | /* |
327 | | * helpVariables |
328 | | * |
329 | | * show list of available variables (options) from command line |
330 | | */ |
331 | | void |
332 | | helpVariables(unsigned short int pager) |
333 | 0 | { |
334 | 0 | FILE *output; |
335 | | |
336 | | /* |
337 | | * Keep this line count in sync with the number of lines printed below! |
338 | | * Use "psql --help=variables | wc" to count correctly; but notice that |
339 | | * Windows builds currently print one more line than non-Windows builds. |
340 | | * Using the larger number is fine. |
341 | | */ |
342 | 0 | output = PageOutput(156, pager ? &(pset.popt.topt) : NULL); |
343 | |
|
344 | 0 | fprintf(output, _("List of specially treated variables\n\n")); |
345 | |
|
346 | 0 | fprintf(output, _("psql variables:\n")); |
347 | 0 | fprintf(output, _("Usage:\n")); |
348 | 0 | fprintf(output, _(" psql --set=NAME=VALUE\n or \\set NAME VALUE inside psql\n\n")); |
349 | |
|
350 | 0 | fprintf(output, _(" AUTOCOMMIT\n" |
351 | 0 | " if set, successful SQL commands are automatically committed\n")); |
352 | 0 | fprintf(output, _(" COMP_KEYWORD_CASE\n" |
353 | 0 | " determines the case used to complete SQL key words\n" |
354 | 0 | " [lower, upper, preserve-lower, preserve-upper]\n")); |
355 | 0 | fprintf(output, _(" DBNAME\n" |
356 | 0 | " the currently connected database name\n")); |
357 | 0 | fprintf(output, _(" ECHO\n" |
358 | 0 | " controls what input is written to standard output\n" |
359 | 0 | " [all, errors, none, queries]\n")); |
360 | 0 | fprintf(output, _(" ECHO_HIDDEN\n" |
361 | 0 | " if set, display internal queries executed by backslash commands;\n" |
362 | 0 | " if set to \"noexec\", just show them without execution\n")); |
363 | 0 | fprintf(output, _(" ENCODING\n" |
364 | 0 | " current client character set encoding\n")); |
365 | 0 | fprintf(output, _(" ERROR\n" |
366 | 0 | " true if last query failed, else false\n")); |
367 | 0 | fprintf(output, _(" FETCH_COUNT\n" |
368 | 0 | " the number of result rows to fetch and display at a time (0 = unlimited)\n")); |
369 | 0 | fprintf(output, _(" HISTCONTROL\n" |
370 | 0 | " controls command history [ignorespace, ignoredups, ignoreboth]\n")); |
371 | 0 | fprintf(output, _(" HISTFILE\n" |
372 | 0 | " file name used to store the command history\n")); |
373 | 0 | fprintf(output, _(" HISTSIZE\n" |
374 | 0 | " maximum number of commands to store in the command history\n")); |
375 | 0 | fprintf(output, _(" HOST\n" |
376 | 0 | " the currently connected database server host\n")); |
377 | 0 | fprintf(output, _(" IGNOREEOF\n" |
378 | 0 | " number of EOFs needed to terminate an interactive session\n")); |
379 | 0 | fprintf(output, _(" LASTOID\n" |
380 | 0 | " value of the last affected OID\n")); |
381 | 0 | fprintf(output, _(" LAST_ERROR_MESSAGE\n" |
382 | 0 | " LAST_ERROR_SQLSTATE\n" |
383 | 0 | " message and SQLSTATE of last error, or empty string and \"00000\" if none\n")); |
384 | 0 | fprintf(output, _(" ON_ERROR_ROLLBACK\n" |
385 | 0 | " if set, an error doesn't stop a transaction (uses implicit savepoints)\n")); |
386 | 0 | fprintf(output, _(" ON_ERROR_STOP\n" |
387 | 0 | " stop batch execution after error\n")); |
388 | 0 | fprintf(output, _(" PORT\n" |
389 | 0 | " server port of the current connection\n")); |
390 | 0 | fprintf(output, _(" PROMPT1\n" |
391 | 0 | " specifies the standard psql prompt\n")); |
392 | 0 | fprintf(output, _(" PROMPT2\n" |
393 | 0 | " specifies the prompt used when a statement continues from a previous line\n")); |
394 | 0 | fprintf(output, _(" PROMPT3\n" |
395 | 0 | " specifies the prompt used during COPY ... FROM STDIN\n")); |
396 | 0 | fprintf(output, _(" QUIET\n" |
397 | 0 | " run quietly (same as -q option)\n")); |
398 | 0 | fprintf(output, _(" ROW_COUNT\n" |
399 | 0 | " number of rows returned or affected by last query, or 0\n")); |
400 | 0 | fprintf(output, _(" SERVER_VERSION_NAME\n" |
401 | 0 | " SERVER_VERSION_NUM\n" |
402 | 0 | " server's version (in short string or numeric format)\n")); |
403 | 0 | fprintf(output, _(" SHOW_CONTEXT\n" |
404 | 0 | " controls display of message context fields [never, errors, always]\n")); |
405 | 0 | fprintf(output, _(" SINGLELINE\n" |
406 | 0 | " if set, end of line terminates SQL commands (same as -S option)\n")); |
407 | 0 | fprintf(output, _(" SINGLESTEP\n" |
408 | 0 | " single-step mode (same as -s option)\n")); |
409 | 0 | fprintf(output, _(" SQLSTATE\n" |
410 | 0 | " SQLSTATE of last query, or \"00000\" if no error\n")); |
411 | 0 | fprintf(output, _(" USER\n" |
412 | 0 | " the currently connected database user\n")); |
413 | 0 | fprintf(output, _(" VERBOSITY\n" |
414 | 0 | " controls verbosity of error reports [default, verbose, terse]\n")); |
415 | 0 | fprintf(output, _(" VERSION\n" |
416 | 0 | " VERSION_NAME\n" |
417 | 0 | " VERSION_NUM\n" |
418 | 0 | " psql's version (in verbose string, short string, or numeric format)\n")); |
419 | |
|
420 | 0 | fprintf(output, _("\nDisplay settings:\n")); |
421 | 0 | fprintf(output, _("Usage:\n")); |
422 | 0 | fprintf(output, _(" psql --pset=NAME[=VALUE]\n or \\pset NAME [VALUE] inside psql\n\n")); |
423 | |
|
424 | 0 | fprintf(output, _(" border\n" |
425 | 0 | " border style (number)\n")); |
426 | 0 | fprintf(output, _(" columns\n" |
427 | 0 | " target width for the wrapped format\n")); |
428 | 0 | fprintf(output, _(" expanded (or x)\n" |
429 | 0 | " expanded output [on, off, auto]\n")); |
430 | 0 | fprintf(output, _(" fieldsep\n" |
431 | 0 | " field separator for unaligned output (default \"%s\")\n"), |
432 | 0 | DEFAULT_FIELD_SEP); |
433 | 0 | fprintf(output, _(" fieldsep_zero\n" |
434 | 0 | " set field separator for unaligned output to a zero byte\n")); |
435 | 0 | fprintf(output, _(" footer\n" |
436 | 0 | " enable or disable display of the table footer [on, off]\n")); |
437 | 0 | fprintf(output, _(" format\n" |
438 | 0 | " set output format [unaligned, aligned, wrapped, html, asciidoc, ...]\n")); |
439 | 0 | fprintf(output, _(" linestyle\n" |
440 | 0 | " set the border line drawing style [ascii, old-ascii, unicode]\n")); |
441 | 0 | fprintf(output, _(" null\n" |
442 | 0 | " set the string to be printed in place of a null value\n")); |
443 | 0 | fprintf(output, _(" numericlocale\n" |
444 | 0 | " enable display of a locale-specific character to separate groups of digits\n")); |
445 | 0 | fprintf(output, _(" pager\n" |
446 | 0 | " control when an external pager is used [yes, no, always]\n")); |
447 | 0 | fprintf(output, _(" recordsep\n" |
448 | 0 | " record (line) separator for unaligned output\n")); |
449 | 0 | fprintf(output, _(" recordsep_zero\n" |
450 | 0 | " set record separator for unaligned output to a zero byte\n")); |
451 | 0 | fprintf(output, _(" tableattr (or T)\n" |
452 | 0 | " specify attributes for table tag in html format, or proportional\n" |
453 | 0 | " column widths for left-aligned data types in latex-longtable format\n")); |
454 | 0 | fprintf(output, _(" title\n" |
455 | 0 | " set the table title for subsequently printed tables\n")); |
456 | 0 | fprintf(output, _(" tuples_only\n" |
457 | 0 | " if set, only actual table data is shown\n")); |
458 | 0 | fprintf(output, _(" unicode_border_linestyle\n" |
459 | 0 | " unicode_column_linestyle\n" |
460 | 0 | " unicode_header_linestyle\n" |
461 | 0 | " set the style of Unicode line drawing [single, double]\n")); |
462 | |
|
463 | 0 | fprintf(output, _("\nEnvironment variables:\n")); |
464 | 0 | fprintf(output, _("Usage:\n")); |
465 | |
|
466 | 0 | #ifndef WIN32 |
467 | 0 | fprintf(output, _(" NAME=VALUE [NAME=VALUE] psql ...\n or \\setenv NAME [VALUE] inside psql\n\n")); |
468 | | #else |
469 | | fprintf(output, _(" set NAME=VALUE\n psql ...\n or \\setenv NAME [VALUE] inside psql\n\n")); |
470 | | #endif |
471 | |
|
472 | 0 | fprintf(output, _(" COLUMNS\n" |
473 | 0 | " number of columns for wrapped format\n")); |
474 | 0 | fprintf(output, _(" PGAPPNAME\n" |
475 | 0 | " same as the application_name connection parameter\n")); |
476 | 0 | fprintf(output, _(" PGDATABASE\n" |
477 | 0 | " same as the dbname connection parameter\n")); |
478 | 0 | fprintf(output, _(" PGHOST\n" |
479 | 0 | " same as the host connection parameter\n")); |
480 | 0 | fprintf(output, _(" PGPASSWORD\n" |
481 | 0 | " connection password (not recommended)\n")); |
482 | 0 | fprintf(output, _(" PGPASSFILE\n" |
483 | 0 | " password file name\n")); |
484 | 0 | fprintf(output, _(" PGPORT\n" |
485 | 0 | " same as the port connection parameter\n")); |
486 | 0 | fprintf(output, _(" PGUSER\n" |
487 | 0 | " same as the user connection parameter\n")); |
488 | 0 | fprintf(output, _(" PSQL_EDITOR, EDITOR, VISUAL\n" |
489 | 0 | " editor used by the \\e, \\ef, and \\ev commands\n")); |
490 | 0 | fprintf(output, _(" PSQL_EDITOR_LINENUMBER_ARG\n" |
491 | 0 | " how to specify a line number when invoking the editor\n")); |
492 | 0 | fprintf(output, _(" PSQL_HISTORY\n" |
493 | 0 | " alternative location for the command history file\n")); |
494 | 0 | fprintf(output, _(" PSQL_PAGER, PAGER\n" |
495 | 0 | " name of external pager program\n")); |
496 | 0 | fprintf(output, _(" PSQLRC\n" |
497 | 0 | " alternative location for the user's .psqlrc file\n")); |
498 | 0 | fprintf(output, _(" SHELL\n" |
499 | 0 | " shell used by the \\! command\n")); |
500 | 0 | fprintf(output, _(" TMPDIR\n" |
501 | 0 | " directory for temporary files\n")); |
502 | |
|
503 | 0 | ClosePager(output); |
504 | 0 | } |
505 | | |
506 | | |
507 | | /* |
508 | | * helpSQL -- help with SQL commands |
509 | | * |
510 | | * Note: we assume caller removed any trailing spaces in "topic". |
511 | | */ |
512 | | void |
513 | | helpSQL(const char *topic, unsigned short int pager) |
514 | 0 | { |
515 | 0 | #define VALUE_OR_NULL(a) ((a) ? (a) : "") |
516 | |
|
517 | 0 | if (!topic || strlen(topic) == 0) |
518 | 0 | { |
519 | | /* Print all the available command names */ |
520 | 0 | int screen_width; |
521 | 0 | int ncolumns; |
522 | 0 | int nrows; |
523 | 0 | FILE *output; |
524 | 0 | int i; |
525 | 0 | int j; |
526 | |
|
527 | 0 | #ifdef TIOCGWINSZ |
528 | 0 | struct winsize screen_size; |
529 | |
|
530 | 0 | if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) |
531 | 0 | screen_width = 80; /* ioctl failed, assume 80 */ |
532 | 0 | else |
533 | 0 | screen_width = screen_size.ws_col; |
534 | | #else |
535 | | screen_width = 80; /* default assumption */ |
536 | | #endif |
537 | |
|
538 | 0 | ncolumns = (screen_width - 3) / (QL_MAX_CMD_LEN + 1); |
539 | 0 | ncolumns = Max(ncolumns, 1); |
540 | 0 | nrows = (QL_HELP_COUNT + (ncolumns - 1)) / ncolumns; |
541 | |
|
542 | 0 | output = PageOutput(nrows + 1, pager ? &(pset.popt.topt) : NULL); |
543 | |
|
544 | 0 | fputs(_("Available help:\n"), output); |
545 | |
|
546 | 0 | for (i = 0; i < nrows; i++) |
547 | 0 | { |
548 | 0 | fprintf(output, " "); |
549 | 0 | for (j = 0; j < ncolumns - 1; j++) |
550 | 0 | fprintf(output, "%-*s", |
551 | 0 | QL_MAX_CMD_LEN + 1, |
552 | 0 | VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd)); |
553 | 0 | if (i + j * nrows < QL_HELP_COUNT) |
554 | 0 | fprintf(output, "%s", |
555 | 0 | VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd)); |
556 | 0 | fputc('\n', output); |
557 | 0 | } |
558 | |
|
559 | 0 | ClosePager(output); |
560 | 0 | } |
561 | 0 | else |
562 | 0 | { |
563 | 0 | int i, |
564 | 0 | j, |
565 | 0 | x = 0; |
566 | 0 | bool help_found = false; |
567 | 0 | FILE *output = NULL; |
568 | 0 | size_t len, |
569 | 0 | wordlen; |
570 | 0 | int nl_count = 0; |
571 | | |
572 | | /* |
573 | | * We first try exact match, then first + second words, then first |
574 | | * word only. |
575 | | */ |
576 | 0 | len = strlen(topic); |
577 | |
|
578 | 0 | for (x = 1; x <= 3; x++) |
579 | 0 | { |
580 | 0 | if (x > 1) /* Nothing on first pass - try the opening |
581 | | * word(s) */ |
582 | 0 | { |
583 | 0 | wordlen = j = 1; |
584 | 0 | while (topic[j] != ' ' && j++ < len) |
585 | 0 | wordlen++; |
586 | 0 | if (x == 2) |
587 | 0 | { |
588 | 0 | j++; |
589 | 0 | while (topic[j] != ' ' && j++ <= len) |
590 | 0 | wordlen++; |
591 | 0 | } |
592 | 0 | if (wordlen >= len) /* Don't try again if the same word */ |
593 | 0 | { |
594 | 0 | if (!output) |
595 | 0 | output = PageOutput(nl_count, pager ? &(pset.popt.topt) : NULL); |
596 | 0 | break; |
597 | 0 | } |
598 | 0 | len = wordlen; |
599 | 0 | } |
600 | | |
601 | | /* Count newlines for pager */ |
602 | 0 | for (i = 0; QL_HELP[i].cmd; i++) |
603 | 0 | { |
604 | 0 | if (pg_strncasecmp(topic, QL_HELP[i].cmd, len) == 0 || |
605 | 0 | strcmp(topic, "*") == 0) |
606 | 0 | { |
607 | 0 | nl_count += 5 + QL_HELP[i].nl_count; |
608 | | |
609 | | /* If we have an exact match, exit. Fixes \h SELECT */ |
610 | 0 | if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0) |
611 | 0 | break; |
612 | 0 | } |
613 | 0 | } |
614 | |
|
615 | 0 | if (!output) |
616 | 0 | output = PageOutput(nl_count, pager ? &(pset.popt.topt) : NULL); |
617 | |
|
618 | 0 | for (i = 0; QL_HELP[i].cmd; i++) |
619 | 0 | { |
620 | 0 | if (pg_strncasecmp(topic, QL_HELP[i].cmd, len) == 0 || |
621 | 0 | strcmp(topic, "*") == 0) |
622 | 0 | { |
623 | 0 | PQExpBufferData buffer; |
624 | |
|
625 | 0 | initPQExpBuffer(&buffer); |
626 | 0 | QL_HELP[i].syntaxfunc(&buffer); |
627 | 0 | help_found = true; |
628 | 0 | fprintf(output, _("Command: %s\n" |
629 | 0 | "Description: %s\n" |
630 | 0 | "Syntax:\n%s\n\n"), |
631 | 0 | QL_HELP[i].cmd, |
632 | 0 | _(QL_HELP[i].help), |
633 | 0 | buffer.data); |
634 | 0 | termPQExpBuffer(&buffer); |
635 | | /* If we have an exact match, exit. Fixes \h SELECT */ |
636 | 0 | if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0) |
637 | 0 | break; |
638 | 0 | } |
639 | 0 | } |
640 | 0 | if (help_found) /* Don't keep trying if we got a match */ |
641 | 0 | break; |
642 | 0 | } |
643 | |
|
644 | 0 | if (!help_found) |
645 | 0 | fprintf(output, _("No help available for \"%s\".\nTry \\h with no arguments to see available help.\n"), topic); |
646 | |
|
647 | 0 | ClosePager(output); |
648 | 0 | } |
649 | 0 | } |
650 | | |
651 | | |
652 | | |
653 | | void |
654 | | print_copyright(void) |
655 | 0 | { |
656 | 0 | puts( |
657 | 0 | "PostgreSQL Database Management System\n" |
658 | 0 | "(formerly known as Postgres, then as Postgres95)\n\n" |
659 | 0 | "Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group\n\n" |
660 | 0 | "Portions Copyright (c) 1994, The Regents of the University of California\n\n" |
661 | 0 | "Permission to use, copy, modify, and distribute this software and its\n" |
662 | 0 | "documentation for any purpose, without fee, and without a written agreement\n" |
663 | 0 | "is hereby granted, provided that the above copyright notice and this\n" |
664 | 0 | "paragraph and the following two paragraphs appear in all copies.\n\n" |
665 | 0 | "IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR\n" |
666 | 0 | "DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING\n" |
667 | 0 | "LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS\n" |
668 | 0 | "DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE\n" |
669 | 0 | "POSSIBILITY OF SUCH DAMAGE.\n\n" |
670 | 0 | "THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,\n" |
671 | 0 | "INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\n" |
672 | 0 | "AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS\n" |
673 | 0 | "ON AN \"AS IS\" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO\n" |
674 | 0 | "PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.\n" |
675 | 0 | ); |
676 | 0 | } |