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
f6689a32
Commit
f6689a32
authored
Jan 12, 2000
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed a few "fixes" and bugs. Adjusted messages and options to GNU suggestions.
parent
267c6c7f
Changes
24
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
613 additions
and
592 deletions
+613
-592
doc/src/sgml/ref/createuser.sgml
doc/src/sgml/ref/createuser.sgml
+2
-2
doc/src/sgml/ref/dropuser.sgml
doc/src/sgml/ref/dropuser.sgml
+2
-2
doc/src/sgml/ref/psql-ref.sgml
doc/src/sgml/ref/psql-ref.sgml
+13
-76
src/bin/psql/command.c
src/bin/psql/command.c
+70
-39
src/bin/psql/common.c
src/bin/psql/common.c
+6
-4
src/bin/psql/copy.c
src/bin/psql/copy.c
+51
-24
src/bin/psql/describe.c
src/bin/psql/describe.c
+149
-104
src/bin/psql/describe.h
src/bin/psql/describe.h
+4
-4
src/bin/psql/help.c
src/bin/psql/help.c
+73
-67
src/bin/psql/large_obj.c
src/bin/psql/large_obj.c
+21
-10
src/bin/psql/large_obj.h
src/bin/psql/large_obj.h
+1
-1
src/bin/psql/mainloop.c
src/bin/psql/mainloop.c
+3
-5
src/bin/psql/print.c
src/bin/psql/print.c
+1
-1
src/bin/psql/prompt.c
src/bin/psql/prompt.c
+3
-12
src/bin/psql/settings.h
src/bin/psql/settings.h
+1
-0
src/bin/psql/startup.c
src/bin/psql/startup.c
+56
-83
src/bin/psql/tab-complete.c
src/bin/psql/tab-complete.c
+11
-9
src/bin/scripts/createdb
src/bin/scripts/createdb
+19
-18
src/bin/scripts/createlang.sh
src/bin/scripts/createlang.sh
+30
-37
src/bin/scripts/createuser
src/bin/scripts/createuser
+19
-20
src/bin/scripts/dropdb
src/bin/scripts/dropdb
+12
-14
src/bin/scripts/droplang
src/bin/scripts/droplang
+27
-23
src/bin/scripts/dropuser
src/bin/scripts/dropuser
+11
-12
src/bin/scripts/vacuumdb
src/bin/scripts/vacuumdb
+28
-25
No files found.
doc/src/sgml/ref/createuser.sgml
View file @
f6689a32
<!--
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createuser.sgml,v 1.
7 1999/12/07 22:41:41 momjian
Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createuser.sgml,v 1.
8 2000/01/12 19:36:34 petere
Exp $
Postgres documentation
Postgres documentation
-->
-->
...
@@ -177,7 +177,7 @@ createuser [ <replaceable class="parameter">options</replaceable> ] [ <replaceab
...
@@ -177,7 +177,7 @@ createuser [ <replaceable class="parameter">options</replaceable> ] [ <replaceab
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><computeroutput>createuser:
Creation of user "<replaceable class="parameter">username</replaceable>" failed.
</computeroutput></term>
<term><computeroutput>createuser:
creation of user "<replaceable class="parameter">username</replaceable>" failed
</computeroutput></term>
<listitem>
<listitem>
<para>
<para>
Something went wrong. The user was not created.
Something went wrong. The user was not created.
...
...
doc/src/sgml/ref/dropuser.sgml
View file @
f6689a32
<!--
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.
2 1999/12/07 22:41:41 momjian
Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.
3 2000/01/12 19:36:34 petere
Exp $
Postgres documentation
Postgres documentation
-->
-->
...
@@ -127,7 +127,7 @@ dropuser [ <replaceable class="parameter">options</replaceable> ] [ <replaceable
...
@@ -127,7 +127,7 @@ dropuser [ <replaceable class="parameter">options</replaceable> ] [ <replaceable
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><computeroutput>dropuser:
Deletion of user "<replaceable class="parameter">username</replaceable>" failed.
</computeroutput></term>
<term><computeroutput>dropuser:
deletion of user "<replaceable class="parameter">username</replaceable>" failed
</computeroutput></term>
<listitem>
<listitem>
<para>
<para>
Something went wrong. The user was not removed.
Something went wrong. The user was not removed.
...
...
doc/src/sgml/ref/psql-ref.sgml
View file @
f6689a32
<!--
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.1
8 1999/11/26 04:24:16 momjian
Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.1
9 2000/01/12 19:36:34 petere
Exp $
Postgres documentation
Postgres documentation
-->
-->
...
@@ -352,7 +352,7 @@ testdb=>
...
@@ -352,7 +352,7 @@ testdb=>
</para>
</para>
<para>
<para>
The command form <literal>\d
?
</literal> is identical, but any comments
The command form <literal>\d
+
</literal> is identical, but any comments
associated with the table columns are shown as well.
associated with the table columns are shown as well.
</para>
</para>
...
@@ -375,10 +375,6 @@ testdb=>
...
@@ -375,10 +375,6 @@ testdb=>
Lists all available aggregate functions, together with the data type they operate on.
Lists all available aggregate functions, together with the data type they operate on.
If <replaceable class="parameter">pattern</replaceable>
If <replaceable class="parameter">pattern</replaceable>
(a regular expression) is specified, only matching aggregates are shown.
(a regular expression) is specified, only matching aggregates are shown.
If the alternative command form <literal>\da?</literal> is used,
comments are listed for each function as well. The command form
<literal>\da+</literal> will show more information about each aggregate
function, which is usually not of general interest.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -426,8 +422,7 @@ testdb=>
...
@@ -426,8 +422,7 @@ testdb=>
If <replaceable class="parameter">pattern</replaceable>
If <replaceable class="parameter">pattern</replaceable>
(a regular expression) is specified, only matching functions are shown.
(a regular expression) is specified, only matching functions are shown.
If the form <literal>\df+</literal> is used, additional information about
If the form <literal>\df+</literal> is used, additional information about
each function is shown. Comments for each function can be shown with
each function, including language and description is shown.
the <literal>\df?</literal> form.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -447,7 +442,7 @@ testdb=>
...
@@ -447,7 +442,7 @@ testdb=>
<para>
<para>
If <replaceable class="parameter">pattern</replaceable> is specified,
If <replaceable class="parameter">pattern</replaceable> is specified,
it is a regular expression restricts the listing to those objects
it is a regular expression restricts the listing to those objects
whose name matches. If one appends a <quote>
?
</quote> to the command name,
whose name matches. If one appends a <quote>
+
</quote> to the command name,
each object is listed with its associated description, if any.
each object is listed with its associated description, if any.
</para>
</para>
</listitem>
</listitem>
...
@@ -476,10 +471,6 @@ testdb=>
...
@@ -476,10 +471,6 @@ testdb=>
interpretation of the backslash as a new command, you might also
interpretation of the backslash as a new command, you might also
wish to quote the argument.)
wish to quote the argument.)
</para>
</para>
<para>
If the form <literal>\do?</literal> is used, comments are listed for
each operator.
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -500,8 +491,7 @@ testdb=>
...
@@ -500,8 +491,7 @@ testdb=>
<listitem>
<listitem>
<para>
<para>
Lists all data types or only those that match <replaceable class="parameter">pattern</replaceable>.
Lists all data types or only those that match <replaceable class="parameter">pattern</replaceable>.
The command forms <literal>\dT+</literal> and <literal>\dT?</literal> show extra information
The command form <literal>\dT+</literal> shows extra information.
and the associated descriptions of the types, respectively.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -648,7 +638,7 @@ Tue Oct 26 21:40:57 CEST 1999
...
@@ -648,7 +638,7 @@ Tue Oct 26 21:40:57 CEST 1999
<listitem>
<listitem>
<para>
<para>
List all the databases in the server as well as their owners. Append a
List all the databases in the server as well as their owners. Append a
<quote>
?</quote> (question mark)
to the command name to see any descriptions
<quote>
+</quote>
to the command name to see any descriptions
for the databases as well. If your <productname>PostgreSQL</productname>
for the databases as well. If your <productname>PostgreSQL</productname>
installation was
installation was
compiled with multibyte encoding support, the encoding scheme of each
compiled with multibyte encoding support, the encoding scheme of each
...
@@ -723,8 +713,6 @@ lo_import 152801
...
@@ -723,8 +713,6 @@ lo_import 152801
<para>
<para>
Shows a list of all <productname>PostgreSQL</productname> <quote>large
Shows a list of all <productname>PostgreSQL</productname> <quote>large
objects</quote> currently stored in the database along with their owners.
objects</quote> currently stored in the database along with their owners.
Append a question mark to the command name (<literal>\lo_list?</literal>) to
see the the associated comments as well.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -1203,11 +1191,9 @@ Access permissions for database "test"
...
@@ -1203,11 +1191,9 @@ Access permissions for database "test"
<para>
<para>
If so configured, <application>psql</application> understands both standard
If so configured, <application>psql</application> understands both standard
Unix short options, and <acronym>GNU</acronym>-style long options. Since the
Unix short options, and <acronym>GNU</acronym>-style long options. The latter
latter are not available on all systems, you are advised to consider carefully
are not available on all systems, so you are advised to consider carefully
whether to use them, if you are writing scripts, etc. For support on the
whether to use them.
<productname>PostgreSQL</productname> mailing lists, you are asked to only
use the standard short options.
</para>
</para>
<para>
<para>
...
@@ -1301,7 +1287,7 @@ Access permissions for database "test"
...
@@ -1301,7 +1287,7 @@ Access permissions for database "test"
<varlistentry>
<varlistentry>
<term>-F, --field-sep <replaceable class="parameter">separator</replaceable></term>
<term>-F, --field-sep
arator
<replaceable class="parameter">separator</replaceable></term>
<listitem>
<listitem>
<para>
<para>
Use <replaceable class="parameter">separator</replaceable> as the field separator.
Use <replaceable class="parameter">separator</replaceable> as the field separator.
...
@@ -1358,7 +1344,7 @@ Access permissions for database "test"
...
@@ -1358,7 +1344,7 @@ Access permissions for database "test"
<varlistentry>
<varlistentry>
<term>-o, --out <replaceable class="parameter">filename</replaceable></term>
<term>-o, --out
put
<replaceable class="parameter">filename</replaceable></term>
<listitem>
<listitem>
<para>
<para>
Put all query output into file <replaceable class="parameter">filename</replaceable>.
Put all query output into file <replaceable class="parameter">filename</replaceable>.
...
@@ -1400,8 +1386,7 @@ Access permissions for database "test"
...
@@ -1400,8 +1386,7 @@ Access permissions for database "test"
<listitem>
<listitem>
<para>
<para>
Specifies that <application>psql</application> should do its work quietly.
Specifies that <application>psql</application> should do its work quietly.
By default, it prints welcome messages, various informational output and
By default, it prints welcome messages and various informational output.
prompts for each query.
If this option is used, none of this happens. This is useful with the
If this option is used, none of this happens. This is useful with the
<option>-c</option> option. Within <application>psql</application> you can
<option>-c</option> option. Within <application>psql</application> you can
also set the <envar>quiet</envar> variable to achieve the same effect.
also set the <envar>quiet</envar> variable to achieve the same effect.
...
@@ -1511,35 +1496,7 @@ Access permissions for database "test"
...
@@ -1511,35 +1496,7 @@ Access permissions for database "test"
<term>-V, --version</term>
<term>-V, --version</term>
<listitem>
<listitem>
<para>
<para>
Shows version information about <application>psql</application> and your
Shows the <application>psql</application> version.
<productname>PostgreSQL</productname> database server, if it could be reached.
</para>
<para>
The output looks similar to this:
<programlisting>
~$ <userinput>psql -V</userinput>
Server: PostgreSQL 6.5.2 on i586-pc-linux-gnu, compiled by egcs
psql 6.6.0 on i586-pc-linux-gnu, compiled by gcc 2.8.1 (Oct 27 1999 15:15:04), long options,
readline, history, locale, assert checks
</programlisting>
The <quote>Server</quote> line is identical to the one returned by the
backend function <function>version()</function> and thus might vary
if you query different servers by using different connection
options.
</para>
<para>
The <quote>psql</quote> line is compiled into the <application>psql</application>
binary. It shows you which <productname>PostgreSQL</productname> release
it was distributed with and what optional features were compiled into it.
Although in general (as in the example above) you can use <application>psql</application>
and database servers from different versions (if they don't differ too much)
this is not recommended or
even necessary. The optional features indicate only <application>psql</application>'s
capabilities but if <application>psql</application> was configured with
the same source tree as the rest of the distribution, it gives you an
indication about other parts of the installation as well.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -2149,26 +2106,6 @@ Field separator is "oo".
...
@@ -2149,26 +2106,6 @@ Field separator is "oo".
</refsect2>
</refsect2>
<refsect2>
<title>History and Lineage</title>
<para>
<application>psql</application> first appeared in <productname>Postgres95</productname>
to complement and later replace the <application>monitor</application> program. (You see this
name here or there in really old files. The author has never had the pleasure to use this
program though.) An uncountable number of people have added features since to reflect
the enhancements in the actual database server.
</para>
<para>
The present version is the result of a major clean-up and re-write in 1999 by
<ulink URL="mailto:peter_e@gmx.net">Peter Eisentraut</ulink> in preparation for release 7.0.
Many people had again contributed their ideas. A bunch of features were stolen
from various shells (in case you hadn't noticed), in particular
<application>tcsh</application>.
</para>
</refsect2>
<refsect2>
<refsect2>
<title><acronym>GNU</acronym> readline</title>
<title><acronym>GNU</acronym> readline</title>
...
...
src/bin/psql/command.c
View file @
f6689a32
...
@@ -243,7 +243,10 @@ HandleSlashCmds(PsqlSettings *pset,
...
@@ -243,7 +243,10 @@ HandleSlashCmds(PsqlSettings *pset,
if
(
status
==
CMD_UNKNOWN
)
if
(
status
==
CMD_UNKNOWN
)
{
{
fprintf
(
stderr
,
"Unrecognized command:
\\
%s. Try
\\
? for help.
\n
"
,
cmd
);
if
(
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"Invalid command
\\
%s. Try
\\
? for help.
\n
"
,
cmd
);
else
fprintf
(
stderr
,
"%s: invalid command
\\
%s"
,
pset
->
progname
,
cmd
);
status
=
CMD_ERROR
;
status
=
CMD_ERROR
;
}
}
...
@@ -341,38 +344,37 @@ exec_command(const char *cmd,
...
@@ -341,38 +344,37 @@ exec_command(const char *cmd,
else
if
(
cmd
[
0
]
==
'd'
)
else
if
(
cmd
[
0
]
==
'd'
)
{
{
bool
show_verbose
=
strchr
(
cmd
,
'+'
)
?
true
:
false
;
bool
show_verbose
=
strchr
(
cmd
,
'+'
)
?
true
:
false
;
bool
show_desc
=
strchr
(
cmd
,
'?'
)
?
true
:
false
;
switch
(
cmd
[
1
])
switch
(
cmd
[
1
])
{
{
case
'\0'
:
case
'\0'
:
case
'?'
:
case
'?'
:
if
(
options
[
0
])
if
(
options
[
0
])
success
=
describeTableDetails
(
options
[
0
],
pset
,
show_
desc
);
success
=
describeTableDetails
(
options
[
0
],
pset
,
show_
verbose
);
else
else
/* standard listing of interesting things */
/* standard listing of interesting things */
success
=
listTables
(
"tvs"
,
NULL
,
pset
,
show_
desc
);
success
=
listTables
(
"tvs"
,
NULL
,
pset
,
show_
verbose
);
break
;
break
;
case
'a'
:
case
'a'
:
success
=
describeAggregates
(
options
[
0
],
pset
,
show_verbose
,
show_desc
);
success
=
describeAggregates
(
options
[
0
],
pset
);
break
;
break
;
case
'd'
:
case
'd'
:
success
=
objectDescription
(
options
[
0
],
pset
);
success
=
objectDescription
(
options
[
0
],
pset
);
break
;
break
;
case
'f'
:
case
'f'
:
success
=
describeFunctions
(
options
[
0
],
pset
,
show_verbose
,
show_desc
);
success
=
describeFunctions
(
options
[
0
],
pset
,
show_verbose
);
break
;
break
;
case
'l'
:
case
'l'
:
success
=
do_lo_list
(
pset
,
show_desc
);
success
=
do_lo_list
(
pset
);
break
;
break
;
case
'o'
:
case
'o'
:
success
=
describeOperators
(
options
[
0
],
pset
,
show_verbose
,
show_desc
);
success
=
describeOperators
(
options
[
0
],
pset
);
break
;
break
;
case
'p'
:
case
'p'
:
success
=
permissionsList
(
options
[
0
],
pset
);
success
=
permissionsList
(
options
[
0
],
pset
);
break
;
break
;
case
'T'
:
case
'T'
:
success
=
describeTypes
(
options
[
0
],
pset
,
show_verbose
,
show_desc
);
success
=
describeTypes
(
options
[
0
],
pset
,
show_verbose
);
break
;
break
;
case
't'
:
case
't'
:
case
'v'
:
case
'v'
:
...
@@ -380,9 +382,9 @@ exec_command(const char *cmd,
...
@@ -380,9 +382,9 @@ exec_command(const char *cmd,
case
's'
:
case
's'
:
case
'S'
:
case
'S'
:
if
(
cmd
[
1
]
==
'S'
&&
cmd
[
2
]
==
'\0'
)
if
(
cmd
[
1
]
==
'S'
&&
cmd
[
2
]
==
'\0'
)
success
=
listTables
(
"Stvs"
,
NULL
,
pset
,
show_
desc
);
success
=
listTables
(
"Stvs"
,
NULL
,
pset
,
show_
verbose
);
else
else
success
=
listTables
(
&
cmd
[
1
],
options
[
0
],
pset
,
show_
desc
);
success
=
listTables
(
&
cmd
[
1
],
options
[
0
],
pset
,
show_
verbose
);
break
;
break
;
default:
default:
status
=
CMD_UNKNOWN
;
status
=
CMD_UNKNOWN
;
...
@@ -452,7 +454,10 @@ exec_command(const char *cmd,
...
@@ -452,7 +454,10 @@ exec_command(const char *cmd,
{
{
if
(
!
options
[
0
])
if
(
!
options
[
0
])
{
{
fputs
(
"Usage:
\\
i <filename>
\n
"
,
stderr
);
if
(
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"
\\
%s: missing required argument
\n
"
,
cmd
);
else
fprintf
(
stderr
,
"%s:
\\
%s: missing required argument"
,
pset
->
progname
,
cmd
);
success
=
false
;
success
=
false
;
}
}
else
else
...
@@ -463,7 +468,7 @@ exec_command(const char *cmd,
...
@@ -463,7 +468,7 @@ exec_command(const char *cmd,
/* \l is list databases */
/* \l is list databases */
else
if
(
strcmp
(
cmd
,
"l"
)
==
0
||
strcmp
(
cmd
,
"list"
)
==
0
)
else
if
(
strcmp
(
cmd
,
"l"
)
==
0
||
strcmp
(
cmd
,
"list"
)
==
0
)
success
=
listAllDbs
(
pset
,
false
);
success
=
listAllDbs
(
pset
,
false
);
else
if
(
strcmp
(
cmd
,
"l
?"
)
==
0
||
strcmp
(
cmd
,
"list?
"
)
==
0
)
else
if
(
strcmp
(
cmd
,
"l
+"
)
==
0
||
strcmp
(
cmd
,
"list+
"
)
==
0
)
success
=
listAllDbs
(
pset
,
true
);
success
=
listAllDbs
(
pset
,
true
);
...
@@ -474,7 +479,10 @@ exec_command(const char *cmd,
...
@@ -474,7 +479,10 @@ exec_command(const char *cmd,
{
{
if
(
!
options
[
1
])
if
(
!
options
[
1
])
{
{
fputs
(
"Usage:
\\
lo_export <loid> <filename>
\n
"
,
stderr
);
if
(
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"
\\
%s: missing required argument"
,
cmd
);
else
fprintf
(
stderr
,
"%s:
\\
%s: missing required argument"
,
pset
->
progname
,
cmd
);
success
=
false
;
success
=
false
;
}
}
else
else
...
@@ -485,7 +493,10 @@ exec_command(const char *cmd,
...
@@ -485,7 +493,10 @@ exec_command(const char *cmd,
{
{
if
(
!
options
[
0
])
if
(
!
options
[
0
])
{
{
fputs
(
"Usage:
\\
lo_import <filename> [<description>]
\n
"
,
stderr
);
if
(
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"
\\
%s: missing required argument"
,
cmd
);
else
fprintf
(
stderr
,
"%s:
\\
%s: missing required argument"
,
pset
->
progname
,
cmd
);
success
=
false
;
success
=
false
;
}
}
else
else
...
@@ -493,15 +504,16 @@ exec_command(const char *cmd,
...
@@ -493,15 +504,16 @@ exec_command(const char *cmd,
}
}
else
if
(
strcmp
(
cmd
+
3
,
"list"
)
==
0
)
else
if
(
strcmp
(
cmd
+
3
,
"list"
)
==
0
)
success
=
do_lo_list
(
pset
,
false
);
success
=
do_lo_list
(
pset
);
else
if
(
strcmp
(
cmd
+
3
,
"list?"
)
==
0
)
success
=
do_lo_list
(
pset
,
true
);
else
if
(
strcmp
(
cmd
+
3
,
"unlink"
)
==
0
)
else
if
(
strcmp
(
cmd
+
3
,
"unlink"
)
==
0
)
{
{
if
(
!
options
[
0
])
if
(
!
options
[
0
])
{
{
fputs
(
"Usage:
\\
lo_unlink <loid>
\n
"
,
stderr
);
if
(
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"
\\
%s: missing required argument"
,
cmd
);
else
fprintf
(
stderr
,
"%s:
\\
%s: missing required argument"
,
pset
->
progname
,
cmd
);
success
=
false
;
success
=
false
;
}
}
else
else
...
@@ -522,7 +534,7 @@ exec_command(const char *cmd,
...
@@ -522,7 +534,7 @@ exec_command(const char *cmd,
{
{
if
(
query_buf
&&
query_buf
->
len
>
0
)
if
(
query_buf
&&
query_buf
->
len
>
0
)
puts
(
query_buf
->
data
);
puts
(
query_buf
->
data
);
else
if
(
!
GetVariableBool
(
pset
->
vars
,
"quiet"
)
)
else
if
(
!
quiet
)
puts
(
"Query buffer is empty."
);
puts
(
"Query buffer is empty."
);
fflush
(
stdout
);
fflush
(
stdout
);
}
}
...
@@ -532,7 +544,10 @@ exec_command(const char *cmd,
...
@@ -532,7 +544,10 @@ exec_command(const char *cmd,
{
{
if
(
!
options
[
0
])
if
(
!
options
[
0
])
{
{
fputs
(
"Usage:
\\
pset <parameter> [<value>]
\n
"
,
stderr
);
if
(
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"
\\
%s: missing required argument"
,
cmd
);
else
fprintf
(
stderr
,
"%s:
\\
%s: missing required argument"
,
pset
->
progname
,
cmd
);
success
=
false
;
success
=
false
;
}
}
else
else
...
@@ -600,7 +615,11 @@ exec_command(const char *cmd,
...
@@ -600,7 +615,11 @@ exec_command(const char *cmd,
{
{
if
(
!
SetVariable
(
pset
->
vars
,
options
[
0
],
options
[
1
]))
if
(
!
SetVariable
(
pset
->
vars
,
options
[
0
],
options
[
1
]))
{
{
fprintf
(
stderr
,
"Set variable failed.
\n
"
);
if
(
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"
\\
%s: failed
\n
"
,
cmd
);
else
fprintf
(
stderr
,
"%s:
\\
%s: failed
\n
"
,
pset
->
progname
,
cmd
);
success
=
false
;
success
=
false
;
}
}
}
}
...
@@ -624,7 +643,10 @@ exec_command(const char *cmd,
...
@@ -624,7 +643,10 @@ exec_command(const char *cmd,
if
(
!
options
[
0
])
if
(
!
options
[
0
])
{
{
fprintf
(
stderr
,
"Usage:
\\
%s <filename>
\n
"
,
cmd
);
if
(
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"
\\
%s: missing required argument"
,
cmd
);
else
fprintf
(
stderr
,
"%s:
\\
%s: missing required argument"
,
pset
->
progname
,
cmd
);
success
=
false
;
success
=
false
;
}
}
else
else
...
@@ -932,20 +954,27 @@ do_connect(const char *new_dbname, const char *new_user, PsqlSettings *pset)
...
@@ -932,20 +954,27 @@ do_connect(const char *new_dbname, const char *new_user, PsqlSettings *pset)
*/
*/
if
(
!
pset
->
db
||
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
if
(
!
pset
->
db
||
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
{
{
fprintf
(
stderr
,
"Could not establish database connection.
\n
%s"
,
PQerrorMessage
(
pset
->
db
));
if
(
pset
->
cur_cmd_interactive
)
PQfinish
(
pset
->
db
);
{
if
(
!
oldconn
||
!
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"
\\
connect: %s"
,
PQerrorMessage
(
pset
->
db
));
{
/* we don't want unpredictable things to
PQfinish
(
pset
->
db
);
* happen in scripting mode */
if
(
oldconn
)
fputs
(
"Terminating.
\n
"
,
stderr
);
{
fputs
(
"Previous connection kept
\n
"
,
stderr
);
pset
->
db
=
oldconn
;
}
else
pset
->
db
=
NULL
;
}
else
{
/* we don't want unpredictable things to
* happen in scripting mode */
fprintf
(
stderr
,
"%s:
\\
connect: %s"
,
pset
->
progname
,
PQerrorMessage
(
pset
->
db
));
PQfinish
(
pset
->
db
);
if
(
oldconn
)
if
(
oldconn
)
PQfinish
(
oldconn
);
PQfinish
(
oldconn
);
pset
->
db
=
NULL
;
pset
->
db
=
NULL
;
}
else
{
fputs
(
"Keeping old connection.
\n
"
,
stderr
);
pset
->
db
=
oldconn
;
}
}
}
}
else
else
...
@@ -956,8 +985,7 @@ do_connect(const char *new_dbname, const char *new_user, PsqlSettings *pset)
...
@@ -956,8 +985,7 @@ do_connect(const char *new_dbname, const char *new_user, PsqlSettings *pset)
printf
(
"You are now connected to database %s.
\n
"
,
dbparam
);
printf
(
"You are now connected to database %s.
\n
"
,
dbparam
);
else
if
(
dbparam
!=
new_dbname
)
/* no new db */
else
if
(
dbparam
!=
new_dbname
)
/* no new db */
printf
(
"You are now connected as new user %s.
\n
"
,
new_user
);
printf
(
"You are now connected as new user %s.
\n
"
,
new_user
);
else
else
/* both new */
/* both new */
printf
(
"You are now connected to database %s as user %s.
\n
"
,
printf
(
"You are now connected to database %s as user %s.
\n
"
,
PQdb
(
pset
->
db
),
PQuser
(
pset
->
db
));
PQdb
(
pset
->
db
),
PQuser
(
pset
->
db
));
}
}
...
@@ -1020,7 +1048,7 @@ editFile(const char *fname)
...
@@ -1020,7 +1048,7 @@ editFile(const char *fname)
static
bool
static
bool
do_edit
(
const
char
*
filename_arg
,
PQExpBuffer
query_buf
)
do_edit
(
const
char
*
filename_arg
,
PQExpBuffer
query_buf
)
{
{
char
fnametmp
[
64
];
char
fnametmp
[
MAXPGPATH
];
FILE
*
stream
;
FILE
*
stream
;
const
char
*
fname
;
const
char
*
fname
;
bool
error
=
false
;
bool
error
=
false
;
...
@@ -1047,8 +1075,11 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
...
@@ -1047,8 +1075,11 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
/* make a temp file to edit */
/* make a temp file to edit */
#ifndef WIN32
#ifndef WIN32
mode_t
oldumask
;
mode_t
oldumask
;
const
char
*
tmpdirenv
=
getenv
(
"TMPDIR"
);
sprintf
(
fnametmp
,
"/tmp/psql.edit.%ld.%ld"
,
(
long
)
geteuid
(),
(
long
)
getpid
());
sprintf
(
fnametmp
,
"%s/psql.edit.%ld.%ld"
,
tmpdirenv
?
tmpdirenv
:
"/tmp"
,
(
long
)
geteuid
(),
(
long
)
getpid
());
#else
#else
GetTempFileName
(
"."
,
"psql"
,
0
,
fnametmp
);
GetTempFileName
(
"."
,
"psql"
,
0
,
fnametmp
);
#endif
#endif
...
...
src/bin/psql/common.c
View file @
f6689a32
...
@@ -491,9 +491,6 @@ SendQuery(PsqlSettings *pset, const char *query)
...
@@ -491,9 +491,6 @@ SendQuery(PsqlSettings *pset, const char *query)
break
;
break
;
case
PGRES_COPY_OUT
:
case
PGRES_COPY_OUT
:
if
(
pset
->
cur_cmd_interactive
&&
!
GetVariableBool
(
pset
->
vars
,
"quiet"
))
puts
(
"Copy command returns:"
);
success
=
handleCopyOut
(
pset
->
db
,
pset
->
queryFout
);
success
=
handleCopyOut
(
pset
->
db
,
pset
->
queryFout
);
break
;
break
;
...
@@ -510,7 +507,7 @@ SendQuery(PsqlSettings *pset, const char *query)
...
@@ -510,7 +507,7 @@ SendQuery(PsqlSettings *pset, const char *query)
case
PGRES_FATAL_ERROR
:
case
PGRES_FATAL_ERROR
:
case
PGRES_BAD_RESPONSE
:
case
PGRES_BAD_RESPONSE
:
success
=
false
;
success
=
false
;
fputs
(
PQerrorMessage
(
pset
->
db
),
pset
->
queryFout
);
fputs
(
PQerrorMessage
(
pset
->
db
),
stderr
);
break
;
break
;
}
}
...
@@ -518,6 +515,11 @@ SendQuery(PsqlSettings *pset, const char *query)
...
@@ -518,6 +515,11 @@ SendQuery(PsqlSettings *pset, const char *query)
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
{
{
if
(
!
pset
->
cur_cmd_interactive
)
{
fprintf
(
stderr
,
"%s: connection to server was lost"
,
pset
->
progname
);
exit
(
EXIT_BADCONN
);
}
fputs
(
"The connection to the server was lost. Attempting reset: "
,
stderr
);
fputs
(
"The connection to the server was lost. Attempting reset: "
,
stderr
);
PQreset
(
pset
->
db
);
PQreset
(
pset
->
db
);
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
if
(
PQstatus
(
pset
->
db
)
==
CONNECTION_BAD
)
...
...
src/bin/psql/copy.c
View file @
f6689a32
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
* parse_slash_copy
* parse_slash_copy
* -- parses \copy command line
* -- parses \copy command line
*
*
* Accepted syntax: \copy [binary] table|"table" [with oids] from|to filename|'filename' using delimiters ['<char>']
* Accepted syntax: \copy [binary] table|"table" [with oids] from|to filename|'filename' using delimiters ['<char>']
[ with null as 'string' ]
* (binary is not here yet)
* (binary is not here yet)
*
*
* returns a malloc'ed structure with the options, or NULL on parsing error
* returns a malloc'ed structure with the options, or NULL on parsing error
...
@@ -41,6 +41,7 @@ struct copy_options
...
@@ -41,6 +41,7 @@ struct copy_options
bool
binary
;
bool
binary
;
bool
oids
;
bool
oids
;
char
*
delim
;
char
*
delim
;
char
*
null
;
};
};
...
@@ -52,12 +53,13 @@ free_copy_options(struct copy_options * ptr)
...
@@ -52,12 +53,13 @@ free_copy_options(struct copy_options * ptr)
free
(
ptr
->
table
);
free
(
ptr
->
table
);
free
(
ptr
->
file
);
free
(
ptr
->
file
);
free
(
ptr
->
delim
);
free
(
ptr
->
delim
);
free
(
ptr
->
null
);
free
(
ptr
);
free
(
ptr
);
}
}
static
struct
copy_options
*
static
struct
copy_options
*
parse_slash_copy
(
const
char
*
args
)
parse_slash_copy
(
const
char
*
args
,
PsqlSettings
*
pset
)
{
{
struct
copy_options
*
result
;
struct
copy_options
*
result
;
char
*
line
;
char
*
line
;
...
@@ -78,7 +80,9 @@ parse_slash_copy(const char *args)
...
@@ -78,7 +80,9 @@ parse_slash_copy(const char *args)
error
=
true
;
error
=
true
;
else
else
{
{
if
(
!
quote
&&
strcasecmp
(
token
,
"binary"
)
==
0
)
#ifdef NOT_USED
/* this is not implemented yet */
if
(
!
quote
&&
strcasecmp
(
token
,
"binary"
)
==
0
)
{
{
result
->
binary
=
true
;
result
->
binary
=
true
;
token
=
strtokx
(
NULL
,
"
\t
"
,
"
\"
"
,
'\\'
,
&
quote
,
NULL
);
token
=
strtokx
(
NULL
,
"
\t
"
,
"
\"
"
,
'\\'
,
&
quote
,
NULL
);
...
@@ -86,6 +90,7 @@ parse_slash_copy(const char *args)
...
@@ -86,6 +90,7 @@ parse_slash_copy(const char *args)
error
=
true
;
error
=
true
;
}
}
if
(
token
)
if
(
token
)
#endif
result
->
table
=
xstrdup
(
token
);
result
->
table
=
xstrdup
(
token
);
}
}
...
@@ -143,9 +148,7 @@ parse_slash_copy(const char *args)
...
@@ -143,9 +148,7 @@ parse_slash_copy(const char *args)
token
=
strtokx
(
NULL
,
"
\t
"
,
NULL
,
'\\'
,
NULL
,
NULL
);
token
=
strtokx
(
NULL
,
"
\t
"
,
NULL
,
'\\'
,
NULL
,
NULL
);
if
(
token
)
if
(
token
)
{
{
if
(
strcasecmp
(
token
,
"using"
)
!=
0
)
if
(
strcasecmp
(
token
,
"using"
)
==
0
)
error
=
true
;
else
{
{
token
=
strtokx
(
NULL
,
"
\t
"
,
NULL
,
'\\'
,
NULL
,
NULL
);
token
=
strtokx
(
NULL
,
"
\t
"
,
NULL
,
'\\'
,
NULL
,
NULL
);
if
(
!
token
||
strcasecmp
(
token
,
"delimiters"
)
!=
0
)
if
(
!
token
||
strcasecmp
(
token
,
"delimiters"
)
!=
0
)
...
@@ -154,11 +157,36 @@ parse_slash_copy(const char *args)
...
@@ -154,11 +157,36 @@ parse_slash_copy(const char *args)
{
{
token
=
strtokx
(
NULL
,
"
\t
"
,
"'"
,
'\\'
,
NULL
,
NULL
);
token
=
strtokx
(
NULL
,
"
\t
"
,
"'"
,
'\\'
,
NULL
,
NULL
);
if
(
token
)
if
(
token
)
{
result
->
delim
=
xstrdup
(
token
);
result
->
delim
=
xstrdup
(
token
);
token
=
strtokx
(
NULL
,
"
\t
"
,
NULL
,
'\\'
,
NULL
,
NULL
);
}
else
else
error
=
true
;
error
=
true
;
}
}
}
}
if
(
!
error
&&
token
)
{
if
(
strcasecmp
(
token
,
"with"
)
==
0
)
{
token
=
strtokx
(
NULL
,
"
\t
"
,
NULL
,
'\\'
,
NULL
,
NULL
);
if
(
!
token
||
strcasecmp
(
token
,
"null"
)
!=
0
)
error
=
true
;
else
{
token
=
strtokx
(
NULL
,
"
\t
"
,
NULL
,
'\\'
,
NULL
,
NULL
);
if
(
!
token
||
strcasecmp
(
token
,
"as"
)
!=
0
)
error
=
true
;
else
{
token
=
strtokx
(
NULL
,
"
\t
"
,
"'"
,
'\\'
,
NULL
,
NULL
);
if
(
token
)
result
->
null
=
xstrdup
(
token
);
}
}
}
}
}
}
}
}
...
@@ -166,11 +194,13 @@ parse_slash_copy(const char *args)
...
@@ -166,11 +194,13 @@ parse_slash_copy(const char *args)
if
(
error
)
if
(
error
)
{
{
fputs
(
"Parse error at "
,
stderr
);
if
(
!
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"%s: "
,
pset
->
progname
);
fputs
(
"
\\
copy: parse error at "
,
stderr
);
if
(
!
token
)
if
(
!
token
)
fputs
(
"end of line
.
"
,
stderr
);
fputs
(
"end of line"
,
stderr
);
else
else
fprintf
(
stderr
,
"'%s'
.
"
,
token
);
fprintf
(
stderr
,
"'%s'"
,
token
);
fputs
(
"
\n
"
,
stderr
);
fputs
(
"
\n
"
,
stderr
);
free
(
result
);
free
(
result
);
return
NULL
;
return
NULL
;
...
@@ -196,15 +226,14 @@ do_copy(const char *args, PsqlSettings *pset)
...
@@ -196,15 +226,14 @@ do_copy(const char *args, PsqlSettings *pset)
bool
success
;
bool
success
;
/* parse options */
/* parse options */
options
=
parse_slash_copy
(
args
);
options
=
parse_slash_copy
(
args
,
pset
);
if
(
!
options
)
if
(
!
options
)
return
false
;
return
false
;
strcpy
(
query
,
"COPY "
);
strcpy
(
query
,
"COPY "
);
if
(
options
->
binary
)
if
(
options
->
binary
)
fputs
(
"Warning:
\\
copy binary is not implemented. Resorting to text output.
\n
"
,
stderr
);
strcat
(
query
,
"BINARY "
);
/* strcat(query, "BINARY "); */
strcat
(
query
,
"
\"
"
);
strcat
(
query
,
"
\"
"
);
strncat
(
query
,
options
->
table
,
NAMEDATALEN
);
strncat
(
query
,
options
->
table
,
NAMEDATALEN
);
...
@@ -220,13 +249,7 @@ do_copy(const char *args, PsqlSettings *pset)
...
@@ -220,13 +249,7 @@ do_copy(const char *args, PsqlSettings *pset)
if
(
options
->
delim
)
if
(
options
->
delim
)
{
{
strcat
(
query
,
" USING DELIMITERS '"
);
/*
* backend copy only uses the first character here, but that might
* be the escape backslash (makes me wonder though why it's called
* delimiterS)
*/
strncat
(
query
,
" USING DELIMITERS '"
,
2
);
strcat
(
query
,
options
->
delim
);
strcat
(
query
,
options
->
delim
);
strcat
(
query
,
"'"
);
strcat
(
query
,
"'"
);
}
}
...
@@ -247,9 +270,11 @@ do_copy(const char *args, PsqlSettings *pset)
...
@@ -247,9 +270,11 @@ do_copy(const char *args, PsqlSettings *pset)
if
(
!
copystream
)
if
(
!
copystream
)
{
{
if
(
!
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"%s: "
,
pset
->
progname
);
fprintf
(
stderr
,
fprintf
(
stderr
,
"
Unable to open file %s which to copy
: %s
\n
"
,
"
unable to open file %s
: %s
\n
"
,
options
->
f
rom
?
"from"
:
"to"
,
strerror
(
errno
));
options
->
f
ile
,
strerror
(
errno
));
free_copy_options
(
options
);
free_copy_options
(
options
);
return
false
;
return
false
;
}
}
...
@@ -272,7 +297,9 @@ do_copy(const char *args, PsqlSettings *pset)
...
@@ -272,7 +297,9 @@ do_copy(const char *args, PsqlSettings *pset)
break
;
break
;
default:
default:
success
=
false
;
success
=
false
;
fprintf
(
stderr
,
"Unexpected response (%d)
\n
"
,
PQresultStatus
(
result
));
if
(
!
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"%s: "
,
pset
->
progname
);
fprintf
(
stderr
,
"
\\
copy: unexpected response (%d)
\n
"
,
PQresultStatus
(
result
));
}
}
PQclear
(
result
);
PQclear
(
result
);
...
@@ -280,9 +307,9 @@ do_copy(const char *args, PsqlSettings *pset)
...
@@ -280,9 +307,9 @@ do_copy(const char *args, PsqlSettings *pset)
if
(
!
GetVariable
(
pset
->
vars
,
"quiet"
))
if
(
!
GetVariable
(
pset
->
vars
,
"quiet"
))
{
{
if
(
success
)
if
(
success
)
puts
(
"Successfully copied
.
"
);
puts
(
"Successfully copied"
);
else
else
puts
(
"Copy failed
.
"
);
puts
(
"Copy failed"
);
}
}
fclose
(
copystream
);
fclose
(
copystream
);
...
...
src/bin/psql/describe.c
View file @
f6689a32
This diff is collapsed.
Click to expand it.
src/bin/psql/describe.h
View file @
f6689a32
...
@@ -5,16 +5,16 @@
...
@@ -5,16 +5,16 @@
#include "settings.h"
#include "settings.h"
/* \da */
/* \da */
bool
describeAggregates
(
const
char
*
name
,
PsqlSettings
*
pset
,
bool
verbose
,
bool
desc
);
bool
describeAggregates
(
const
char
*
name
,
PsqlSettings
*
pset
);
/* \df */
/* \df */
bool
describeFunctions
(
const
char
*
name
,
PsqlSettings
*
pset
,
bool
verbose
,
bool
desc
);
bool
describeFunctions
(
const
char
*
name
,
PsqlSettings
*
pset
,
bool
verbose
);
/* \dT */
/* \dT */
bool
describeTypes
(
const
char
*
name
,
PsqlSettings
*
pset
,
bool
verbose
,
bool
desc
);
bool
describeTypes
(
const
char
*
name
,
PsqlSettings
*
pset
,
bool
verbose
);
/* \do */
/* \do */
bool
describeOperators
(
const
char
*
name
,
PsqlSettings
*
pset
,
bool
verbose
,
bool
desc
);
bool
describeOperators
(
const
char
*
name
,
PsqlSettings
*
pset
);
/* \z (or \dp) */
/* \z (or \dp) */
bool
permissionsList
(
const
char
*
name
,
PsqlSettings
*
pset
);
bool
permissionsList
(
const
char
*
name
,
PsqlSettings
*
pset
);
...
...
src/bin/psql/help.c
View file @
f6689a32
This diff is collapsed.
Click to expand it.
src/bin/psql/large_obj.c
View file @
f6689a32
...
@@ -90,7 +90,9 @@ do_lo_export(PsqlSettings *pset, const char *loid_arg, const char *filename_arg)
...
@@ -90,7 +90,9 @@ do_lo_export(PsqlSettings *pset, const char *loid_arg, const char *filename_arg)
if
(
!
pset
->
db
)
if
(
!
pset
->
db
)
{
{
fputs
(
"You are not connected to a database.
\n
"
,
stderr
);
if
(
!
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"%s: "
,
pset
->
progname
);
fputs
(
"
\\
lo_export: not connected to a database
\n
"
,
stderr
);
return
false
;
return
false
;
}
}
...
@@ -157,7 +159,9 @@ do_lo_import(PsqlSettings *pset, const char *filename_arg, const char *comment_a
...
@@ -157,7 +159,9 @@ do_lo_import(PsqlSettings *pset, const char *filename_arg, const char *comment_a
if
(
!
pset
->
db
)
if
(
!
pset
->
db
)
{
{
fputs
(
"You are not connected to a database.
\n
"
,
stderr
);
if
(
!
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"%s: "
,
pset
->
progname
);
fputs
(
"
\\
lo_import: not connected to a database
\n
"
,
stderr
);
return
false
;
return
false
;
}
}
...
@@ -247,7 +251,9 @@ do_lo_unlink(PsqlSettings *pset, const char *loid_arg)
...
@@ -247,7 +251,9 @@ do_lo_unlink(PsqlSettings *pset, const char *loid_arg)
if
(
!
pset
->
db
)
if
(
!
pset
->
db
)
{
{
fputs
(
"You are not connected to a database.
\n
"
,
stderr
);
if
(
!
pset
->
cur_cmd_interactive
)
fprintf
(
stderr
,
"%s: "
,
pset
->
progname
);
fputs
(
"
\\
lo_unlink: not connected to a database
\n
"
,
stderr
);
return
false
;
return
false
;
}
}
...
@@ -309,20 +315,25 @@ do_lo_unlink(PsqlSettings *pset, const char *loid_arg)
...
@@ -309,20 +315,25 @@ do_lo_unlink(PsqlSettings *pset, const char *loid_arg)
/*
/*
* do_lo_list()
* do_lo_list()
*
*
* Show all large objects in database
, with comments if desired
* Show all large objects in database
with comments
*/
*/
bool
bool
do_lo_list
(
PsqlSettings
*
pset
,
bool
desc
)
do_lo_list
(
PsqlSettings
*
pset
)
{
{
PGresult
*
res
;
PGresult
*
res
;
char
buf
[
512
];
char
buf
[
1024
];
printQueryOpt
myopt
=
pset
->
popt
;
printQueryOpt
myopt
=
pset
->
popt
;
strcpy
(
buf
,
"SELECT usename as
\"
Owner
\"
, substring(relname from 5) as
\"
ID
\"
"
);
strcpy
(
buf
,
if
(
desc
)
"SELECT usename as
\"
Owner
\"
, substring(relname from 5) as
\"
ID
\"
,
\n
"
strcat
(
buf
,
",
\n
obj_description(pg_class.oid) as
\"
Description
\"
"
);
" obj_description(pg_class.oid) as
\"
Description
\"\n
"
strcat
(
buf
,
"
\n
FROM pg_class, pg_user
\n
"
"
FROM pg_class, pg_user
\n
"
"WHERE usesysid = relowner AND relkind = 'l'
\n
"
"WHERE usesysid = relowner AND relkind = 'l'
\n
"
"UNION
\n
"
"SELECT NULL as
\"
Owner
\"
, substring(relname from 5) as
\"
ID
\"
,
\n
"
" obj_description(pg_class.oid) as
\"
Description
\"\n
"
"FROM pg_class
\n
"
"WHERE not exists (select 1 from pg_user where usesysid = relowner) AND relkind = 'l'
\n
"
"ORDER BY
\"
ID
\"
"
);
"ORDER BY
\"
ID
\"
"
);
res
=
PSQLexec
(
pset
,
buf
);
res
=
PSQLexec
(
pset
,
buf
);
...
...
src/bin/psql/large_obj.h
View file @
f6689a32
...
@@ -7,6 +7,6 @@
...
@@ -7,6 +7,6 @@
bool
do_lo_export
(
PsqlSettings
*
pset
,
const
char
*
loid_arg
,
const
char
*
filename_arg
);
bool
do_lo_export
(
PsqlSettings
*
pset
,
const
char
*
loid_arg
,
const
char
*
filename_arg
);
bool
do_lo_import
(
PsqlSettings
*
pset
,
const
char
*
filename_arg
,
const
char
*
comment_arg
);
bool
do_lo_import
(
PsqlSettings
*
pset
,
const
char
*
filename_arg
,
const
char
*
comment_arg
);
bool
do_lo_unlink
(
PsqlSettings
*
pset
,
const
char
*
loid_arg
);
bool
do_lo_unlink
(
PsqlSettings
*
pset
,
const
char
*
loid_arg
);
bool
do_lo_list
(
PsqlSettings
*
pset
,
bool
desc
);
bool
do_lo_list
(
PsqlSettings
*
pset
);
#endif
/* LARGE_OBJ_H */
#endif
/* LARGE_OBJ_H */
src/bin/psql/mainloop.c
View file @
f6689a32
...
@@ -124,10 +124,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
...
@@ -124,10 +124,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
}
}
/* Setting this will not have effect until next line. (Faster.
/* Setting this will not have effect until next line. */
Also think about what happens if there is an error processing
_this_ command.)
*/
die_on_error
=
GetVariableBool
(
pset
->
vars
,
"die_on_error"
);
die_on_error
=
GetVariableBool
(
pset
->
vars
,
"die_on_error"
);
/*
/*
...
@@ -143,7 +140,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
...
@@ -143,7 +140,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
if
(
GetVariableBool
(
pset
->
vars
,
"echo"
)
&&
!
GetVariableBool
(
pset
->
vars
,
"quiet"
))
if
(
GetVariableBool
(
pset
->
vars
,
"echo"
)
&&
!
GetVariableBool
(
pset
->
vars
,
"quiet"
))
puts
(
"EOF"
);
puts
(
"EOF"
);
else
if
(
pset
->
cur_cmd_interactive
)
else
if
(
pset
->
cur_cmd_interactive
)
put
s
(
""
);
/* just newline */
put
c
(
'\n'
,
stdout
);
/* just newline */
eof
=
true
;
eof
=
true
;
continue
;
continue
;
...
@@ -269,6 +266,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
...
@@ -269,6 +266,7 @@ MainLoop(PsqlSettings *pset, FILE *source)
free
(
line
);
free
(
line
);
line
=
new
;
line
=
new
;
len
=
strlen
(
new
);
continue
;
/* reparse the just substituted */
continue
;
/* reparse the just substituted */
}
}
...
...
src/bin/psql/print.c
View file @
f6689a32
...
@@ -204,7 +204,7 @@ print_aligned_text(const char *title, const char * const * headers,
...
@@ -204,7 +204,7 @@ print_aligned_text(const char *title, const char * const * headers,
if
(
opt_border
==
0
)
if
(
opt_border
==
0
)
total_w
=
col_count
-
1
;
total_w
=
col_count
-
1
;
else
if
(
opt_border
==
1
)
else
if
(
opt_border
==
1
)
total_w
=
col_count
*
3
-
2
;
total_w
=
col_count
*
3
-
1
;
else
else
total_w
=
col_count
*
3
+
1
;
total_w
=
col_count
*
3
+
1
;
...
...
src/bin/psql/prompt.c
View file @
f6689a32
...
@@ -52,8 +52,7 @@
...
@@ -52,8 +52,7 @@
*
*
*
*
* If the application-wide prompts became NULL somehow, the returned string
* If the application-wide prompts became NULL somehow, the returned string
* will be empty (not NULL!). Do not free() the result of this function unless
* will be empty (not NULL!).
* you want trouble.
*--------------------------
*--------------------------
*/
*/
const
char
*
const
char
*
...
@@ -66,9 +65,6 @@ get_prompt(PsqlSettings *pset, promptStatus_t status)
...
@@ -66,9 +65,6 @@ get_prompt(PsqlSettings *pset, promptStatus_t status)
const
char
*
p
;
const
char
*
p
;
const
char
*
prompt_string
;
const
char
*
prompt_string
;
if
(
GetVariable
(
pset
->
vars
,
"quiet"
))
return
""
;
if
(
status
==
PROMPT_READY
)
if
(
status
==
PROMPT_READY
)
prompt_string
=
GetVariable
(
pset
->
vars
,
"prompt1"
);
prompt_string
=
GetVariable
(
pset
->
vars
,
"prompt1"
);
else
if
(
status
==
PROMPT_CONTINUE
||
status
==
PROMPT_SINGLEQUOTE
||
status
==
PROMPT_DOUBLEQUOTE
||
status
==
PROMPT_COMMENT
)
else
if
(
status
==
PROMPT_CONTINUE
||
status
==
PROMPT_SINGLEQUOTE
||
status
==
PROMPT_DOUBLEQUOTE
||
status
==
PROMPT_COMMENT
)
...
@@ -130,13 +126,8 @@ get_prompt(PsqlSettings *pset, promptStatus_t status)
...
@@ -130,13 +126,8 @@ get_prompt(PsqlSettings *pset, promptStatus_t status)
break
;
break
;
/* DB server port number */
/* DB server port number */
case
'>'
:
case
'>'
:
if
(
pset
->
db
)
if
(
pset
->
db
&&
PQport
(
pset
->
db
))
{
strncpy
(
buf
,
PQport
(
pset
->
db
),
MAX_PROMPT_SIZE
);
if
(
PQhost
(
pset
->
db
))
strncpy
(
buf
,
PQport
(
pset
->
db
),
MAX_PROMPT_SIZE
);
else
buf
[
0
]
=
'.'
;
}
break
;
break
;
/* DB server user name */
/* DB server user name */
case
'n'
:
case
'n'
:
...
...
src/bin/psql/settings.h
View file @
f6689a32
...
@@ -45,6 +45,7 @@ typedef struct _psqlSettings
...
@@ -45,6 +45,7 @@ typedef struct _psqlSettings
* startup? */
* startup? */
Oid
lastOid
;
/* saves oid from insert command
Oid
lastOid
;
/* saves oid from insert command
because people want it so badly */
because people want it so badly */
char
*
progname
;
/* in case you renamed psql */
}
PsqlSettings
;
}
PsqlSettings
;
...
...
src/bin/psql/startup.c
View file @
f6689a32
...
@@ -40,7 +40,7 @@ static void
...
@@ -40,7 +40,7 @@ static void
process_psqlrc
(
PsqlSettings
*
pset
);
process_psqlrc
(
PsqlSettings
*
pset
);
static
void
static
void
showVersion
(
PsqlSettings
*
pset
);
showVersion
(
void
);
/* Structures to pass information between the option parsing routine
/* Structures to pass information between the option parsing routine
...
@@ -51,7 +51,6 @@ enum _actions
...
@@ -51,7 +51,6 @@ enum _actions
ACT_NOTHING
=
0
,
ACT_NOTHING
=
0
,
ACT_SINGLE_SLASH
,
ACT_SINGLE_SLASH
,
ACT_LIST_DB
,
ACT_LIST_DB
,
ACT_SHOW_VER
,
ACT_SINGLE_QUERY
,
ACT_SINGLE_QUERY
,
ACT_FILE
ACT_FILE
};
};
...
@@ -90,6 +89,11 @@ main(int argc, char **argv)
...
@@ -90,6 +89,11 @@ main(int argc, char **argv)
memset
(
&
settings
,
0
,
sizeof
settings
);
memset
(
&
settings
,
0
,
sizeof
settings
);
if
(
!
strrchr
(
argv
[
0
],
SEP_CHAR
))
settings
.
progname
=
argv
[
0
];
else
settings
.
progname
=
strrchr
(
argv
[
0
],
SEP_CHAR
)
+
1
;
settings
.
cur_cmd_source
=
stdin
;
settings
.
cur_cmd_source
=
stdin
;
settings
.
cur_cmd_interactive
=
false
;
settings
.
cur_cmd_interactive
=
false
;
...
@@ -119,7 +123,7 @@ main(int argc, char **argv)
...
@@ -119,7 +123,7 @@ main(int argc, char **argv)
parse_options
(
argc
,
argv
,
&
settings
,
&
options
);
parse_options
(
argc
,
argv
,
&
settings
,
&
options
);
if
(
options
.
action
==
ACT_LIST_DB
||
options
.
action
==
ACT_SHOW_VER
)
if
(
options
.
action
==
ACT_LIST_DB
)
options
.
dbname
=
"template1"
;
options
.
dbname
=
"template1"
;
if
(
options
.
username
)
if
(
options
.
username
)
...
@@ -152,9 +156,10 @@ main(int argc, char **argv)
...
@@ -152,9 +156,10 @@ main(int argc, char **argv)
free
(
username
);
free
(
username
);
free
(
password
);
free
(
password
);
if
(
PQstatus
(
settings
.
db
)
==
CONNECTION_BAD
&&
options
.
action
!=
ACT_SHOW_VER
)
if
(
PQstatus
(
settings
.
db
)
==
CONNECTION_BAD
)
{
{
fprintf
(
stderr
,
"Connection to database '%s' failed.
\n
%s
\n
"
,
PQdb
(
settings
.
db
),
PQerrorMessage
(
settings
.
db
));
fprintf
(
stderr
,
"%s: connection to database '%s' failed - %s"
,
settings
.
progname
,
PQdb
(
settings
.
db
),
PQerrorMessage
(
settings
.
db
));
PQfinish
(
settings
.
db
);
PQfinish
(
settings
.
db
);
exit
(
EXIT_BADCONN
);
exit
(
EXIT_BADCONN
);
}
}
...
@@ -167,22 +172,15 @@ main(int argc, char **argv)
...
@@ -167,22 +172,15 @@ main(int argc, char **argv)
exit
(
!
success
);
exit
(
!
success
);
}
}
if
(
options
.
action
==
ACT_SHOW_VER
)
{
showVersion
(
&
settings
);
PQfinish
(
settings
.
db
);
exit
(
EXIT_SUCCESS
);
}
if
(
!
GetVariable
(
settings
.
vars
,
"quiet"
)
&&
!
settings
.
notty
&&
!
options
.
action
)
if
(
!
GetVariable
(
settings
.
vars
,
"quiet"
)
&&
!
settings
.
notty
&&
!
options
.
action
)
{
{
p
uts
(
"Welcome to psql
, the PostgreSQL interactive terminal.
\n\n
"
p
rintf
(
"Welcome to %s
, the PostgreSQL interactive terminal.
\n\n
"
"Type:
\\
copyright for distribution terms
\n
"
"Type:
\\
copyright for distribution terms
\n
"
"
\\
h for help with SQL commands
\n
"
"
\\
h for help with SQL commands
\n
"
"
\\
? for help on internal slash commands
\n
"
"
\\
? for help on internal slash commands
\n
"
"
\\
g or terminate with semicolon to execute query
\n
"
"
\\
g or terminate with semicolon to execute query
\n
"
"
\\
q to quit
\n
"
);
"
\\
q to quit
\n
"
,
settings
.
progname
);
}
}
process_psqlrc
(
&
settings
);
process_psqlrc
(
&
settings
);
...
@@ -239,13 +237,12 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
...
@@ -239,13 +237,12 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
{
"echo-all"
,
no_argument
,
NULL
,
'E'
},
{
"echo-all"
,
no_argument
,
NULL
,
'E'
},
{
"echo-all-queries"
,
no_argument
,
NULL
,
'E'
},
{
"echo-all-queries"
,
no_argument
,
NULL
,
'E'
},
{
"file"
,
required_argument
,
NULL
,
'f'
},
{
"file"
,
required_argument
,
NULL
,
'f'
},
{
"field-sep"
,
required_argument
,
NULL
,
'F'
},
{
"field-sep
arator
"
,
required_argument
,
NULL
,
'F'
},
{
"host"
,
required_argument
,
NULL
,
'h'
},
{
"host"
,
required_argument
,
NULL
,
'h'
},
{
"html"
,
no_argument
,
NULL
,
'H'
},
{
"html"
,
no_argument
,
NULL
,
'H'
},
{
"list"
,
no_argument
,
NULL
,
'l'
},
{
"list"
,
no_argument
,
NULL
,
'l'
},
{
"no-readline"
,
no_argument
,
NULL
,
'n'
},
{
"no-readline"
,
no_argument
,
NULL
,
'n'
},
{
"out"
,
required_argument
,
NULL
,
'o'
},
{
"output"
,
required_argument
,
NULL
,
'o'
},
{
"to-file"
,
required_argument
,
NULL
,
'o'
},
{
"port"
,
required_argument
,
NULL
,
'p'
},
{
"port"
,
required_argument
,
NULL
,
'p'
},
{
"pset"
,
required_argument
,
NULL
,
'P'
},
{
"pset"
,
required_argument
,
NULL
,
'P'
},
{
"quiet"
,
no_argument
,
NULL
,
'q'
},
{
"quiet"
,
no_argument
,
NULL
,
'q'
},
...
@@ -390,7 +387,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
...
@@ -390,7 +387,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
{
{
if
(
!
DeleteVariable
(
pset
->
vars
,
value
))
if
(
!
DeleteVariable
(
pset
->
vars
,
value
))
{
{
fprintf
(
stderr
,
"Couldn't delete variable %s.
\n
"
,
value
);
fprintf
(
stderr
,
"%s: could not delete variable %s
\n
"
,
pset
->
progname
,
value
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
}
}
...
@@ -399,7 +397,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
...
@@ -399,7 +397,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
*
equal_loc
=
'\0'
;
*
equal_loc
=
'\0'
;
if
(
!
SetVariable
(
pset
->
vars
,
value
,
equal_loc
+
1
))
if
(
!
SetVariable
(
pset
->
vars
,
value
,
equal_loc
+
1
))
{
{
fprintf
(
stderr
,
"Couldn't set variable %s to %s.
\n
"
,
value
,
equal_loc
);
fprintf
(
stderr
,
"%s: Couldn't set variable %s to %s
\n
"
,
pset
->
progname
,
value
,
equal_loc
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
}
}
...
@@ -408,8 +407,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
...
@@ -408,8 +407,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
break
;
break
;
}
}
case
'V'
:
case
'V'
:
options
->
action
=
ACT_SHOW_VER
;
showVersion
()
;
break
;
exit
(
EXIT_SUCCESS
)
;
case
'W'
:
case
'W'
:
pset
->
getPassword
=
true
;
pset
->
getPassword
=
true
;
break
;
break
;
...
@@ -419,8 +418,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
...
@@ -419,8 +418,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
break
;
break
;
#ifndef HAVE_GETOPT_LONG
#ifndef HAVE_GETOPT_LONG
case
'-'
:
case
'-'
:
fprintf
(
stderr
,
"
This version of psql
was compiled without support for long options.
\n
"
fprintf
(
stderr
,
"
%s
was compiled without support for long options.
\n
"
"Use -? for help on invocation options.
\n
"
);
"Use -? for help on invocation options.
\n
"
,
pset
->
progname
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
break
;
break
;
#endif
#endif
...
@@ -442,7 +441,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
...
@@ -442,7 +441,8 @@ parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * op
else
if
(
!
options
->
username
)
else
if
(
!
options
->
username
)
options
->
username
=
argv
[
optind
];
options
->
username
=
argv
[
optind
];
else
else
fprintf
(
stderr
,
"Warning: extra option %s ignored.
\n
"
,
argv
[
optind
]);
fprintf
(
stderr
,
"%s: warning: extra option %s ignored
\n
"
,
pset
->
progname
,
argv
[
optind
]);
optind
++
;
optind
++
;
}
}
...
@@ -498,73 +498,46 @@ process_psqlrc(PsqlSettings *pset)
...
@@ -498,73 +498,46 @@ process_psqlrc(PsqlSettings *pset)
/* showVersion
/* showVersion
*
*
* Displays the database backend version.
* This output format is intended to match GNU standards.
* Also checks against the version psql was compiled for and makes
* sure that there are no problems.
*
* Returns false if there was a problem retrieving the information
* or a mismatch was detected.
*/
*/
static
void
static
void
showVersion
(
PsqlSettings
*
pset
)
showVersion
(
void
)
{
{
PGresult
*
res
=
NULL
;
puts
(
"psql (PostgreSQL) "
PG_RELEASE
"."
PG_VERSION
"."
PG_SUBVERSION
);
const
char
*
versionstr
=
NULL
;
long
int
release
=
0
,
version
=
0
,
subversion
=
0
;
/* get backend version */
if
(
pset
->
db
&&
PQstatus
(
pset
->
db
)
==
CONNECTION_OK
)
{
res
=
PSQLexec
(
pset
,
"SELECT version()"
);
if
(
PQresultStatus
(
res
)
==
PGRES_TUPLES_OK
)
versionstr
=
PQgetvalue
(
res
,
0
,
0
);
}
if
(
versionstr
&&
strncmp
(
versionstr
,
"PostgreSQL "
,
11
)
==
0
)
{
char
*
tmp
;
release
=
strtol
(
&
versionstr
[
11
],
&
tmp
,
10
);
version
=
strtol
(
tmp
+
1
,
&
tmp
,
10
);
subversion
=
strtol
(
tmp
+
1
,
&
tmp
,
10
);
}
printf
(
"Server: %s
\n
psql"
,
versionstr
?
versionstr
:
"(could not connect)"
);
#if defined(USE_READLINE) || defined (USE_HISTORY) || defined(MULTIBYTE)
fputs
(
"contains "
,
stdout
);
if
(
!
versionstr
||
strcmp
(
versionstr
,
PG_VERSION_STR
)
!=
0
)
printf
(
&
PG_VERSION_STR
[
strcspn
(
PG_VERSION_STR
,
" "
)]);
printf
(
" ("
__DATE__
" "
__TIME__
")"
);
#ifdef MULTIBYTE
printf
(
", multibyte"
);
#endif
#ifdef HAVE_GETOPT_LONG
printf
(
", long options"
);
#endif
#ifdef USE_READLINE
#ifdef USE_READLINE
printf
(
", readline"
);
fputs
(
"readline"
,
stdout
);
#define _Feature
#endif
#endif
#ifdef USE_HISTORY
#ifdef USE_HISTORY
printf
(
", history"
);
#ifdef _Feature
fputs
(
", "
,
stdout
);
#else
#define _Feature
#endif
#endif
#ifdef USE_LOCALE
fputs
(
"history"
,
stdout
);
printf
(
", locale"
);
#endif
#endif
#ifdef PSQL_ALWAYS_GET_PASSWORDS
printf
(
", always password"
);
#ifdef MULTIBYTE
#ifdef _Feature
fputs
(
", "
,
stdout
);
#else
#define _Feature
#endif
#endif
#ifdef USE_ASSERT_CHECKING
fputs
(
"multibyte"
);
printf
(
", assert checks"
);
#endif
#endif
#undef _Feature
puts
(
""
);
puts
(
" support"
);
#endif
if
(
versionstr
&&
(
release
<
6
||
(
release
==
6
&&
version
<
5
)))
puts
(
"
\n
Warning: The server you are connected to is potentially too old for this client
\n
"
"version. You should ideally be using clients and servers from the same
\n
"
"distribution."
);
if
(
res
)
puts
(
"Copyright (C) 2000 PostgreSQL Global Development Team"
);
PQclear
(
res
);
puts
(
"Copyright (C) 1996 Regents of the University of California"
);
puts
(
"Read the file COPYING or use the command
\\
copyright to see the"
);
puts
(
"usage and distribution terms."
);
}
}
src/bin/psql/tab-complete.c
View file @
f6689a32
...
@@ -97,14 +97,12 @@ void initialize_readline(PGconn ** conn)
...
@@ -97,14 +97,12 @@ void initialize_readline(PGconn ** conn)
rl_readline_name
=
"psql"
;
rl_readline_name
=
"psql"
;
rl_attempted_completion_function
=
psql_completion
;
rl_attempted_completion_function
=
psql_completion
;
rl_filename_quoting_function
=
quote_file_name
;
/*rl_filename_dequoting_function = dequote_file_name;*/
rl_filename_quote_characters
=
"qwertyuioplkjhgfdsazxcvbnm"
;
rl_special_prefixes
=
"()'"
;
rl_special_prefixes
=
"()'"
;
rl_basic_word_break_characters
=
"
\t\n\"
'`@$><=;|&{ "
;
rl_basic_word_break_characters
=
"
\t\n\"
'`@$><=;|&{ "
;
completion_max_records
=
rl_completion_query_items
+
1
;
completion_max_records
=
100
;
/* There is a variable rl_completion_query_items for this but apparently
it's not defined everywhere. */
database_connection
=
conn
;
database_connection
=
conn
;
}
}
...
@@ -203,8 +201,6 @@ char ** psql_completion(char *text, int start, int end)
...
@@ -203,8 +201,6 @@ char ** psql_completion(char *text, int start, int end)
(
void
)
end
;
/* not used */
(
void
)
end
;
/* not used */
rl_completion_append_character
=
' '
;
/* Clear a few things. */
/* Clear a few things. */
completion_charp
=
NULL
;
completion_charp
=
NULL
;
completion_charpp
=
NULL
;
completion_charpp
=
NULL
;
...
@@ -721,8 +717,10 @@ PGresult * exec_query(char * query)
...
@@ -721,8 +717,10 @@ PGresult * exec_query(char * query)
result
=
PQexec
(
*
database_connection
,
query
);
result
=
PQexec
(
*
database_connection
,
query
);
if
(
result
!=
NULL
&&
PQresultStatus
(
result
)
!=
PGRES_TUPLES_OK
)
{
if
(
result
!=
NULL
&&
PQresultStatus
(
result
)
!=
PGRES_TUPLES_OK
)
{
#ifdef NOT_USED
fprintf
(
stderr
,
"
\n
The completion query
\"
%s
\"
failed thus: %s
\n
"
,
fprintf
(
stderr
,
"
\n
The completion query
\"
%s
\"
failed thus: %s
\n
"
,
query
,
PQresStatus
(
PQresultStatus
(
result
)));
query
,
PQresStatus
(
PQresultStatus
(
result
)));
#endif
PQclear
(
result
);
PQclear
(
result
);
result
=
NULL
;
result
=
NULL
;
}
}
...
@@ -777,6 +775,9 @@ char * previous_word(int point, int skip) {
...
@@ -777,6 +775,9 @@ char * previous_word(int point, int skip) {
}
}
#ifdef NOT_USED
/* Surround a string with single quotes. This works for both SQL and
/* Surround a string with single quotes. This works for both SQL and
psql internal. Doesn't work so well yet.
psql internal. Doesn't work so well yet.
*/
*/
...
@@ -798,7 +799,7 @@ char * quote_file_name(char *text, int match_type, char * quote_pointer)
...
@@ -798,7 +799,7 @@ char * quote_file_name(char *text, int match_type, char * quote_pointer)
}
}
#ifdef NOT_USED
static
char
*
dequote_file_name
(
char
*
text
,
char
quote_char
)
static
char
*
dequote_file_name
(
char
*
text
,
char
quote_char
)
{
{
char
*
s
;
char
*
s
;
...
@@ -814,6 +815,7 @@ static char * dequote_file_name(char *text, char quote_char)
...
@@ -814,6 +815,7 @@ static char * dequote_file_name(char *text, char quote_char)
return
s
;
return
s
;
}
}
#endif
#endif
/* NOT_USED */
#endif
/* USE_READLINE */
#endif
/* USE_READLINE */
src/bin/scripts/createdb
View file @
f6689a32
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
#
#
# IDENTIFICATION
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.
5 2000/01/12 13:08:55 ishii
Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.
6 2000/01/12 19:36:36 petere
Exp $
#
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
...
@@ -28,6 +28,7 @@ do
...
@@ -28,6 +28,7 @@ do
case
"
$1
"
in
case
"
$1
"
in
--help
|
-
\?
)
--help
|
-
\?
)
usage
=
t
usage
=
t
break
;;
;;
# options passed on to psql
# options passed on to psql
--host
|
-h
)
--host
|
-h
)
...
@@ -89,7 +90,8 @@ do
...
@@ -89,7 +90,8 @@ do
MB
=
`
echo
$1
|
sed
's/^--encoding=//'
`
MB
=
`
echo
$1
|
sed
's/^--encoding=//'
`
;;
;;
-
*
)
-
*
)
echo
"
$CMDNAME
: Unrecognized option:
$1
. Try -? for help."
echo
"
$CMDNAME
: unrecognized option:
$1
"
echo
"Try -? for help."
exit
1
exit
1
;;
;;
*
)
*
)
...
@@ -104,20 +106,17 @@ do
...
@@ -104,20 +106,17 @@ do
done
done
if
[
"
$usage
"
]
;
then
if
[
"
$usage
"
]
;
then
echo
""
echo
"Usage:
$CMDNAME
[options] dbname [description]"
echo
"Usage:
$CMDNAME
[options] dbname [description]"
echo
""
echo
""
echo
" -h HOSTNAME, --host=HOSTNAME "
echo
" -D, --location=PATH Alternative place to store the database"
echo
" -p PORT, --port=PORT "
echo
" -E, --encoding=ENCODING Multibyte encoding for the database"
echo
" -U USERNAME, --username=USERNAME "
echo
" -h, --host=HOSTNAME Database server host"
echo
" -W, --password "
echo
" -p, --port=PORT Database server port"
echo
" -e, --echo "
echo
" -U, --username=USERNAME Username to connect as"
echo
" -q, --quiet "
echo
" -W, --password Prompt for password"
echo
" -D PATH, --location=PATH "
#??? echo " -e, --echo "
echo
" -E ENCODING --encoding=ENCODING "
echo
" -q, --quiet Don't write any messages"
echo
" -?, --help "
exit
0
echo
""
exit
1
fi
fi
...
@@ -126,17 +125,19 @@ then
...
@@ -126,17 +125,19 @@ then
mbcode
=
`
pg_encoding
"
$MB
"
`
mbcode
=
`
pg_encoding
"
$MB
"
`
if
[
-z
"
$mbcode
"
]
if
[
-z
"
$mbcode
"
]
then
then
echo
"
$CMDNAME
:
\"
$MB
\"
is not a valid encoding name
.
"
echo
"
$CMDNAME
:
\"
$MB
\"
is not a valid encoding name"
exit
1
exit
1
fi
fi
fi
fi
if
[
-z
"
$dbname
"
]
;
then
if
[
-z
"
$dbname
"
]
;
then
echo
"
$CMDNAME
: Missing required argument database name. Try -? for help."
echo
"
$CMDNAME
: missing required argument database name"
echo
"Try -? for help."
exit
1
exit
1
fi
fi
# escape the quotes
dbpath
=
`
echo
$dbpath
|
sed
"s/'/
\\\\\'
/g"
`
dbpath
=
`
echo
$dbpath
|
sed
"s/'/
\\\\\'
/g"
`
dbname
=
`
echo
$dbname
|
sed
's/\"/\\\"/g'
`
dbname
=
`
echo
$dbname
|
sed
's/\"/\\\"/g'
`
...
@@ -147,7 +148,7 @@ withstring=
...
@@ -147,7 +148,7 @@ withstring=
psql
$PSQLOPT
-d
template1
-c
"CREATE DATABASE
\"
$dbname
\"
$withstring
"
psql
$PSQLOPT
-d
template1
-c
"CREATE DATABASE
\"
$dbname
\"
$withstring
"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
$CMDNAME
:
Database creation failed.
"
echo
"
$CMDNAME
:
database creation failed
"
exit
1
exit
1
fi
fi
...
@@ -158,7 +159,7 @@ dbcomment=`echo $dbcomment | sed "s/'/\\\\\'/g"`
...
@@ -158,7 +159,7 @@ dbcomment=`echo $dbcomment | sed "s/'/\\\\\'/g"`
psql
$PSQLOPT
-d
template1
-c
"COMMENT ON DATABASE
\"
$dbname
\"
IS '
$dbcomment
'"
psql
$PSQLOPT
-d
template1
-c
"COMMENT ON DATABASE
\"
$dbname
\"
IS '
$dbcomment
'"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
$CMDNAME
:
Comment creation failed. (Database was created.
)"
echo
"
$CMDNAME
:
comment creation failed (database was created
)"
exit
1
exit
1
fi
fi
...
...
src/bin/scripts/createlang.sh
View file @
f6689a32
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#
#
#
#
# IDENTIFICATION
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.
4 1999/12/17 18:05:32 momjian
Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.
5 2000/01/12 19:36:36 petere
Exp $
#
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
...
@@ -32,16 +32,6 @@ else
...
@@ -32,16 +32,6 @@ else
fi
fi
# ----------
# Find the default PGLIB directory
# ----------
postconfig_result
=
"
`
sh
-c
postconfig 2>/dev/null
`
"
if
[
"
$postconfig_result
"
]
;
then
set
-a
eval
"
$postconfig_result
"
set
+a
fi
# ----------
# ----------
# Get options, language name and dbname
# Get options, language name and dbname
...
@@ -51,6 +41,7 @@ do
...
@@ -51,6 +41,7 @@ do
case
"
$1
"
in
case
"
$1
"
in
--help
|
-
\?
)
--help
|
-
\?
)
usage
=
t
usage
=
t
break
;;
;;
--list
|
-l
)
--list
|
-l
)
list
=
t
list
=
t
...
@@ -115,6 +106,11 @@ do
...
@@ -115,6 +106,11 @@ do
PGLIB
=
`
echo
$1
|
sed
's/^--pglib=//'
`
PGLIB
=
`
echo
$1
|
sed
's/^--pglib=//'
`
;;
;;
-
*
)
echo
"
$CMDNAME
: unrecognized option:
$1
"
echo
"Try -? for help."
exit
1
;;
*
)
*
)
langname
=
"
$1
"
langname
=
"
$1
"
if
[
"
$2
"
]
;
then
if
[
"
$2
"
]
;
then
...
@@ -130,18 +126,15 @@ if [ "$usage" ]; then
...
@@ -130,18 +126,15 @@ if [ "$usage" ]; then
echo
""
echo
""
echo
"Usage:
$CMDNAME
[options] [langname [dbname]]"
echo
"Usage:
$CMDNAME
[options] [langname [dbname]]"
echo
""
echo
""
echo
" -h HOSTNAME, --host=HOSTNAME "
echo
" -h, --host=HOSTNAME Database server host"
echo
" -p PORT, --port=PORT "
echo
" -p, --port=PORT Database server port"
echo
" -U USERNAME, --username=USERNAME "
echo
" -U, --username=USERNAME Username to connect as"
echo
" -l, --list "
echo
" -W, --password Prompt for password"
echo
" -W, --password "
echo
" -d, --dbname=DBNAME Database to install language in"
echo
" -d DBNAME, --database=DBNAME "
echo
" -e, --echo Create some output about what is happening"
echo
" -e, --echo "
echo
" -L, --pglib=PGLIB Find language interpreter in directory PGLIB"
echo
" -D PATH, --location=PATH "
echo
" -l, --list Show a list of currently installed languages"
echo
" -L PGLIB --pglib=PGLIB "
exit
0
echo
" -?, --help "
echo
""
exit
1
fi
fi
if
[
"
$list
"
]
;
then
if
[
"
$list
"
]
;
then
...
@@ -154,7 +147,8 @@ fi
...
@@ -154,7 +147,8 @@ fi
# Check that we have a database
# Check that we have a database
# ----------
# ----------
if
[
-z
"
$dbname
"
]
;
then
if
[
-z
"
$dbname
"
]
;
then
echo
"
$CMDNAME
: Missing required argument database name. Try -? for help."
echo
"
$CMDNAME
: missing required argument database name"
echo
"Try -? for help."
exit
1
exit
1
fi
fi
...
@@ -163,9 +157,10 @@ fi
...
@@ -163,9 +157,10 @@ fi
# Check that we have PGLIB
# Check that we have PGLIB
# ----------
# ----------
if
[
-z
"
$PGLIB
"
]
;
then
if
[
-z
"
$PGLIB
"
]
;
then
echo
"Cannot determine the PostgreSQL lib directory (PGLIB). You must"
echo
"
$CMDNAME
: missing required argument PGLIB directory"
echo
"identify it either with a --pglib option or by setting the PGLIB"
echo
"(This is the directory where the interpreter for the procedural"
echo
"environment variable."
echo
"language is stored. Traditionally, these are installed in whatever"
echo
"'lib' directory was specified at configure time.)"
exit
1
exit
1
fi
fi
...
@@ -191,7 +186,7 @@ case "$langname" in
...
@@ -191,7 +186,7 @@ case "$langname" in
trusted
=
"TRUSTED "
trusted
=
"TRUSTED "
handler
=
"pltcl_call_handler"
;;
handler
=
"pltcl_call_handler"
;;
*
)
*
)
echo
"
$CMDNAME
:
Unsupported language '
$langname
'.
"
echo
"
$CMDNAME
:
unsupported language '
$langname
'
"
echo
"Supported languages are 'plpgsql' and 'pltcl'."
echo
"Supported languages are 'plpgsql' and 'pltcl'."
exit
1
exit
1
;;
;;
...
@@ -203,7 +198,7 @@ esac
...
@@ -203,7 +198,7 @@ esac
# in PGLIB
# in PGLIB
# ----------
# ----------
if
[
!
-f
$PGLIB
/
${
langname
}
__DLSUFFIX__
]
;
then
if
[
!
-f
$PGLIB
/
${
langname
}
__DLSUFFIX__
]
;
then
echo
"
Cannot find the file
$PGLIB
/
${
langname
}
__DLSUFFIX__.
"
echo
"
$CMDNAME
: cannot find the file
$PGLIB
/
${
langname
}
__DLSUFFIX__
"
echo
""
echo
""
echo
"This file contains the call handler for
$lancomp
. By default,"
echo
"This file contains the call handler for
$lancomp
. By default,"
echo
"only PL/pgSQL is built and installed; other languages must be"
echo
"only PL/pgSQL is built and installed; other languages must be"
...
@@ -228,12 +223,12 @@ PSQL="psql -A -t $PSQLOPT -d $dbname -c"
...
@@ -228,12 +223,12 @@ PSQL="psql -A -t $PSQLOPT -d $dbname -c"
# ----------
# ----------
res
=
`
$PSQL
"SELECT oid FROM pg_language WHERE lanname = '
$langname
'"
`
res
=
`
$PSQL
"SELECT oid FROM pg_language WHERE lanname = '
$langname
'"
`
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
Language installation failed.
"
echo
"
$CMDNAME
: external error
"
exit
1
exit
1
fi
fi
if
[
"
$res
"
]
;
then
if
[
"
$res
"
]
;
then
echo
"
The language '
$langname
' is already installed in database
$dbname
.
"
echo
"
$CMDNAME
: '
$langname
' is already installed in database
$dbname
"
exit
2
exit
1
fi
fi
# ----------
# ----------
...
@@ -241,9 +236,7 @@ fi
...
@@ -241,9 +236,7 @@ fi
# ----------
# ----------
res
=
`
$PSQL
"SELECT oid FROM pg_proc WHERE proname = '
$handler
'"
`
res
=
`
$PSQL
"SELECT oid FROM pg_proc WHERE proname = '
$handler
'"
`
if
[
!
-z
"
$res
"
]
;
then
if
[
!
-z
"
$res
"
]
;
then
echo
"The language
$lancomp
isn't created up to now but there is"
echo
"
$CMDNAME
: A function named '
$handler
' already exists. Installation aborted."
echo
"already a function named '
$handler
' declared."
echo
"Language installation aborted."
exit
1
exit
1
fi
fi
...
@@ -252,12 +245,12 @@ fi
...
@@ -252,12 +245,12 @@ fi
# ----------
# ----------
$PSQL
"CREATE FUNCTION
$handler
() RETURNS OPAQUE AS '
$PGLIB
/
${
langname
}
__DLSUFFIX__' LANGUAGE 'C'"
$PSQL
"CREATE FUNCTION
$handler
() RETURNS OPAQUE AS '
$PGLIB
/
${
langname
}
__DLSUFFIX__' LANGUAGE 'C'"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
Language installation failed.
"
echo
"
$CMDNAME
: language installation failed
"
exit
1
exit
1
fi
fi
$PSQL
"CREATE
${
trusted
}
PROCEDURAL LANGUAGE '
$langname
' HANDLER
$handler
LANCOMPILER '
$lancomp
'"
$PSQL
"CREATE
${
trusted
}
PROCEDURAL LANGUAGE '
$langname
' HANDLER
$handler
LANCOMPILER '
$lancomp
'"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
Language installation failed.
"
echo
"
$CMDNAME
: language installation failed
"
exit
1
exit
1
fi
fi
...
...
src/bin/scripts/createuser
View file @
f6689a32
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#
#
#
#
# IDENTIFICATION
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.
4 1999/12/16 20:10:02 momjian
Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.
5 2000/01/12 19:36:36 petere
Exp $
#
#
# Note - this should NOT be setuid.
# Note - this should NOT be setuid.
#
#
...
@@ -41,6 +41,7 @@ do
...
@@ -41,6 +41,7 @@ do
case
"
$1
"
in
case
"
$1
"
in
--help
|
-
\?
)
--help
|
-
\?
)
usage
=
t
usage
=
t
break
;;
;;
# options passed on to psql
# options passed on to psql
--host
|
-h
)
--host
|
-h
)
...
@@ -110,7 +111,8 @@ do
...
@@ -110,7 +111,8 @@ do
PwPrompt
=
t
PwPrompt
=
t
;;
;;
-
*
)
-
*
)
echo
"
$CMDNAME
: Unrecognized option:
$1
. Try -? for help."
echo
"
$CMDNAME
: unrecognized option:
$1
"
echo
"Try -? for help."
exit
1
exit
1
;;
;;
*
)
*
)
...
@@ -121,29 +123,26 @@ do
...
@@ -121,29 +123,26 @@ do
done
done
if
[
"
$usage
"
]
;
then
if
[
"
$usage
"
]
;
then
echo
""
echo
"Usage:
$CMDNAME
[options] [username]"
echo
"Usage:
$CMDNAME
[options] [username]"
echo
""
echo
""
echo
" -h HOSTNAME, --host=HOSTNAME "
echo
" -d, --createdb User can create new databases"
echo
" -p PORT, --port=PORT "
echo
" -D, --no-createdb User cannot create databases"
echo
" -d, --createdb "
echo
" -a, --adduser User can add new users"
echo
" -D, --no-createdb "
echo
" -A, --no-adduser User cannot add new users"
echo
" -a, --adduser "
echo
" -i, --sysid=SYSID Select sysid for new user"
echo
" -A, --no-adduser "
echo
" -P, --pwprompt Assign a password to new user"
echo
" -i SYSID, --sysid=SYSID "
echo
" -h, --host=HOSTNAME Database server host"
echo
" -P, --pwprompt "
echo
" -p, --port=PORT Database server port"
echo
" -U USERNAME, --username=USERNAME (for connect to db)"
echo
" -U, --username=USERNAME Username to connect as (not the one to create)"
echo
" -W, --password (for connect to db)"
echo
" -W, --password Prompt for password to connect"
echo
" -e, --echo "
#??? echo " -e, --echo "
echo
" -q, --quiet "
echo
" -q, --quiet Don't write any messages"
echo
" -?, --help "
exit
0
echo
""
exit
1
fi
fi
if
[
"
$SysID
"
]
;
then
if
[
"
$SysID
"
]
;
then
if
[
"
$SysID
"
!=
"
`
echo
$SysID
|
sed
's/[^0-9]//g'
`
"
]
;
then
if
[
"
$SysID
"
!=
"
`
echo
$SysID
|
sed
's/[^0-9]//g'
`
"
]
;
then
echo
"
$CMDNAME
:
User sysid must be a positive number.
"
echo
"
$CMDNAME
:
user sysid must be a positive number
"
exit
1
exit
1
fi
fi
fi
fi
...
@@ -204,7 +203,7 @@ SUBQUERY=
...
@@ -204,7 +203,7 @@ SUBQUERY=
psql
$PSQLOPT
-d
template1
-c
"
$QUERY
"
psql
$PSQLOPT
-d
template1
-c
"
$QUERY
"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
$CMDNAME
:
Creation of user
\"
$NewUser
\"
failed.
"
echo
"
$CMDNAME
:
creation of user
\"
$NewUser
\"
failed
"
exit
1
exit
1
fi
fi
...
...
src/bin/scripts/dropdb
View file @
f6689a32
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#
#
#
#
# IDENTIFICATION
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.
4 1999/12/16 20:10:02 momjian
Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.
5 2000/01/12 19:36:36 petere
Exp $
#
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
...
@@ -96,23 +96,21 @@ done
...
@@ -96,23 +96,21 @@ done
if
[
"
$usage
"
]
;
then
if
[
"
$usage
"
]
;
then
echo
""
echo
"Usage:
$CMDNAME
[options] dbname"
echo
"Usage:
$CMDNAME
[options] dbname"
echo
""
echo
""
echo
" -h HOSTNAME, --host=HOSTNAME "
echo
" -h, --host=HOSTNAME Database server host"
echo
" -p PORT, --port=PORT "
echo
" -p, --port=PORT Database server port"
echo
" -u USERNAME, --username=USERNAME "
echo
" -U, --username=USERNAME Username to connect as"
echo
" -W, --password "
echo
" -W, --password Prompt for password"
echo
" -e, --echo "
echo
" -i, --interactive Prompt before deleting anything"
echo
" -q, --quiet "
#??? echo " -e, --echo "
echo
" -i, --interactive "
echo
" -q, --quiet Don't write any messages"
echo
" -?, --help "
exit
0
echo
""
exit
1
fi
fi
if
[
-z
"
$dbname
"
]
;
then
if
[
-z
"
$dbname
"
]
;
then
echo
"
$CMDNAME
: Missing required argument database name. Try -? for help."
echo
"
$CMDNAME
: missing required argument database name"
echo
"Try -? for help."
exit
1
exit
1
fi
fi
...
@@ -131,7 +129,7 @@ dbname=`echo $dbname | sed 's/\"/\\\"/g'`
...
@@ -131,7 +129,7 @@ dbname=`echo $dbname | sed 's/\"/\\\"/g'`
psql
$PSQLOPT
-d
template1
-c
"DROP DATABASE
\"
$dbname
\"
"
psql
$PSQLOPT
-d
template1
-c
"DROP DATABASE
\"
$dbname
\"
"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
$CMDNAME
:
Database removal failed.
"
echo
"
$CMDNAME
:
database removal failed
"
exit
1
exit
1
fi
fi
...
...
src/bin/scripts/droplang
View file @
f6689a32
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#
#
#
#
# IDENTIFICATION
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.
4 1999/12/16 20:10:02 momjian
Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.
5 2000/01/12 19:36:36 petere
Exp $
#
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
...
@@ -40,6 +40,7 @@ do
...
@@ -40,6 +40,7 @@ do
case
"
$1
"
in
case
"
$1
"
in
--help
|
-
\?
)
--help
|
-
\?
)
usage
=
t
usage
=
t
break
;;
;;
--list
|
-l
)
--list
|
-l
)
list
=
t
list
=
t
...
@@ -94,6 +95,11 @@ do
...
@@ -94,6 +95,11 @@ do
dbname
=
`
echo
$1
|
sed
's/^--database=//'
`
dbname
=
`
echo
$1
|
sed
's/^--database=//'
`
;;
;;
-
*
)
echo
"
$CMDNAME
: unrecognized option:
$1
"
echo
"Try -? for help."
exit
1
;;
*
)
*
)
langname
=
"
$1
"
langname
=
"
$1
"
if
[
"
$2
"
]
;
then
if
[
"
$2
"
]
;
then
...
@@ -108,18 +114,16 @@ done
...
@@ -108,18 +114,16 @@ done
if
[
"
$usage
"
]
;
then
if
[
"
$usage
"
]
;
then
echo
""
echo
""
echo
"Usage:
$CMDNAME
[options] [lang
uag
e [dbname]]"
echo
"Usage:
$CMDNAME
[options] [lang
nam
e [dbname]]"
echo
""
echo
""
echo
" -h HOSTNAME, --host=HOSTNAME "
echo
" -h, --host=HOSTNAME Database server host"
echo
" -p PORT, --port=PORT "
echo
" -p, --port=PORT Database server port"
echo
" -u USERNAME, --username=USERNAME "
echo
" -U, --username=USERNAME Username to connect as"
echo
" -W, --password "
echo
" -W, --password Prompt for password"
echo
" -d DBNAME --database=DBNAME "
echo
" -d, --dbname=DBNAME Database to remove language from"
echo
" -e, --echo "
echo
" -e, --echo Create some output about what is happening"
echo
" -q, --quiet "
echo
" -l, --list Show a list of currently installed languages"
echo
" -?, --help "
exit
0
echo
""
exit
1
fi
fi
...
@@ -133,7 +137,8 @@ fi
...
@@ -133,7 +137,8 @@ fi
# Check that we have a database
# Check that we have a database
# ----------
# ----------
if
[
-z
"
$dbname
"
]
;
then
if
[
-z
"
$dbname
"
]
;
then
echo
"
$CMDNAME
: Missing required argument database name. Try -? for help."
echo
"
$CMDNAME
: missing required argument database name"
echo
"Try -? for help."
exit
1
exit
1
fi
fi
...
@@ -159,8 +164,8 @@ case "$langname" in
...
@@ -159,8 +164,8 @@ case "$langname" in
handler
=
"pltcl_call_handler"
handler
=
"pltcl_call_handler"
;;
;;
*
)
*
)
echo
"
$CMDNAME
:
Unsupported language '
$langname
'.
"
echo
"
$CMDNAME
:
unsupported language '
$langname
'
"
echo
"
Supported languages are 'plpgsql' and 'pltcl'."
echo
"Supported languages are 'plpgsql' and 'pltcl'."
exit
1
exit
1
;;
;;
esac
esac
...
@@ -180,11 +185,11 @@ PSQL="psql -A -t $PSQLOPT -d $dbname -c"
...
@@ -180,11 +185,11 @@ PSQL="psql -A -t $PSQLOPT -d $dbname -c"
# ----------
# ----------
res
=
`
$PSQL
"SELECT oid FROM pg_language WHERE lanname = '
$langname
'"
`
res
=
`
$PSQL
"SELECT oid FROM pg_language WHERE lanname = '
$langname
'"
`
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
Language removal failed.
"
echo
"
$CMDNAME
: external error
"
exit
1
exit
1
fi
fi
if
[
-z
"
$res
"
]
;
then
if
[
-z
"
$res
"
]
;
then
echo
"
The language '
$langname
' isn't installed in database
$dbname
.
"
echo
"
$CMDNAME
: '
$langname
' is not installed in database
$dbname
"
exit
1
exit
1
fi
fi
...
@@ -194,13 +199,12 @@ fi
...
@@ -194,13 +199,12 @@ fi
# ----------
# ----------
res
=
`
$PSQL
"SELECT COUNT(proname) FROM pg_proc P, pg_language L WHERE P.prolang = L.oid AND L.lanname = '
$langname
'"
`
res
=
`
$PSQL
"SELECT COUNT(proname) FROM pg_proc P, pg_language L WHERE P.prolang = L.oid AND L.lanname = '
$langname
'"
`
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
Language removal failed.
"
echo
"
$CMDNAME
: external error
"
exit
1
exit
1
fi
fi
if
[
$res
-ne
0
]
;
then
if
[
$res
-ne
0
]
;
then
echo
"There are
$res
functions/trigger procedures declared in language"
echo
"
$CMDNAME
: There are
$res
functions/trigger procedures declared in language"
echo
"
$lancomp
."
echo
"
$lancomp
. Language not removed."
echo
"Language not removed."
exit
1
exit
1
fi
fi
...
@@ -209,12 +213,12 @@ fi
...
@@ -209,12 +213,12 @@ fi
# ----------
# ----------
$PSQL
"DROP PROCEDURAL LANGUAGE '
$langname
'"
$PSQL
"DROP PROCEDURAL LANGUAGE '
$langname
'"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
Language removal failed.
"
echo
"
$CMDNAME
: language removal failed
"
exit
1
exit
1
fi
fi
$PSQL
"DROP FUNCTION
$handler
()"
$PSQL
"DROP FUNCTION
$handler
()"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
Language removal failed.
"
echo
"
$CMDNAME
: language removal failed
"
exit
1
exit
1
fi
fi
...
...
src/bin/scripts/dropuser
View file @
f6689a32
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#
#
#
#
# IDENTIFICATION
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.
4 1999/12/16 20:10:02 momjian
Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.
5 2000/01/12 19:36:36 petere
Exp $
#
#
# Note - this should NOT be setuid.
# Note - this should NOT be setuid.
#
#
...
@@ -36,6 +36,7 @@ do
...
@@ -36,6 +36,7 @@ do
case
"
$1
"
in
case
"
$1
"
in
--help
|
-
\?
)
--help
|
-
\?
)
usage
=
t
usage
=
t
break
;;
;;
# options passed on to psql
# options passed on to psql
--host
|
-h
)
--host
|
-h
)
...
@@ -99,16 +100,14 @@ if [ "$usage" ]; then
...
@@ -99,16 +100,14 @@ if [ "$usage" ]; then
echo
""
echo
""
echo
"Usage:
$CMDNAME
[options] [username]"
echo
"Usage:
$CMDNAME
[options] [username]"
echo
""
echo
""
echo
" -h HOSTNAME, --host=HOSTNAME "
echo
" -h, --host=HOSTNAME Database server host"
echo
" -p PORT, --port=PORT "
echo
" -p, --port=PORT Database server port"
echo
" -u USERNAME, --username=USERNAME (for connect to db)"
echo
" -U, --username=USERNAME Username to connect as (not the one to drop)"
echo
" -W, --password "
echo
" -W, --password Prompt for password to connect"
echo
" -e, --echo "
echo
" -i, --interactive Prompt before deleting anything"
echo
" -q, --quiet "
#??? echo " -e, --echo "
echo
" -i, --interactive "
echo
" -q, --quiet Don't write any messages"
echo
" -?, --help "
exit
0
echo
""
exit
1
fi
fi
# Prompt for username if missing
# Prompt for username if missing
...
@@ -135,7 +134,7 @@ DelUser=`echo $DelUser | sed 's/\"/\\\"/g'`
...
@@ -135,7 +134,7 @@ DelUser=`echo $DelUser | sed 's/\"/\\\"/g'`
psql
$PSQLOPT
-d
template1
-c
"DROP USER
\"
$DelUser
\"
"
psql
$PSQLOPT
-d
template1
-c
"DROP USER
\"
$DelUser
\"
"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"
$CMDNAME
:
Deletion of user
\"
$DelUser
\"
failed.
"
echo
"
$CMDNAME
:
deletion of user
\"
$DelUser
\"
failed
"
exit
1
exit
1
fi
fi
...
...
src/bin/scripts/vacuumdb
View file @
f6689a32
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
#
#
# IDENTIFICATION
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.
7 1999/12/18 08:46:44 momjian
Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.
8 2000/01/12 19:36:36 petere
Exp $
#
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
...
@@ -29,6 +29,7 @@ do
...
@@ -29,6 +29,7 @@ do
case
"
$1
"
in
case
"
$1
"
in
--help
|
-
\?
)
--help
|
-
\?
)
usage
=
t
usage
=
t
break
;;
;;
# options passed on to psql
# options passed on to psql
--host
|
-h
)
--host
|
-h
)
...
@@ -86,7 +87,7 @@ do
...
@@ -86,7 +87,7 @@ do
--analyze
|
-z
)
--analyze
|
-z
)
analyze
=
"ANALYZE "
analyze
=
"ANALYZE "
;;
;;
--all
db
|
-a
)
--all
|
-a
)
alldb
=
Y
alldb
=
Y
;;
;;
--table
|
-t
)
--table
|
-t
)
...
@@ -103,7 +104,8 @@ do
...
@@ -103,7 +104,8 @@ do
;;
;;
-
*
)
-
*
)
echo
"
$CMDNAME
: Unrecognized option:
$1
. Try -? for help."
echo
"
$CMDNAME
: unrecognized option:
$1
"
echo
"Try -? for help."
exit
1
exit
1
;;
;;
*
)
*
)
...
@@ -114,42 +116,43 @@ do
...
@@ -114,42 +116,43 @@ do
done
done
if
[
"
$usage
"
]
;
then
if
[
"
$usage
"
]
;
then
echo
""
echo
"Usage:
$CMDNAME
[options] [dbname]"
echo
"Usage:
$CMDNAME
[options] [dbname]"
echo
""
echo
""
echo
" -h HOSTNAME, --host=HOSTNAME "
echo
" -h, --host=HOSTNAME Database server host"
echo
" -p PORT, --port=PORT "
echo
" -p, --port=PORT Database server port"
echo
" -u USERNAME, --username=USERNAME "
echo
" -U, --username=USERNAME Username to connect as"
echo
" -W, --password "
echo
" -W, --password Prompt for password"
echo
" -d DBNAME, --database=DBNAME "
echo
" -d, --dbname=DBNAME Database to vacuum"
echo
" -z, --analyze "
echo
" -a, --all Vacuum all databases"
echo
" -a, --alldb "
echo
" -z, --analyze Update optimizer hints"
echo
" -t TABLE[(columns)], --table=TABLE[(columns)]"
echo
" -t, --table='TABLE[(columns)]' Vacuum specific table only"
echo
" -v, --verbose "
echo
" -v, --verbose Write a lot of output"
echo
" -e, --echo "
#??? echo " -e, --echo "
echo
" -q, --quiet "
echo
" -q, --quiet Don't write any output"
echo
" -?, --help "
exit
0
echo
""
exit
1
fi
fi
if
[
!
-z
"
$alldb
"
]
;
then
if
[
"
$alldb
"
]
;
then
dbname
=
"
`
psql
$PASSWDOPT
$AUTHOPT
$PGHOSTOPT
$PGPORTOPT
-q
-t
-A
-d
template1
-c
'SELECT datname FROM pg_database'
`
"
if
[
"
$dbname
"
-o
"
$table
"
]
;
then
echo
"
$CMDNAME
: cannot vacuum all databases and a specific one at the same time"
exit
1
fi
dbname
=
"
`
psql
$PSQLOPT
-q
-t
-A
-d
template1
-c
'SELECT datname FROM pg_database'
`
"
fi
fi
if
[
-z
"
$dbname
"
]
;
then
if
[
-z
"
$dbname
"
]
;
then
echo
"
$CMDNAME
: Missing required argument database name. Try -? for help."
echo
"
$CMDNAME
: missing required argument database name"
echo
"Try -? for help."
exit
1
exit
1
fi
fi
for
db
in
$dbname
for
db
in
$dbname
do
do
psql
$P
ASSWDOPT
-tq
$AUTHOPT
$PGHOSTOPT
$PGPORTOPT
-c
"vacuum
$verbose
$analyze
$table
"
$db
psql
$P
SQLOPT
-c
"vacuum
$verbose
$analyze
$table
"
-d
$dbname
done
done
if
[
$?
-ne
0
]
if
[
$?
-ne
0
]
;
then
then
echo
"
$CMDNAME
: vacuum failed"
echo
"
$CMDNAME
: Vacuum failed."
exit
1
exit
1
fi
fi
...
...
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