Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
8447148a
Commit
8447148a
authored
Jul 24, 1997
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
psql: Add PAGER for \h and \?,\C fix, indices spell fix.
parent
4d8a5efc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
49 deletions
+78
-49
src/bin/psql/psql.c
src/bin/psql/psql.c
+78
-49
No files found.
src/bin/psql/psql.c
View file @
8447148a
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.7
7 1997/07/14 22:08:56
momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.7
8 1997/07/24 20:01:33
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -153,40 +153,52 @@ on(bool f)
...
@@ -153,40 +153,52 @@ on(bool f)
static
void
static
void
slashUsage
(
PsqlSettings
*
ps
)
slashUsage
(
PsqlSettings
*
ps
)
{
{
int
ch
;
int
usePipe
=
0
;
char
*
pagerenv
;
fprintf
(
stderr
,
"
\\
? -- help
\n
"
);
FILE
*
fout
;
fprintf
(
stderr
,
"
\\
a -- toggle field-alignment (currenty %s)
\n
"
,
on
(
ps
->
opt
.
align
));
fprintf
(
stderr
,
"
\\
C [<captn>] -- set html3 caption (currently '%s')
\n
"
,
ps
->
opt
.
caption
?
ps
->
opt
.
caption
:
""
);
if
((
pagerenv
=
getenv
(
"PAGER"
))
&&
(
pagerenv
[
0
]
!=
'\0'
)
&&
\
fprintf
(
stderr
,
"
\\
connect <dbname|-> <user> -- connect to new database (currently '%s')
\n
"
,
PQdb
(
ps
->
db
));
(
fout
=
popen
(
pagerenv
,
"w"
)))
fprintf
(
stderr
,
"
\\
copy table {from | to} <fname>
\n
"
);
{
fprintf
(
stderr
,
"
\\
d [<table>] -- list tables and indicies in database or columns in <table>, * for all
\n
"
);
usePipe
=
1
;
fprintf
(
stderr
,
"
\\
di -- list only indicies in database
\n
"
);
pqsignal
(
SIGPIPE
,
SIG_IGN
);
fprintf
(
stderr
,
"
\\
ds -- list only sequences in database
\n
"
);
}
fprintf
(
stderr
,
"
\\
dt -- list only tables in database
\n
"
);
else
fprintf
(
stderr
,
"
\\
e [<fname>] -- edit the current query buffer or <fname>,
\\
E execute too
\n
"
);
fout
=
stderr
;
fprintf
(
stderr
,
"
\\
f [<sep>] -- change field separater (currently '%s')
\n
"
,
ps
->
opt
.
fieldSep
);
fprintf
(
stderr
,
"
\\
g [<fname>] [|<cmd>] -- send query to backend [and results in <fname> or pipe]
\n
"
);
fprintf
(
fout
,
"
\\
? -- help
\n
"
);
fprintf
(
stderr
,
"
\\
h [<cmd>] -- help on syntax of sql commands, * for all commands
\n
"
);
fprintf
(
fout
,
"
\\
a -- toggle field-alignment (currenty %s)
\n
"
,
on
(
ps
->
opt
.
align
));
fprintf
(
stderr
,
"
\\
H -- toggle html3 output (currently %s)
\n
"
,
on
(
ps
->
opt
.
html3
));
fprintf
(
fout
,
"
\\
C [<captn>] -- set html3 caption (currently '%s')
\n
"
,
ps
->
opt
.
caption
?
ps
->
opt
.
caption
:
""
);
fprintf
(
stderr
,
"
\\
i <fname> -- read and execute queries from filename
\n
"
);
fprintf
(
fout
,
"
\\
connect <dbname|-> <user> -- connect to new database (currently '%s')
\n
"
,
PQdb
(
ps
->
db
));
fprintf
(
stderr
,
"
\\
l -- list all databases
\n
"
);
fprintf
(
fout
,
"
\\
copy table {from | to} <fname>
\n
"
);
fprintf
(
stderr
,
"
\\
m -- toggle monitor-like table display (currently %s)
\n
"
,
on
(
ps
->
opt
.
standard
));
fprintf
(
fout
,
"
\\
d [<table>] -- list tables and indices in database or columns in <table>, * for all
\n
"
);
fprintf
(
stderr
,
"
\\
o [<fname>] [|<cmd>] -- send all query results to stdout, <fname>, or pipe
\n
"
);
fprintf
(
fout
,
"
\\
di -- list only indices in database
\n
"
);
fprintf
(
stderr
,
"
\\
p -- print the current query buffer
\n
"
);
fprintf
(
fout
,
"
\\
ds -- list only sequences in database
\n
"
);
fprintf
(
fout
,
"
\\
dt -- list only tables in database
\n
"
);
fprintf
(
stderr
,
"Press ENTER to continue"
);
fprintf
(
fout
,
"
\\
e [<fname>] -- edit the current query buffer or <fname>,
\\
E execute too
\n
"
);
/* eat up any extra characters typed before ENTER */
fprintf
(
fout
,
"
\\
f [<sep>] -- change field separater (currently '%s')
\n
"
,
ps
->
opt
.
fieldSep
);
while
((
ch
=
fgetc
(
stdin
))
!=
'\r'
&&
ch
!=
'\n'
)
fprintf
(
fout
,
"
\\
g [<fname>] [|<cmd>] -- send query to backend [and results in <fname> or pipe]
\n
"
);
;
fprintf
(
fout
,
"
\\
h [<cmd>] -- help on syntax of sql commands, * for all commands
\n
"
);
fprintf
(
stderr
,
"
\\
q -- quit
\n
"
);
fprintf
(
fout
,
"
\\
H -- toggle html3 output (currently %s)
\n
"
,
on
(
ps
->
opt
.
html3
));
fprintf
(
stderr
,
"
\\
r -- reset(clear) the query buffer
\n
"
);
fprintf
(
fout
,
"
\\
i <fname> -- read and execute queries from filename
\n
"
);
fprintf
(
stderr
,
"
\\
s [<fname>] -- print history or save it in <fname>
\n
"
);
fprintf
(
fout
,
"
\\
l -- list all databases
\n
"
);
fprintf
(
stderr
,
"
\\
t -- toggle table headings and row count (currently %s)
\n
"
,
on
(
ps
->
opt
.
header
));
fprintf
(
fout
,
"
\\
m -- toggle monitor-like table display (currently %s)
\n
"
,
on
(
ps
->
opt
.
standard
));
fprintf
(
stderr
,
"
\\
T [<html>] -- set html3.0 <table ...> options (currently '%s')
\n
"
,
ps
->
opt
.
tableOpt
?
ps
->
opt
.
tableOpt
:
""
);
fprintf
(
fout
,
"
\\
o [<fname>] [|<cmd>] -- send all query results to stdout, <fname>, or pipe
\n
"
);
fprintf
(
stderr
,
"
\\
x -- toggle expanded output (currently %s)
\n
"
,
on
(
ps
->
opt
.
expanded
));
fprintf
(
fout
,
"
\\
p -- print the current query buffer
\n
"
);
fprintf
(
stderr
,
"
\\
z -- list current grant/revoke permissions
\n
"
);
fprintf
(
fout
,
"
\\
q -- quit
\n
"
);
fprintf
(
stderr
,
"
\\
! [<cmd>] -- shell escape or command
\n
"
);
fprintf
(
fout
,
"
\\
r -- reset(clear) the query buffer
\n
"
);
fprintf
(
fout
,
"
\\
s [<fname>] -- print history or save it in <fname>
\n
"
);
fprintf
(
fout
,
"
\\
t -- toggle table headings and row count (currently %s)
\n
"
,
on
(
ps
->
opt
.
header
));
fprintf
(
fout
,
"
\\
T [<html>] -- set html3.0 <table ...> options (currently '%s')
\n
"
,
ps
->
opt
.
tableOpt
?
ps
->
opt
.
tableOpt
:
""
);
fprintf
(
fout
,
"
\\
x -- toggle expanded output (currently %s)
\n
"
,
on
(
ps
->
opt
.
expanded
));
fprintf
(
fout
,
"
\\
z -- list current grant/revoke permissions
\n
"
);
fprintf
(
fout
,
"
\\
! [<cmd>] -- shell escape or command
\n
"
);
if
(
usePipe
)
{
pclose
(
fout
);
pqsignal
(
SIGPIPE
,
SIG_DFL
);
}
}
}
static
PGresult
*
static
PGresult
*
...
@@ -326,12 +338,12 @@ tableList(PsqlSettings * ps, bool deep_tablelist, char info_type)
...
@@ -326,12 +338,12 @@ tableList(PsqlSettings * ps, bool deep_tablelist, char info_type)
switch
(
info_type
)
{
switch
(
info_type
)
{
case
't'
:
fprintf
(
stderr
,
"Couldn't find any tables!
\n
"
);
case
't'
:
fprintf
(
stderr
,
"Couldn't find any tables!
\n
"
);
break
;
break
;
case
'i'
:
fprintf
(
stderr
,
"Couldn't find any indic
i
es!
\n
"
);
case
'i'
:
fprintf
(
stderr
,
"Couldn't find any indices!
\n
"
);
break
;
break
;
case
'S'
:
fprintf
(
stderr
,
"Couldn't find any sequences!
\n
"
);
case
'S'
:
fprintf
(
stderr
,
"Couldn't find any sequences!
\n
"
);
break
;
break
;
case
'b'
:
case
'b'
:
default:
fprintf
(
stderr
,
"Couldn't find any tables, sequences or indic
i
es!
\n
"
);
default:
fprintf
(
stderr
,
"Couldn't find any tables, sequences or indices!
\n
"
);
break
;
break
;
}
}
return
(
-
1
);
return
(
-
1
);
...
@@ -1030,18 +1042,38 @@ do_help(const char *topic)
...
@@ -1030,18 +1042,38 @@ do_help(const char *topic)
int
i
;
/* Index into QL_HELP[] */
int
i
;
/* Index into QL_HELP[] */
bool
help_found
;
/* We found the help he asked for */
bool
help_found
;
/* We found the help he asked for */
int
usePipe
=
0
;
char
*
pagerenv
;
FILE
*
fout
;
if
((
pagerenv
=
getenv
(
"PAGER"
))
&&
(
pagerenv
[
0
]
!=
'\0'
)
&&
\
(
fout
=
popen
(
pagerenv
,
"w"
)))
{
usePipe
=
1
;
pqsignal
(
SIGPIPE
,
SIG_IGN
);
}
else
fout
=
stderr
;
help_found
=
false
;
/* Haven't found it yet */
help_found
=
false
;
/* Haven't found it yet */
for
(
i
=
0
;
QL_HELP
[
i
].
cmd
;
i
++
)
{
for
(
i
=
0
;
QL_HELP
[
i
].
cmd
;
i
++
)
{
if
(
strcmp
(
QL_HELP
[
i
].
cmd
,
topic
)
==
0
||
if
(
strcmp
(
QL_HELP
[
i
].
cmd
,
topic
)
==
0
||
strcmp
(
topic
,
"*"
)
==
0
)
{
strcmp
(
topic
,
"*"
)
==
0
)
{
help_found
=
true
;
help_found
=
true
;
printf
(
"Command: %s
\n
"
,
QL_HELP
[
i
].
cmd
);
fprintf
(
fout
,
"Command: %s
\n
"
,
QL_HELP
[
i
].
cmd
);
printf
(
"Description: %s
\n
"
,
QL_HELP
[
i
].
help
);
fprintf
(
fout
,
"Description: %s
\n
"
,
QL_HELP
[
i
].
help
);
printf
(
"Syntax:
\n
"
);
fprintf
(
fout
,
"Syntax:
\n
"
);
printf
(
"%s
\n
"
,
QL_HELP
[
i
].
syntax
);
fprintf
(
fout
,
"%s
\n
"
,
QL_HELP
[
i
].
syntax
);
printf
(
"
\n
"
);
fprintf
(
fout
,
"
\n
"
);
}
}
}
}
if
(
usePipe
)
{
pclose
(
fout
);
pqsignal
(
SIGPIPE
,
SIG_DFL
);
}
if
(
!
help_found
)
if
(
!
help_found
)
printf
(
"command not found, "
printf
(
"command not found, "
"try
\\
h with no arguments to see available help
\n
"
);
"try
\\
h with no arguments to see available help
\n
"
);
...
@@ -1145,14 +1177,11 @@ HandleSlashCmds(PsqlSettings * settings,
...
@@ -1145,14 +1177,11 @@ HandleSlashCmds(PsqlSettings * settings,
break
;
break
;
case
'C'
:
/* define new caption */
case
'C'
:
/* define new caption */
if
(
settings
->
opt
.
caption
)
if
(
settings
->
opt
.
caption
)
free
(
settings
->
opt
.
caption
);
if
(
!
optarg
)
{
{
if
(
settings
->
opt
.
caption
)
free
(
settings
->
opt
.
caption
);
free
(
settings
->
opt
.
caption
);
settings
->
opt
.
caption
=
NULL
;
settings
->
opt
.
caption
=
NULL
;
}
}
else
if
(
!
(
settings
->
opt
.
caption
=
strdup
(
optarg
)))
{
if
(
optarg
&&
!
(
settings
->
opt
.
caption
=
strdup
(
optarg
)))
{
perror
(
"malloc"
);
perror
(
"malloc"
);
exit
(
1
);
exit
(
1
);
}
}
...
@@ -1198,11 +1227,11 @@ HandleSlashCmds(PsqlSettings * settings,
...
@@ -1198,11 +1227,11 @@ HandleSlashCmds(PsqlSettings * settings,
case
'd'
:
/* \d describe tables or columns in a table */
case
'd'
:
/* \d describe tables or columns in a table */
if
(
strncmp
(
cmd
,
"dt"
,
2
)
==
0
)
{
/* only tables */
if
(
strncmp
(
cmd
,
"dt"
,
2
)
==
0
)
{
/* only tables */
tableList
(
settings
,
0
,
't'
);
tableList
(
settings
,
0
,
't'
);
}
else
if
(
strncmp
(
cmd
,
"di"
,
2
)
==
0
)
{
/* only indic
i
es */
}
else
if
(
strncmp
(
cmd
,
"di"
,
2
)
==
0
)
{
/* only indices */
tableList
(
settings
,
0
,
'i'
);
tableList
(
settings
,
0
,
'i'
);
}
else
if
(
strncmp
(
cmd
,
"ds"
,
2
)
==
0
)
{
/* only sequences */
}
else
if
(
strncmp
(
cmd
,
"ds"
,
2
)
==
0
)
{
/* only sequences */
tableList
(
settings
,
0
,
'S'
);
tableList
(
settings
,
0
,
'S'
);
}
else
if
(
!
optarg
)
{
/* show tables, sequences and indic
i
es */
}
else
if
(
!
optarg
)
{
/* show tables, sequences and indices */
tableList
(
settings
,
0
,
'b'
);
tableList
(
settings
,
0
,
'b'
);
}
else
if
(
strcmp
(
optarg
,
"*"
)
==
0
)
{
/* show everything */
}
else
if
(
strcmp
(
optarg
,
"*"
)
==
0
)
{
/* show everything */
tableList
(
settings
,
0
,
'b'
);
tableList
(
settings
,
0
,
'b'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment