Commit 9ceb5d8a authored by Peter Eisentraut's avatar Peter Eisentraut

Fixed psql double quoting of SQL ids

Fixed libpq printing functions
parent 4842ef86
...@@ -494,7 +494,7 @@ soon.) ...@@ -494,7 +494,7 @@ soon.)
<function>PQdb</function> <function>PQdb</function>
Returns the database name of the connection. Returns the database name of the connection.
<synopsis> <synopsis>
const char *PQdb(const PGconn *conn) char *PQdb(const PGconn *conn)
</synopsis> </synopsis>
PQdb and the next several functions return the values established PQdb and the next several functions return the values established
at connection. These values are fixed for the life of the PGconn at connection. These values are fixed for the life of the PGconn
...@@ -507,7 +507,7 @@ object. ...@@ -507,7 +507,7 @@ object.
<function>PQuser</function> <function>PQuser</function>
Returns the user name of the connection. Returns the user name of the connection.
<synopsis> <synopsis>
const char *PQuser(const PGconn *conn) char *PQuser(const PGconn *conn)
</synopsis> </synopsis>
</para> </para>
</listitem> </listitem>
...@@ -517,7 +517,7 @@ const char *PQuser(const PGconn *conn) ...@@ -517,7 +517,7 @@ const char *PQuser(const PGconn *conn)
<function>PQpass</function> <function>PQpass</function>
Returns the password of the connection. Returns the password of the connection.
<synopsis> <synopsis>
const char *PQpass(const PGconn *conn) char *PQpass(const PGconn *conn)
</synopsis> </synopsis>
</para> </para>
</listitem> </listitem>
...@@ -527,7 +527,7 @@ const char *PQpass(const PGconn *conn) ...@@ -527,7 +527,7 @@ const char *PQpass(const PGconn *conn)
<function>PQhost</function> <function>PQhost</function>
Returns the server host name of the connection. Returns the server host name of the connection.
<synopsis> <synopsis>
const char *PQhost(const PGconn *conn) char *PQhost(const PGconn *conn)
</synopsis> </synopsis>
</para> </para>
</listitem> </listitem>
...@@ -537,7 +537,7 @@ const char *PQhost(const PGconn *conn) ...@@ -537,7 +537,7 @@ const char *PQhost(const PGconn *conn)
<function>PQport</function> <function>PQport</function>
Returns the port of the connection. Returns the port of the connection.
<synopsis> <synopsis>
const char *PQport(const PGconn *conn) char *PQport(const PGconn *conn)
</synopsis> </synopsis>
</para> </para>
</listitem> </listitem>
...@@ -547,7 +547,7 @@ const char *PQport(const PGconn *conn) ...@@ -547,7 +547,7 @@ const char *PQport(const PGconn *conn)
<function>PQtty</function> <function>PQtty</function>
Returns the debug tty of the connection. Returns the debug tty of the connection.
<synopsis> <synopsis>
const char *PQtty(const PGconn *conn) char *PQtty(const PGconn *conn)
</synopsis> </synopsis>
</para> </para>
</listitem> </listitem>
...@@ -557,7 +557,7 @@ const char *PQtty(const PGconn *conn) ...@@ -557,7 +557,7 @@ const char *PQtty(const PGconn *conn)
<function>PQoptions</function> <function>PQoptions</function>
Returns the backend options used in the connection. Returns the backend options used in the connection.
<synopsis> <synopsis>
const char *PQoptions(const PGconn *conn) char *PQoptions(const PGconn *conn)
</synopsis> </synopsis>
</para> </para>
</listitem> </listitem>
...@@ -602,7 +602,7 @@ ConnStatusType PQstatus(const PGconn *conn) ...@@ -602,7 +602,7 @@ ConnStatusType PQstatus(const PGconn *conn)
Returns the error message most recently generated by Returns the error message most recently generated by
an operation on the connection. an operation on the connection.
<synopsis> <synopsis>
const char *PQerrorMessage(const PGconn* conn); char *PQerrorMessage(const PGconn* conn);
</synopsis> </synopsis>
</para> </para>
...@@ -790,7 +790,7 @@ exposes a bug in the client software. ...@@ -790,7 +790,7 @@ exposes a bug in the client software.
Converts the enumerated type returned by PQresultStatus into Converts the enumerated type returned by PQresultStatus into
a string constant describing the status code. a string constant describing the status code.
<synopsis> <synopsis>
const char *PQresStatus(ExecStatusType status); char *PQresStatus(ExecStatusType status);
</synopsis> </synopsis>
</para> </para>
</listitem> </listitem>
...@@ -801,7 +801,7 @@ const char *PQresStatus(ExecStatusType status); ...@@ -801,7 +801,7 @@ const char *PQresStatus(ExecStatusType status);
returns the error message associated with the query, or an empty string returns the error message associated with the query, or an empty string
if there was no error. if there was no error.
<synopsis> <synopsis>
const char *PQresultErrorMessage(const PGresult *res); char *PQresultErrorMessage(const PGresult *res);
</synopsis> </synopsis>
Immediately following a <function>PQexec</function> or <function>PQgetResult</function> Immediately following a <function>PQexec</function> or <function>PQgetResult</function>
call, <function>PQerrorMessage</function> (on the connection) will return the same call, <function>PQerrorMessage</function> (on the connection) will return the same
...@@ -855,7 +855,7 @@ extracts data from a <acronym>BINARY</acronym> cursor. ...@@ -855,7 +855,7 @@ extracts data from a <acronym>BINARY</acronym> cursor.
Returns the field (attribute) name associated with the given field index. Returns the field (attribute) name associated with the given field index.
Field indices start at 0. Field indices start at 0.
<synopsis> <synopsis>
const char *PQfname(const PGresult *res, char *PQfname(const PGresult *res,
int field_index); int field_index);
</synopsis> </synopsis>
</para> </para>
...@@ -931,9 +931,9 @@ int PQfmod(const PGresult *res, ...@@ -931,9 +931,9 @@ int PQfmod(const PGresult *res,
of a PGresult. of a PGresult.
Tuple and field indices start at 0. Tuple and field indices start at 0.
<synopsis> <synopsis>
const char* PQgetvalue(const PGresult *res, char* PQgetvalue(const PGresult *res,
int tup_num, int tup_num,
int field_num); int field_num);
</synopsis> </synopsis>
For most queries, the value returned by <function>PQgetvalue</function> For most queries, the value returned by <function>PQgetvalue</function>
is a null-terminated <acronym>ASCII</acronym> string representation is a null-terminated <acronym>ASCII</acronym> string representation
...@@ -991,7 +991,7 @@ int PQgetisnull(const PGresult *res, ...@@ -991,7 +991,7 @@ int PQgetisnull(const PGresult *res,
Returns the command status string from the SQL command that Returns the command status string from the SQL command that
generated the PGresult. generated the PGresult.
<synopsis> <synopsis>
const char * PQcmdStatus(const PGresult *res); char * PQcmdStatus(const PGresult *res);
</synopsis> </synopsis>
</para> </para>
</listitem> </listitem>
...@@ -1001,7 +1001,7 @@ const char * PQcmdStatus(const PGresult *res); ...@@ -1001,7 +1001,7 @@ const char * PQcmdStatus(const PGresult *res);
<function>PQcmdTuples</function> <function>PQcmdTuples</function>
Returns the number of rows affected by the SQL command. Returns the number of rows affected by the SQL command.
<synopsis> <synopsis>
const char * PQcmdTuples(const PGresult *res); char * PQcmdTuples(const PGresult *res);
</synopsis> </synopsis>
If the <acronym>SQL</acronym> command that generated the If the <acronym>SQL</acronym> command that generated the
PGresult was INSERT, UPDATE or DELETE, this returns a PGresult was INSERT, UPDATE or DELETE, this returns a
...@@ -1032,7 +1032,7 @@ Oid PQoidValue(const PGresult *res); ...@@ -1032,7 +1032,7 @@ Oid PQoidValue(const PGresult *res);
inserted, if the <acronym>SQL</acronym> command was an INSERT. inserted, if the <acronym>SQL</acronym> command was an INSERT.
Otherwise, returns an empty string. Otherwise, returns an empty string.
<synopsis> <synopsis>
const char * PQoidStatus(const PGresult *res); char * PQoidStatus(const PGresult *res);
</synopsis> </synopsis>
The function is deprecated in favor of <function>PQoidValue</function> The function is deprecated in favor of <function>PQoidValue</function>
and is not thread-safe. and is not thread-safe.
...@@ -1050,25 +1050,25 @@ void PQprint(FILE* fout, /* output stream */ ...@@ -1050,25 +1050,25 @@ void PQprint(FILE* fout, /* output stream */
const PQprintOpt *po); const PQprintOpt *po);
struct { struct {
int header; /* print output field headings and row count */ pqbool header; /* print output field headings and row count */
int align; /* fill align the fields */ pqbool align; /* fill align the fields */
int standard; /* old brain dead format */ pqbool standard; /* old brain dead format */
int html3; /* output html tables */ pqbool html3; /* output html tables */
int expanded; /* expand tables */ pqbool expanded; /* expand tables */
int pager; /* use pager for output if needed */ pqbool pager; /* use pager for output if needed */
char *fieldSep; /* field separator */ char *fieldSep; /* field separator */
char *tableOpt; /* insert to HTML &lt;table ...&gt; */ char *tableOpt; /* insert to HTML &lt;table ...&gt; */
char *caption; /* HTML &lt;caption&gt; */ char *caption; /* HTML &lt;caption&gt; */
char **fieldName; /* null terminated array of replacement field names */ char **fieldName; /* null terminated array of replacement field names */
} PQprintOpt; } PQprintOpt;
</synopsis> </synopsis>
This function was formerly used by <application>psql</application> This function was formerly used by <application>psql</application>
to print query results, but this is no longer the case and this to print query results, but this is no longer the case and this
function is no longer supported. function is no longer actively supported.
</para> </para>
</listitem> </listitem>
</listitem>
<listitem> <listitem>
<para> <para>
<function>PQclear</function> <function>PQclear</function>
......
This diff is collapsed.
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.11 2000/01/29 16:58:48 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.12 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "common.h" #include "common.h"
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <unistd.h> /* for write() */ #include <unistd.h> /* for write() */
#else #else
#include <io.h> /* for _write() */ #include <io.h> /* for _write() */
#include <win32.h>
#endif #endif
#include <libpq-fe.h> #include <libpq-fe.h>
...@@ -37,18 +38,10 @@ ...@@ -37,18 +38,10 @@
#include "prompt.h" #include "prompt.h"
#include "print.h" #include "print.h"
#ifdef WIN32
#define popen(x,y) _popen(x,y)
#define pclose(x) _pclose(x)
#define write(a,b,c) _write(a,b,c)
#endif
/* xstrdup() /*
*
* "Safe" wrapper around strdup() * "Safe" wrapper around strdup()
* (Using this also avoids writing #ifdef HAVE_STRDUP in every file :)
*/ */
char * char *
xstrdup(const char *string) xstrdup(const char *string)
...@@ -57,7 +50,8 @@ xstrdup(const char *string) ...@@ -57,7 +50,8 @@ xstrdup(const char *string)
if (!string) if (!string)
{ {
fprintf(stderr, "%s: xstrdup: cannot duplicate null pointer\n", pset.progname); fprintf(stderr, "%s: xstrdup: cannot duplicate null pointer (internal error)\n",
pset.progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
tmp = strdup(string); tmp = strdup(string);
...@@ -133,7 +127,7 @@ setQFout(const char *fname) ...@@ -133,7 +127,7 @@ setQFout(const char *fname)
/* /*
* Error reporting for scripts. Errors should look like * Error reporting for scripts. Errors should look like
* filename:lineno: message * psql:filename:lineno: message
* *
*/ */
void void
...@@ -152,8 +146,11 @@ psql_error(const char *fmt, ...) ...@@ -152,8 +146,11 @@ psql_error(const char *fmt, ...)
va_end(ap); va_end(ap);
} }
/* for backend NOTICES */
/*
* for backend NOTICES
*/
void void
NoticeProcessor(void * arg, const char * message) NoticeProcessor(void * arg, const char * message)
{ {
...@@ -184,7 +181,6 @@ simple_prompt(const char *prompt, int maxlen, bool echo) ...@@ -184,7 +181,6 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
struct termios t_orig, struct termios t_orig,
t; t;
#endif #endif
destination = (char *) malloc(maxlen + 2); destination = (char *) malloc(maxlen + 2);
...@@ -240,8 +236,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo) ...@@ -240,8 +236,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
* Before we start a query, we enable a SIGINT signal catcher that sends a * Before we start a query, we enable a SIGINT signal catcher that sends a
* cancel request to the backend. Note that sending the cancel directly from * cancel request to the backend. Note that sending the cancel directly from
* the signal handler is safe because PQrequestCancel() is written to make it * the signal handler is safe because PQrequestCancel() is written to make it
* so. We have to be very careful what else we do in the signal handler. This * so. We use write() to print to stdout because it's better to use simple
* includes using write() for output. * facilities in a signal handler.
*/ */
static PGconn *cancelConn; static PGconn *cancelConn;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# #
# Copyright 2000 by PostgreSQL Global Development Group # Copyright 2000 by PostgreSQL Global Development Group
# #
# $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.3 2000/01/29 16:58:48 petere Exp $ # $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.4 2000/02/07 23:10:06 petere Exp $
################################################################# #################################################################
# #
...@@ -56,6 +56,8 @@ struct _helpStruct ...@@ -56,6 +56,8 @@ struct _helpStruct
static struct _helpStruct QL_HELP[] = { static struct _helpStruct QL_HELP[] = {
"; ";
$count = 0;
foreach $file (sort readdir DIR) { foreach $file (sort readdir DIR) {
my ($cmdname, $cmddesc, $cmdsynopsis); my ($cmdname, $cmddesc, $cmdsynopsis);
$file =~ /\.sgml$/ || next; $file =~ /\.sgml$/ || next;
...@@ -84,6 +86,7 @@ foreach $file (sort readdir DIR) { ...@@ -84,6 +86,7 @@ foreach $file (sort readdir DIR) {
$cmdsynopsis =~ s/\"/\\"/g; $cmdsynopsis =~ s/\"/\\"/g;
print OUT " { \"$cmdname\",\n \"$cmddesc\",\n \"$cmdsynopsis\" },\n\n"; print OUT " { \"$cmdname\",\n \"$cmddesc\",\n \"$cmdsynopsis\" },\n\n";
$count++;
} }
else { else {
print STDERR "$0: parsing file '$file' failed at or near line $. (N='$cmdname' D='$cmddesc')\n"; print STDERR "$0: parsing file '$file' failed at or near line $. (N='$cmdname' D='$cmddesc')\n";
...@@ -94,6 +97,10 @@ print OUT " ...@@ -94,6 +97,10 @@ print OUT "
{ NULL, NULL, NULL } /* End of list marker */ { NULL, NULL, NULL } /* End of list marker */
}; };
#define QL_HELP_COUNT $count
#endif /* $define */ #endif /* $define */
"; ";
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.15 2000/01/29 16:58:48 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.16 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "describe.h" #include "describe.h"
...@@ -56,7 +56,7 @@ describeAggregates(const char *name) ...@@ -56,7 +56,7 @@ describeAggregates(const char *name)
if (name) if (name)
{ {
strcat(buf, " AND a.aggname ~* '"); strcat(buf, " AND a.aggname ~* '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -71,7 +71,7 @@ describeAggregates(const char *name) ...@@ -71,7 +71,7 @@ describeAggregates(const char *name)
if (name) if (name)
{ {
strcat(buf, " AND a.aggname ~* '"); strcat(buf, " AND a.aggname ~* '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -125,7 +125,7 @@ describeFunctions(const char *name, bool verbose) ...@@ -125,7 +125,7 @@ describeFunctions(const char *name, bool verbose)
if (name) if (name)
{ {
strcat(buf, " AND p.proname ~* '"); strcat(buf, " AND p.proname ~* '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -169,7 +169,7 @@ describeTypes(const char *name, bool verbose) ...@@ -169,7 +169,7 @@ describeTypes(const char *name, bool verbose)
if (name) if (name)
{ {
strcat(buf, " AND t.typname ~* '"); strcat(buf, " AND t.typname ~* '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "' "); strcat(buf, "' ");
} }
...@@ -215,7 +215,7 @@ describeOperators(const char *name) ...@@ -215,7 +215,7 @@ describeOperators(const char *name)
" o.oprright = t2.oid\n"); " o.oprright = t2.oid\n");
if (name) if (name)
{ {
strcat(buf, " AND o.oprname ~ '"); strcat(buf, " AND o.oprname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -233,7 +233,7 @@ describeOperators(const char *name) ...@@ -233,7 +233,7 @@ describeOperators(const char *name)
" o.oprright = t1.oid\n"); " o.oprright = t1.oid\n");
if (name) if (name)
{ {
strcat(buf, "AND o.oprname ~ '"); strcat(buf, "AND o.oprname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -251,7 +251,7 @@ describeOperators(const char *name) ...@@ -251,7 +251,7 @@ describeOperators(const char *name)
" o.oprleft = t1.oid\n"); " o.oprleft = t1.oid\n");
if (name) if (name)
{ {
strcat(buf, "AND o.oprname ~ '"); strcat(buf, "AND o.oprname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -346,7 +346,7 @@ permissionsList(const char *name) ...@@ -346,7 +346,7 @@ permissionsList(const char *name)
" relname !~ '^pg_'\n"); " relname !~ '^pg_'\n");
if (name) if (name)
{ {
strcat(descbuf, " AND relname ~ '"); strcat(descbuf, " AND relname ~ '^");
strncat(descbuf, name, REGEXP_CUTOFF); strncat(descbuf, name, REGEXP_CUTOFF);
strcat(descbuf, "'\n"); strcat(descbuf, "'\n");
} }
...@@ -391,7 +391,7 @@ objectDescription(const char *object) ...@@ -391,7 +391,7 @@ objectDescription(const char *object)
"WHERE a.oid = d.objoid\n"); "WHERE a.oid = d.objoid\n");
if (object) if (object)
{ {
strcat(descbuf, " AND a.aggname ~* '"); strcat(descbuf, " AND a.aggname ~* '^");
strncat(descbuf, object, REGEXP_CUTOFF); strncat(descbuf, object, REGEXP_CUTOFF);
strcat(descbuf, "'\n"); strcat(descbuf, "'\n");
} }
...@@ -403,7 +403,7 @@ objectDescription(const char *object) ...@@ -403,7 +403,7 @@ objectDescription(const char *object)
"WHERE p.oid = d.objoid AND (p.pronargs = 0 or oidvectortypes(p.proargtypes) != '')\n"); "WHERE p.oid = d.objoid AND (p.pronargs = 0 or oidvectortypes(p.proargtypes) != '')\n");
if (object) if (object)
{ {
strcat(descbuf, " AND p.proname ~* '"); strcat(descbuf, " AND p.proname ~* '^");
strncat(descbuf, object, REGEXP_CUTOFF); strncat(descbuf, object, REGEXP_CUTOFF);
strcat(descbuf, "'\n"); strcat(descbuf, "'\n");
} }
...@@ -416,7 +416,7 @@ objectDescription(const char *object) ...@@ -416,7 +416,7 @@ objectDescription(const char *object)
"WHERE RegprocToOid(o.oprcode) = d.objoid\n"); "WHERE RegprocToOid(o.oprcode) = d.objoid\n");
if (object) if (object)
{ {
strcat(descbuf, " AND o.oprname ~ '"); strcat(descbuf, " AND o.oprname ~ '^");
strncat(descbuf, object, REGEXP_CUTOFF); strncat(descbuf, object, REGEXP_CUTOFF);
strcat(descbuf, "'\n"); strcat(descbuf, "'\n");
} }
...@@ -428,7 +428,7 @@ objectDescription(const char *object) ...@@ -428,7 +428,7 @@ objectDescription(const char *object)
"WHERE t.oid = d.objoid\n"); "WHERE t.oid = d.objoid\n");
if (object) if (object)
{ {
strcat(descbuf, " AND t.typname ~* '"); strcat(descbuf, " AND t.typname ~* '^");
strncat(descbuf, object, REGEXP_CUTOFF); strncat(descbuf, object, REGEXP_CUTOFF);
strcat(descbuf, "'\n"); strcat(descbuf, "'\n");
} }
...@@ -440,7 +440,7 @@ objectDescription(const char *object) ...@@ -440,7 +440,7 @@ objectDescription(const char *object)
"WHERE c.oid = d.objoid\n"); "WHERE c.oid = d.objoid\n");
if (object) if (object)
{ {
strcat(descbuf, " AND c.relname ~* '"); strcat(descbuf, " AND c.relname ~* '^");
strncat(descbuf, object, REGEXP_CUTOFF); strncat(descbuf, object, REGEXP_CUTOFF);
strcat(descbuf, "'\n"); strcat(descbuf, "'\n");
} }
...@@ -452,7 +452,7 @@ objectDescription(const char *object) ...@@ -452,7 +452,7 @@ objectDescription(const char *object)
"WHERE r.oid = d.objoid AND r.rulename !~ '^_RET'\n"); "WHERE r.oid = d.objoid AND r.rulename !~ '^_RET'\n");
if (object) if (object)
{ {
strcat(descbuf, " AND r.rulename ~* '"); strcat(descbuf, " AND r.rulename ~* '^");
strncat(descbuf, object, REGEXP_CUTOFF); strncat(descbuf, object, REGEXP_CUTOFF);
strcat(descbuf, "'\n"); strcat(descbuf, "'\n");
} }
...@@ -464,7 +464,7 @@ objectDescription(const char *object) ...@@ -464,7 +464,7 @@ objectDescription(const char *object)
"WHERE t.oid = d.objoid\n"); "WHERE t.oid = d.objoid\n");
if (object) if (object)
{ {
strcat(descbuf, " AND t.tgname ~* '"); strcat(descbuf, " AND t.tgname ~* '^");
strncat(descbuf, object, REGEXP_CUTOFF); strncat(descbuf, object, REGEXP_CUTOFF);
strcat(descbuf, "'\n"); strcat(descbuf, "'\n");
} }
...@@ -504,7 +504,7 @@ xmalloc(size_t size) ...@@ -504,7 +504,7 @@ xmalloc(size_t size)
tmp = malloc(size); tmp = malloc(size);
if (!tmp) if (!tmp)
{ {
psql_error("out of memory"); psql_error("out of memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return tmp; return tmp;
...@@ -626,7 +626,7 @@ describeTableDetails(const char *name, bool desc) ...@@ -626,7 +626,7 @@ describeTableDetails(const char *name, bool desc)
bool isarray = false; bool isarray = false;
/* Name */ /* Name */
cells[i * cols + 0] = (char *)PQgetvalue(res, i, 0); /* don't free this afterwards */ cells[i * cols + 0] = PQgetvalue(res, i, 0); /* don't free this afterwards */
/* Type */ /* Type */
if (attype[0] == '_') if (attype[0] == '_')
...@@ -701,7 +701,7 @@ describeTableDetails(const char *name, bool desc) ...@@ -701,7 +701,7 @@ describeTableDetails(const char *name, bool desc)
/* Description */ /* Description */
if (desc) if (desc)
cells[i * cols + cols-1] = (char*)PQgetvalue(res, i, 7); cells[i * cols + cols-1] = PQgetvalue(res, i, 7);
} }
/* Make title */ /* Make title */
...@@ -960,7 +960,7 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -960,7 +960,7 @@ listTables(const char *infotype, const char *name, bool desc)
strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n"); strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
if (name) if (name)
{ {
strcat(buf, " AND c.relname ~ '"); strcat(buf, " AND c.relname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -976,7 +976,7 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -976,7 +976,7 @@ listTables(const char *infotype, const char *name, bool desc)
strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n"); strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
if (name) if (name)
{ {
strcat(buf, " AND c.relname ~ '"); strcat(buf, " AND c.relname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -997,7 +997,7 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -997,7 +997,7 @@ listTables(const char *infotype, const char *name, bool desc)
strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n"); strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
if (name) if (name)
{ {
strcat(buf, " AND c.relname ~ '"); strcat(buf, " AND c.relname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -1013,7 +1013,7 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -1013,7 +1013,7 @@ listTables(const char *infotype, const char *name, bool desc)
strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n"); strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
if (name) if (name)
{ {
strcat(buf, " AND c.relname ~ '"); strcat(buf, " AND c.relname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -1049,7 +1049,7 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -1049,7 +1049,7 @@ listTables(const char *infotype, const char *name, bool desc)
strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n"); strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
if (name) if (name)
{ {
strcat(buf, " AND c.relname ~ '"); strcat(buf, " AND c.relname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -1079,7 +1079,7 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -1079,7 +1079,7 @@ listTables(const char *infotype, const char *name, bool desc)
strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n"); strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
if (name) if (name)
{ {
strcat(buf, " AND c.relname ~ '"); strcat(buf, " AND c.relname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -1098,7 +1098,7 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -1098,7 +1098,7 @@ listTables(const char *infotype, const char *name, bool desc)
"WHERE c.relowner = u.usesysid AND c.relkind = 's'\n"); "WHERE c.relowner = u.usesysid AND c.relkind = 's'\n");
if (name) if (name)
{ {
strcat(buf, " AND c.relname ~ '"); strcat(buf, " AND c.relname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -1112,7 +1112,7 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -1112,7 +1112,7 @@ listTables(const char *infotype, const char *name, bool desc)
" AND not exists (select 1 from pg_user where usesysid = c.relowner)"); " AND not exists (select 1 from pg_user where usesysid = c.relowner)");
if (name) if (name)
{ {
strcat(buf, " AND c.relname ~ '"); strcat(buf, " AND c.relname ~ '^");
strncat(buf, name, REGEXP_CUTOFF); strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n"); strcat(buf, "'\n");
} }
...@@ -1127,10 +1127,10 @@ listTables(const char *infotype, const char *name, bool desc) ...@@ -1127,10 +1127,10 @@ listTables(const char *infotype, const char *name, bool desc)
if (PQntuples(res) == 0 && !QUIET()) if (PQntuples(res) == 0 && !QUIET())
{ {
if (name) if (name)
fprintf(pset.queryFout, "No matching relations found.\n"); fprintf(pset.queryFout, "No matching relations found.\n");
else else
fprintf(pset.queryFout, "No relations found.\n"); fprintf(pset.queryFout, "No relations found.\n");
} }
else else
{ {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.15 2000/01/29 16:58:48 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.16 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "help.h" #include "help.h"
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <errno.h>
#ifndef WIN32 #ifndef WIN32
#include <sys/ioctl.h> /* for ioctl() */ #include <sys/ioctl.h> /* for ioctl() */
...@@ -20,9 +21,7 @@ ...@@ -20,9 +21,7 @@
#include <sys/types.h> /* (ditto) */ #include <sys/types.h> /* (ditto) */
#include <unistd.h> /* for getuid() */ #include <unistd.h> /* for getuid() */
#else #else
#define strcasecmp(x,y) stricmp(x,y) #include <win32.h>
#define popen(x,y) _popen(x,y)
#define pclose(x) _pclose(x)
#endif #endif
#include <pqsignal.h> #include <pqsignal.h>
...@@ -48,7 +47,6 @@ usage(void) ...@@ -48,7 +47,6 @@ usage(void)
#ifndef WIN32 #ifndef WIN32
struct passwd *pw = NULL; struct passwd *pw = NULL;
#endif #endif
/* Find default user, in case we need it. */ /* Find default user, in case we need it. */
...@@ -61,7 +59,7 @@ usage(void) ...@@ -61,7 +59,7 @@ usage(void)
user = pw->pw_name; user = pw->pw_name;
else else
{ {
perror("getpwuid()"); psql_error("could not get current user name: %s", strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#else #else
...@@ -70,10 +68,11 @@ usage(void) ...@@ -70,10 +68,11 @@ usage(void)
} }
/* If this " is the start of the string then it ought to end there to fit in 80 columns >> " */ /* If this " is the start of the string then it ought to end there to fit in 80 columns >> " */
puts( "This is psql, the PostgreSQL interactive terminal."); puts( "This is psql, the PostgreSQL interactive terminal.\n");
puts( "\nUsage:"); puts( "Usage:");
puts( " psql [options] [dbname [username]]"); puts( " psql [options] [dbname [username]]\n");
puts( "\nOptions:"); puts( "Options:");
/* puts( " -a Echo all input from script");*/
puts( " -A Unaligned table output mode (-P format=unaligned)"); puts( " -A Unaligned table output mode (-P format=unaligned)");
puts( " -c <query> Run only single query (or slash command) and exit"); puts( " -c <query> Run only single query (or slash command) and exit");
...@@ -83,7 +82,7 @@ usage(void) ...@@ -83,7 +82,7 @@ usage(void)
env = user; env = user;
printf(" -d <dbname> Specify database name to connect to (default: %s)\n", env); printf(" -d <dbname> Specify database name to connect to (default: %s)\n", env);
puts( " -e Echo all input in non-interactive mode"); puts( " -e Echo queries sent to backend");
puts( " -E Display queries that internal commands generate"); puts( " -E Display queries that internal commands generate");
puts( " -f <filename> Execute queries from file, then exit"); puts( " -f <filename> Execute queries from file, then exit");
puts( " -F <string> Set field separator (default: \"" DEFAULT_FIELD_SEP "\") (-P fieldsep=)"); puts( " -F <string> Set field separator (default: \"" DEFAULT_FIELD_SEP "\") (-P fieldsep=)");
...@@ -99,7 +98,6 @@ usage(void) ...@@ -99,7 +98,6 @@ usage(void)
puts( " -H HTML table output mode (-P format=html)"); puts( " -H HTML table output mode (-P format=html)");
puts( " -l List available databases, then exit"); puts( " -l List available databases, then exit");
puts( " -n Do not use readline or history");
puts( " -o <filename> Send query output to filename (or |pipe)"); puts( " -o <filename> Send query output to filename (or |pipe)");
/* Display default port */ /* Display default port */
...@@ -109,6 +107,7 @@ usage(void) ...@@ -109,6 +107,7 @@ usage(void)
puts( " -P var[=arg] Set printing option 'var' to 'arg' (see \\pset command)"); puts( " -P var[=arg] Set printing option 'var' to 'arg' (see \\pset command)");
puts( " -q Run quietly (no messages, only query output)"); puts( " -q Run quietly (no messages, only query output)");
puts( " -R <string> Set record separator (default: newline) (-P recordsep=)");
puts( " -s Single step mode (confirm each query)"); puts( " -s Single step mode (confirm each query)");
puts( " -S Single line mode (newline terminates query)"); puts( " -S Single line mode (newline terminates query)");
puts( " -t Don't print headings and row count (-P tuples_only)"); puts( " -t Don't print headings and row count (-P tuples_only)");
...@@ -118,7 +117,7 @@ usage(void) ...@@ -118,7 +117,7 @@ usage(void)
env = getenv("PGUSER"); env = getenv("PGUSER");
if (!env) if (!env)
env = user; env = user;
printf(" -U <username> Specifiy username, \"?\"=prompt (default user: %s)\n", env); printf(" -U <username> Specify database username (default: %s)\n", env);
puts( " -x Turn on expanded table output (-P expanded)"); puts( " -x Turn on expanded table output (-P expanded)");
puts( " -v name=val Set psql variable 'name' to 'value'"); puts( " -v name=val Set psql variable 'name' to 'value'");
...@@ -190,10 +189,9 @@ slashUsage(void) ...@@ -190,10 +189,9 @@ slashUsage(void)
fout = stdout; fout = stdout;
/* if you add/remove a line here, change the row test above */ /* if you add/remove a line here, change the row test above */
fprintf(fout, " \\? help\n"); fprintf(fout, " \\c[onnect] [dbname|- [user]]\n"
fprintf(fout, " \\c[onnect] [dbname|- [user|?]]\n"
" connect to new database (currently '%s')\n", PQdb(pset.db)); " connect to new database (currently '%s')\n", PQdb(pset.db));
fprintf(fout, " \\copy ... perform SQL COPY with data stream to the client machine"); fprintf(fout, " \\copy ... perform SQL COPY with data stream to the client machine\n");
fprintf(fout, " \\copyright show PostgreSQL usage and distribution terms\n"); fprintf(fout, " \\copyright show PostgreSQL usage and distribution terms\n");
fprintf(fout, " \\d <table> describe table (or view, index, sequence)\n"); fprintf(fout, " \\d <table> describe table (or view, index, sequence)\n");
fprintf(fout, " \\d{i|s|t|v|S} list only indices/sequences/tables/views/system tables\n"); fprintf(fout, " \\d{i|s|t|v|S} list only indices/sequences/tables/views/system tables\n");
...@@ -209,10 +207,11 @@ slashUsage(void) ...@@ -209,10 +207,11 @@ slashUsage(void)
fprintf(fout, " \\i <fname> read and execute queries from filename\n"); fprintf(fout, " \\i <fname> read and execute queries from filename\n");
fprintf(fout, " \\l list all databases\n"); fprintf(fout, " \\l list all databases\n");
fprintf(fout, " \\lo_export, \\lo_import, \\lo_list, \\lo_unlink\n" fprintf(fout, " \\lo_export, \\lo_import, \\lo_list, \\lo_unlink\n"
" large object operations\n"); " large object operations\n");
fprintf(fout, " \\o [fname] send all query results to <fname>, or |pipe\n"); fprintf(fout, " \\o [fname] send all query results to <fname>, or |pipe\n");
fprintf(fout, " \\p show the content of the current query buffer\n"); fprintf(fout, " \\p show the content of the current query buffer\n");
fprintf(fout, " \\pset [opt] set table output options\n"); fprintf(fout, " \\pset {format|border|expanded|fieldsep|recordsep|tuples_only|title|tableattr\n"
" |pager} set table output options\n");
fprintf(fout, " \\q quit psql\n"); fprintf(fout, " \\q quit psql\n");
fprintf(fout, " \\qecho <text> write text to query output stream (see \\o)\n"); fprintf(fout, " \\qecho <text> write text to query output stream (see \\o)\n");
fprintf(fout, " \\r reset (clear) the query buffer\n"); fprintf(fout, " \\r reset (clear) the query buffer\n");
...@@ -243,36 +242,24 @@ slashUsage(void) ...@@ -243,36 +242,24 @@ slashUsage(void)
void void
helpSQL(const char *topic) helpSQL(const char *topic)
{ {
#define VALUE_OR_NULL(a) ((a) ? (a) : "")
if (!topic || strlen(topic) == 0) if (!topic || strlen(topic) == 0)
{ {
char left_center_right; /* Which column we're displaying */ int i;
int i; /* Index into QL_HELP[] */ int items_per_column = (QL_HELP_COUNT + 2)/3;
puts("Available help:"); puts("Available help:");
left_center_right = 'L';/* Start with left column */ for (i = 0; i < items_per_column; i++)
i = 0;
while (QL_HELP[i].cmd != NULL)
{ {
switch (left_center_right) printf(" %-25s%-25s%-25s\n",
{ VALUE_OR_NULL(QL_HELP[i].cmd),
case 'L': VALUE_OR_NULL(QL_HELP[i + items_per_column].cmd),
printf(" %-25s", QL_HELP[i].cmd); VALUE_OR_NULL(QL_HELP[i + 2*items_per_column].cmd)
left_center_right = 'C'; );
break;
case 'C':
printf("%-25s", QL_HELP[i].cmd);
left_center_right = 'R';
break;
case 'R':
printf("%-25s\n", QL_HELP[i].cmd);
left_center_right = 'L';
break;
}
i++;
} }
if (left_center_right != 'L') putc('\n', stdout);
puts("\n");
} }
else else
...@@ -286,8 +273,10 @@ helpSQL(const char *topic) ...@@ -286,8 +273,10 @@ helpSQL(const char *topic)
strcmp(topic, "*") == 0) strcmp(topic, "*") == 0)
{ {
help_found = true; help_found = true;
printf("Command: %s\nDescription: %s\nSyntax:\n%s\n\n", printf("Command: %s\n"
QL_HELP[i].cmd, QL_HELP[i].help, QL_HELP[i].syntax); "Description: %s\n"
"Syntax:\n%s\n\n",
QL_HELP[i].cmd, QL_HELP[i].help, QL_HELP[i].syntax);
} }
} }
...@@ -298,28 +287,28 @@ helpSQL(const char *topic) ...@@ -298,28 +287,28 @@ helpSQL(const char *topic)
void void
print_copyright(void) print_copyright(void)
{ {
puts( puts(
"PostgreSQL Data Base Management System\n\n" "PostgreSQL Data Base Management System\n\n"
"Portions Copyright (c) 1996-2000, PostgreSQL, Inc\n\n" "Portions Copyright (c) 1996-2000, PostgreSQL, Inc\n\n"
"This software is based on Postgres95, formerly known as Postgres, which\n" "This software is based on Postgres95, formerly known as Postgres, which\n"
"contains the following notice:\n\n" "contains the following notice:\n\n"
"Portions Copyright(c) 1994 - 7 Regents of the University of California\n\n" "Portions Copyright(c) 1994 - 7 Regents of the University of California\n\n"
"Permission to use, copy, modify, and distribute this software and its\n" "Permission to use, copy, modify, and distribute this software and its\n"
"documentation for any purpose, without fee, and without a written agreement\n" "documentation for any purpose, without fee, and without a written agreement\n"
"is hereby granted, provided that the above copyright notice and this paragraph\n" "is hereby granted, provided that the above copyright notice and this paragraph\n"
"and the following two paragraphs appear in all copies.\n\n" "and the following two paragraphs appear in all copies.\n\n"
"IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR\n" "IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR\n"
"DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST\n" "DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST\n"
"PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF\n" "PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF\n"
"THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\n" "THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\n"
"DAMAGE.\n\n" "DAMAGE.\n\n"
"THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,\n" "THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,\n"
"BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n" "BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n"
"PARTICULAR PURPOSE.THE SOFTWARE PROVIDED HEREUNDER IS ON AN \"AS IS\" BASIS,\n" "PARTICULAR PURPOSE.THE SOFTWARE PROVIDED HEREUNDER IS ON AN \"AS IS\" BASIS,\n"
"AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,\n" "AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,\n"
"SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."); "SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
);
} }
...@@ -3,15 +3,18 @@ ...@@ -3,15 +3,18 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.8 2000/01/29 16:58:48 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.9 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "input.h" #include "input.h"
#include <errno.h>
#include <pqexpbuffer.h> #include <pqexpbuffer.h>
#include "settings.h" #include "settings.h"
#include "tab-complete.h" #include "tab-complete.h"
#include "common.h"
/* Runtime options for turning off readline and history */ /* Runtime options for turning off readline and history */
/* (of course there is no runtime command for doing that :) */ /* (of course there is no runtime command for doing that :) */
...@@ -32,7 +35,7 @@ static bool useHistory; ...@@ -32,7 +35,7 @@ static bool useHistory;
* The result is malloced. * The result is malloced.
*/ */
char * char *
gets_interactive(const char *prompt) gets_interactive(char *prompt)
{ {
char *s; char *s;
#ifdef USE_HISTORY #ifdef USE_HISTORY
...@@ -42,7 +45,7 @@ gets_interactive(const char *prompt) ...@@ -42,7 +45,7 @@ gets_interactive(const char *prompt)
#ifdef USE_READLINE #ifdef USE_READLINE
if (useReadline) if (useReadline)
s = readline((char *) prompt); s = readline(prompt);
else else
{ {
#endif #endif
...@@ -120,7 +123,6 @@ initializeInput(int flags) ...@@ -120,7 +123,6 @@ initializeInput(int flags)
if (flags == 1) if (flags == 1)
{ {
useReadline = true; useReadline = true;
rl_readline_name = "psql";
initialize_readline(); initialize_readline();
} }
#endif #endif
...@@ -152,14 +154,14 @@ initializeInput(int flags) ...@@ -152,14 +154,14 @@ initializeInput(int flags)
bool bool
saveHistory(const char *fname) saveHistory(char *fname)
{ {
#ifdef USE_HISTORY #ifdef USE_HISTORY
if (useHistory) if (useHistory && fname)
{ {
if (write_history((char *) fname) != 0) if (write_history(fname) != 0)
{ {
perror(fname); psql_error("could not save history to %s: %s", fname, strerror(errno));
return false; return false;
} }
return true; return true;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.6 2000/01/29 16:58:48 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.7 2000/02/07 23:10:06 petere Exp $
*/ */
#ifndef INPUT_H #ifndef INPUT_H
#define INPUT_H #define INPUT_H
...@@ -37,11 +37,11 @@ ...@@ -37,11 +37,11 @@
# endif # endif
#endif #endif
char * gets_interactive(const char *prompt); char * gets_interactive(char *prompt);
char * gets_fromFile(FILE *source); char * gets_fromFile(FILE *source);
void initializeInput(int flags); void initializeInput(int flags);
bool saveHistory(const char *fname); bool saveHistory(char *fname);
void finishInput(void); void finishInput(void);
#endif /* INPUT_H */ #endif /* INPUT_H */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.7 2000/01/29 16:58:48 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.8 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "large_obj.h" #include "large_obj.h"
...@@ -113,7 +113,7 @@ do_lo_export(const char *loid_arg, const char *filename_arg) ...@@ -113,7 +113,7 @@ do_lo_export(const char *loid_arg, const char *filename_arg)
PQclear(res); PQclear(res);
} }
status = lo_export(pset.db, atol(loid_arg), (char *) filename_arg); status = lo_export(pset.db, atol(loid_arg), filename_arg);
if (status != 1) if (status != 1)
{ /* of course this status is documented { /* of course this status is documented
* nowhere :( */ * nowhere :( */
...@@ -182,7 +182,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg) ...@@ -182,7 +182,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
PQclear(res); PQclear(res);
} }
loid = lo_import(pset.db, (char *) filename_arg); loid = lo_import(pset.db, filename_arg);
if (loid == InvalidOid) if (loid == InvalidOid)
{ {
fputs(PQerrorMessage(pset.db), stderr); fputs(PQerrorMessage(pset.db), stderr);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.16 2000/01/24 19:34:17 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.17 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "mainloop.h" #include "mainloop.h"
...@@ -47,10 +47,10 @@ MainLoop(FILE *source) ...@@ -47,10 +47,10 @@ MainLoop(FILE *source)
bool xcomment; /* in extended comment */ bool xcomment; /* in extended comment */
int paren_level; int paren_level;
unsigned int query_start; unsigned int query_start;
int count_eof; int count_eof = 0;
const char *var; const char *var;
bool was_bslash; bool was_bslash;
unsigned int bslash_count; unsigned int bslash_count = 0;
int i, int i,
prevlen, prevlen,
...@@ -123,6 +123,8 @@ MainLoop(FILE *source) ...@@ -123,6 +123,8 @@ MainLoop(FILE *source)
prompt_status = PROMPT_DOUBLEQUOTE; prompt_status = PROMPT_DOUBLEQUOTE;
else if (xcomment) else if (xcomment)
prompt_status = PROMPT_COMMENT; prompt_status = PROMPT_COMMENT;
else if (paren_level)
prompt_status = PROMPT_PAREN;
else if (query_buf->len > 0) else if (query_buf->len > 0)
prompt_status = PROMPT_CONTINUE; prompt_status = PROMPT_CONTINUE;
else else
...@@ -251,7 +253,7 @@ MainLoop(FILE *source) ...@@ -251,7 +253,7 @@ MainLoop(FILE *source)
} }
/* start of quote */ /* start of quote */
else if (line[i] == '\'' || line[i] == '"') else if (!was_bslash && (line[i] == '\'' || line[i] == '"'))
in_quote = line[i]; in_quote = line[i];
/* in extended comment? */ /* in extended comment? */
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.9 2000/01/29 16:58:49 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.10 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "print.h" #include "print.h"
...@@ -266,7 +266,9 @@ print_aligned_text(const char *title, const char * const * headers, ...@@ -266,7 +266,9 @@ print_aligned_text(const char *title, const char * const * headers,
for (i = 0; i < col_count; i++) for (i = 0; i < col_count; i++)
{ {
/* centered */ /* centered */
fprintf(fout, "%-*s%s%-*s", (int) floor((widths[i] - strlen(headers[i])) / 2.0), "", headers[i], (int) ceil((widths[i] - strlen(headers[i])) / 2.0), ""); fprintf(fout, "%-*s%s%-*s",
(int) floor((widths[i] - strlen(headers[i])) / 2.0), "",
headers[i], (int) ceil((widths[i] - strlen(headers[i])) / 2.0), "");
if (i < col_count - 1) if (i < col_count - 1)
{ {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.7 2000/01/29 16:58:49 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.8 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "prompt.h" #include "prompt.h"
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
#include "variables.h" #include "variables.h"
#ifdef WIN32 #ifdef WIN32
#define popen(x,y) _popen(x,y) #include <io.h>
#define pclose(x) _pclose(x) #include <win32.h>
#endif #endif
...@@ -53,14 +53,14 @@ ...@@ -53,14 +53,14 @@
* *
* %`command` - The result of executing command in /bin/sh with trailing * %`command` - The result of executing command in /bin/sh with trailing
* newline stripped. * newline stripped.
* %$name$ - The value of the psql variable 'name' * %:name: - The value of the psql variable 'name'
* (those will not be rescanned for more escape sequences!) * (those will not be rescanned for more escape sequences!)
* *
* 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!). * will be empty (not NULL!).
*-------------------------- *--------------------------
*/ */
const char * char *
get_prompt(promptStatus_t status) get_prompt(promptStatus_t status)
{ {
#define MAX_PROMPT_SIZE 256 #define MAX_PROMPT_SIZE 256
...@@ -72,7 +72,7 @@ get_prompt(promptStatus_t status) ...@@ -72,7 +72,7 @@ get_prompt(promptStatus_t status)
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 || status == PROMPT_PAREN)
prompt_string = GetVariable(pset.vars, "PROMPT2"); prompt_string = GetVariable(pset.vars, "PROMPT2");
else if (status == PROMPT_COPY) else if (status == PROMPT_COPY)
prompt_string = GetVariable(pset.vars, "PROMPT3"); prompt_string = GetVariable(pset.vars, "PROMPT3");
...@@ -183,6 +183,9 @@ get_prompt(promptStatus_t status) ...@@ -183,6 +183,9 @@ get_prompt(promptStatus_t status)
case PROMPT_COMMENT: case PROMPT_COMMENT:
buf[0] = '*'; buf[0] = '*';
break; break;
case PROMPT_PAREN:
buf[0] = '(';
break;
default: default:
buf[0] = '\0'; buf[0] = '\0';
break; break;
...@@ -226,14 +229,14 @@ get_prompt(promptStatus_t status) ...@@ -226,14 +229,14 @@ get_prompt(promptStatus_t status)
} }
/* interpolate variable */ /* interpolate variable */
case '$': case ':':
{ {
char *name; char *name;
const char *val; const char *val;
int nameend; int nameend;
name = strdup(p + 1); name = strdup(p + 1);
nameend = strcspn(name, "$"); nameend = strcspn(name, ":");
name[nameend] = '\0'; name[nameend] = '\0';
val = GetVariable(pset.vars, name); val = GetVariable(pset.vars, name);
if (val) if (val)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/prompt.h,v 1.5 2000/01/29 16:58:49 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/prompt.h,v 1.6 2000/02/07 23:10:06 petere Exp $
*/ */
#ifndef PROMPT_H #ifndef PROMPT_H
#define PROMPT_H #define PROMPT_H
...@@ -17,9 +17,10 @@ typedef enum _promptStatus ...@@ -17,9 +17,10 @@ typedef enum _promptStatus
PROMPT_COMMENT, PROMPT_COMMENT,
PROMPT_SINGLEQUOTE, PROMPT_SINGLEQUOTE,
PROMPT_DOUBLEQUOTE, PROMPT_DOUBLEQUOTE,
PROMPT_PAREN,
PROMPT_COPY PROMPT_COPY
} promptStatus_t; } promptStatus_t;
const char *get_prompt(promptStatus_t status); char *get_prompt(promptStatus_t status);
#endif /* PROMPT_H */ #endif /* PROMPT_H */
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.23 2000/01/29 16:58:49 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.24 2000/02/07 23:10:06 petere Exp $
*/ */
#include <c.h> #include <c.h>
#include "stringutils.h" #include "stringutils.h"
...@@ -12,19 +12,13 @@ ...@@ -12,19 +12,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <postgres.h>
#ifndef HAVE_STRDUP
#include <strdup.h>
#endif
#include <libpq-fe.h> #include <libpq-fe.h>
static void static void unescape_quotes(char *source, int quote, int escape);
unescape_quotes(char *source, char quote, char escape);
/* /*
...@@ -45,7 +39,7 @@ char * ...@@ -45,7 +39,7 @@ char *
strtokx(const char *s, strtokx(const char *s,
const char *delim, const char *delim,
const char *quote, const char *quote,
char escape, int escape,
char *was_quoted, char *was_quoted,
unsigned int *token_pos, unsigned int *token_pos,
int encoding) int encoding)
...@@ -60,6 +54,10 @@ strtokx(const char *s, ...@@ -60,6 +54,10 @@ strtokx(const char *s,
char *start; char *start;
char *cp = NULL; char *cp = NULL;
#ifndef MULTIBYTE
(void)encoding; /*not used*/
#endif
if (s) if (s)
{ {
free(storage); free(storage);
...@@ -160,7 +158,7 @@ strtokx(const char *s, ...@@ -160,7 +158,7 @@ strtokx(const char *s,
* Resolves escaped quotes. Used by strtokx above. * Resolves escaped quotes. Used by strtokx above.
*/ */
static void static void
unescape_quotes(char *source, char quote, char escape) unescape_quotes(char *source, int quote, int escape)
{ {
char *p; char *p;
char *destination, char *destination,
...@@ -170,7 +168,7 @@ unescape_quotes(char *source, char quote, char escape) ...@@ -170,7 +168,7 @@ unescape_quotes(char *source, char quote, char escape)
assert(source); assert(source);
#endif #endif
destination = (char *) calloc(1, strlen(source) + 1); destination = calloc(1, strlen(source) + 1);
if (!destination) if (!destination)
{ {
perror("calloc"); perror("calloc");
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/stringutils.h,v 1.13 2000/01/29 16:58:49 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.h,v 1.14 2000/02/07 23:10:07 petere Exp $
*/ */
#ifndef STRINGUTILS_H #ifndef STRINGUTILS_H
#define STRINGUTILS_H #define STRINGUTILS_H
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
extern char *strtokx(const char *s, extern char *strtokx(const char *s,
const char *delim, const char *delim,
const char *quote, const char *quote,
char escape, int escape,
char *was_quoted, char *was_quoted,
unsigned int *token_pos, unsigned int *token_pos,
int encoding); int encoding);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.9 2000/01/29 16:58:49 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.10 2000/02/07 23:10:07 petere Exp $
*/ */
/*----------- /*-----------
...@@ -121,9 +121,7 @@ pgsql_thing_t words_after_create[] = { ...@@ -121,9 +121,7 @@ pgsql_thing_t words_after_create[] = {
{ "TYPE", "SELECT typname FROM pg_type WHERE substr(typname,1,%d)='%s'" }, { "TYPE", "SELECT typname FROM pg_type WHERE substr(typname,1,%d)='%s'" },
{ "UNIQUE", NULL }, /* for CREATE UNIQUE INDEX ... */ { "UNIQUE", NULL }, /* for CREATE UNIQUE INDEX ... */
{ "USER", "SELECT usename FROM pg_user WHERE substr(usename,1,%d)='%s'" }, { "USER", "SELECT usename FROM pg_user WHERE substr(usename,1,%d)='%s'" },
{ "VIEW", NULL }, /* Telling a view from a table is not the easiest { "VIEW", "SELECT viewname FROM pg_views WHERE substr(viewname,1,%d)='%s'" },
thing in the world, and the solutions I've seen
don't really work, so I'll wait on this. */
{ NULL, NULL } /* end of list */ { NULL, NULL } /* end of list */
}; };
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes). * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.36 2000/01/26 05:58:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.37 2000/02/07 23:10:08 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -474,6 +474,10 @@ int ...@@ -474,6 +474,10 @@ int
fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
const char *password, char *PQerrormsg) const char *password, char *PQerrormsg)
{ {
#if !defined(KRB4) && !defined(KRB5)
(void)hostname; /*not used*/
#endif
switch (areq) switch (areq)
{ {
case AUTH_REQ_OK: case AUTH_REQ_OK:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.117 2000/02/05 12:33:22 ishii Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.118 2000/02/07 23:10:09 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2291,7 +2291,7 @@ conninfo_free() ...@@ -2291,7 +2291,7 @@ conninfo_free()
} }
/* =========== accessor functions for PGconn ========= */ /* =========== accessor functions for PGconn ========= */
const char * char *
PQdb(const PGconn *conn) PQdb(const PGconn *conn)
{ {
if (!conn) if (!conn)
...@@ -2299,7 +2299,7 @@ PQdb(const PGconn *conn) ...@@ -2299,7 +2299,7 @@ PQdb(const PGconn *conn)
return conn->dbName; return conn->dbName;
} }
const char * char *
PQuser(const PGconn *conn) PQuser(const PGconn *conn)
{ {
if (!conn) if (!conn)
...@@ -2307,7 +2307,7 @@ PQuser(const PGconn *conn) ...@@ -2307,7 +2307,7 @@ PQuser(const PGconn *conn)
return conn->pguser; return conn->pguser;
} }
const char * char *
PQpass(const PGconn *conn) PQpass(const PGconn *conn)
{ {
if (!conn) if (!conn)
...@@ -2315,7 +2315,7 @@ PQpass(const PGconn *conn) ...@@ -2315,7 +2315,7 @@ PQpass(const PGconn *conn)
return conn->pgpass; return conn->pgpass;
} }
const char * char *
PQhost(const PGconn *conn) PQhost(const PGconn *conn)
{ {
if (!conn) if (!conn)
...@@ -2323,7 +2323,7 @@ PQhost(const PGconn *conn) ...@@ -2323,7 +2323,7 @@ PQhost(const PGconn *conn)
return conn->pghost; return conn->pghost;
} }
const char * char *
PQport(const PGconn *conn) PQport(const PGconn *conn)
{ {
if (!conn) if (!conn)
...@@ -2331,7 +2331,7 @@ PQport(const PGconn *conn) ...@@ -2331,7 +2331,7 @@ PQport(const PGconn *conn)
return conn->pgport; return conn->pgport;
} }
const char * char *
PQtty(const PGconn *conn) PQtty(const PGconn *conn)
{ {
if (!conn) if (!conn)
...@@ -2339,7 +2339,7 @@ PQtty(const PGconn *conn) ...@@ -2339,7 +2339,7 @@ PQtty(const PGconn *conn)
return conn->pgtty; return conn->pgtty;
} }
const char * char *
PQoptions(const PGconn *conn) PQoptions(const PGconn *conn)
{ {
if (!conn) if (!conn)
...@@ -2355,7 +2355,7 @@ PQstatus(const PGconn *conn) ...@@ -2355,7 +2355,7 @@ PQstatus(const PGconn *conn)
return conn->status; return conn->status;
} }
const char * char *
PQerrorMessage(const PGconn *conn) PQerrorMessage(const PGconn *conn)
{ {
static char noConn[] = "PQerrorMessage: conn pointer is NULL\n"; static char noConn[] = "PQerrorMessage: conn pointer is NULL\n";
...@@ -2478,6 +2478,7 @@ PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg) ...@@ -2478,6 +2478,7 @@ PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
static void static void
defaultNoticeProcessor(void *arg, const char *message) defaultNoticeProcessor(void *arg, const char *message)
{ {
(void)arg; /*not used*/
/* Note: we expect the supplied string to end with a newline already. */ /* Note: we expect the supplied string to end with a newline already. */
fprintf(stderr, "%s", message); fprintf(stderr, "%s", message);
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.89 2000/01/26 05:58:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.90 2000/02/07 23:10:10 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#endif #endif
/* keep this in same order as ExecStatusType in libpq-fe.h */ /* keep this in same order as ExecStatusType in libpq-fe.h */
const char *const pgresStatus[] = { char * const pgresStatus[] = {
"PGRES_EMPTY_QUERY", "PGRES_EMPTY_QUERY",
"PGRES_COMMAND_OK", "PGRES_COMMAND_OK",
"PGRES_TUPLES_OK", "PGRES_TUPLES_OK",
...@@ -1760,15 +1760,15 @@ PQresultStatus(const PGresult *res) ...@@ -1760,15 +1760,15 @@ PQresultStatus(const PGresult *res)
return res->resultStatus; return res->resultStatus;
} }
const char * char *
PQresStatus(ExecStatusType status) PQresStatus(ExecStatusType status)
{ {
if ((int)status < 0 || (size_t)status >= sizeof pgresStatus / sizeof pgresStatus[0]) if (status < 0 || status >= sizeof pgresStatus / sizeof pgresStatus[0])
return "Invalid ExecStatusType code"; return "Invalid ExecStatusType code";
return pgresStatus[status]; return pgresStatus[status];
} }
const char * char *
PQresultErrorMessage(const PGresult *res) PQresultErrorMessage(const PGresult *res)
{ {
if (!res || !res->errMsg) if (!res || !res->errMsg)
...@@ -1862,7 +1862,7 @@ check_tuple_field_number(const char *routineName, const PGresult *res, ...@@ -1862,7 +1862,7 @@ check_tuple_field_number(const char *routineName, const PGresult *res,
/* /*
returns NULL if the field_num is invalid returns NULL if the field_num is invalid
*/ */
const char * char *
PQfname(const PGresult *res, int field_num) PQfname(const PGresult *res, int field_num)
{ {
if (!check_field_number("PQfname", res, field_num)) if (!check_field_number("PQfname", res, field_num))
...@@ -1947,8 +1947,8 @@ PQfmod(const PGresult *res, int field_num) ...@@ -1947,8 +1947,8 @@ PQfmod(const PGresult *res, int field_num)
return 0; return 0;
} }
const char * char *
PQcmdStatus(const PGresult *res) PQcmdStatus(PGresult *res)
{ {
if (!res) if (!res)
return NULL; return NULL;
...@@ -1960,7 +1960,7 @@ PQcmdStatus(const PGresult *res) ...@@ -1960,7 +1960,7 @@ PQcmdStatus(const PGresult *res)
if the last command was an INSERT, return the oid string if the last command was an INSERT, return the oid string
if not, return "" if not, return ""
*/ */
const char * char *
PQoidStatus(const PGresult *res) PQoidStatus(const PGresult *res)
{ {
/* /*
...@@ -2011,8 +2011,8 @@ PQoidValue(const PGresult *res) ...@@ -2011,8 +2011,8 @@ PQoidValue(const PGresult *res)
if the last command was an INSERT/UPDATE/DELETE, return number if the last command was an INSERT/UPDATE/DELETE, return number
of inserted/affected tuples, if not, return "" of inserted/affected tuples, if not, return ""
*/ */
const char * char *
PQcmdTuples(const PGresult *res) PQcmdTuples(PGresult *res)
{ {
char noticeBuf[128]; char noticeBuf[128];
...@@ -2023,7 +2023,7 @@ PQcmdTuples(const PGresult *res) ...@@ -2023,7 +2023,7 @@ PQcmdTuples(const PGresult *res)
strncmp(res->cmdStatus, "DELETE", 6) == 0 || strncmp(res->cmdStatus, "DELETE", 6) == 0 ||
strncmp(res->cmdStatus, "UPDATE", 6) == 0) strncmp(res->cmdStatus, "UPDATE", 6) == 0)
{ {
const char *p = res->cmdStatus + 6; char *p = res->cmdStatus + 6;
if (*p == 0) if (*p == 0)
{ {
...@@ -2067,7 +2067,7 @@ PQcmdTuples(const PGresult *res) ...@@ -2067,7 +2067,7 @@ PQcmdTuples(const PGresult *res)
if res is not binary, a null-terminated ASCII string is returned. if res is not binary, a null-terminated ASCII string is returned.
*/ */
const char * char *
PQgetvalue(const PGresult *res, int tup_num, int field_num) PQgetvalue(const PGresult *res, int tup_num, int field_num)
{ {
if (!check_tuple_field_number("PQgetvalue", res, tup_num, field_num)) if (!check_tuple_field_number("PQgetvalue", res, tup_num, field_num))
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.27 2000/01/26 05:58:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.28 2000/02/07 23:10:11 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -168,7 +168,7 @@ lo_read(PGconn *conn, int fd, char *buf, size_t len) ...@@ -168,7 +168,7 @@ lo_read(PGconn *conn, int fd, char *buf, size_t len)
* *
*/ */
int int
lo_write(PGconn *conn, int fd, const char *buf, size_t len) lo_write(PGconn *conn, int fd, char *buf, size_t len)
{ {
PQArgBlock argv[2]; PQArgBlock argv[2];
PGresult *res; PGresult *res;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.38 2000/01/29 16:58:51 petere Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.39 2000/02/07 23:10:11 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -782,6 +782,8 @@ PQenv2encoding(void) ...@@ -782,6 +782,8 @@ PQenv2encoding(void)
int int
PQmblen(const unsigned char *s, int encoding) PQmblen(const unsigned char *s, int encoding)
{ {
(void)s;
(void)encoding;
return 1; return 1;
} }
int int
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* didn't really belong there. * didn't really belong there.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.34 2000/02/05 12:33:22 ishii Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.35 2000/02/07 23:10:11 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -59,7 +59,7 @@ static char *do_header(FILE *fout, const PQprintOpt *po, const int nFields, ...@@ -59,7 +59,7 @@ static char *do_header(FILE *fout, const PQprintOpt *po, const int nFields,
static void output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields, static void output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
unsigned char *fieldNotNum, int *fieldMax, char *border, unsigned char *fieldNotNum, int *fieldMax, char *border,
const int row_index); const int row_index);
static void fill(int length, int max, char filler, FILE *fp);
/* /*
* PQprint() * PQprint()
...@@ -440,7 +440,6 @@ do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax, ...@@ -440,7 +440,6 @@ do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax,
fputs("<tr>", fout); fputs("<tr>", fout);
else else
{ {
int j; /* for loop index */
int tot = 0; int tot = 0;
int n = 0; int n = 0;
char *p = NULL; char *p = NULL;
...@@ -557,7 +556,6 @@ output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields, ...@@ -557,7 +556,6 @@ output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
#if 0
/* /*
* really old printing routines * really old printing routines
*/ */
...@@ -728,4 +726,17 @@ PQprintTuples(const PGresult *res, ...@@ -728,4 +726,17 @@ PQprintTuples(const PGresult *res,
} }
} }
} }
#endif
/* simply send out max-length number of filler characters to fp */
static void
fill(int length, int max, char filler, FILE *fp)
{
int count;
count = max - length;
while (count-- >= 0)
putc(filler, fp);
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: libpq-fe.h,v 1.59 2000/02/05 12:33:22 ishii Exp $ * $Id: libpq-fe.h,v 1.60 2000/02/07 23:10:11 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -74,11 +74,6 @@ extern "C" ...@@ -74,11 +74,6 @@ extern "C"
PGRES_FATAL_ERROR PGRES_FATAL_ERROR
} ExecStatusType; } ExecStatusType;
/* String descriptions of the ExecStatusTypes.
* NB: direct use of this array is now deprecated; call PQresStatus() instead.
*/
extern const char *const pgresStatus[];
/* PGconn encapsulates a connection to the backend. /* PGconn encapsulates a connection to the backend.
* The contents of this struct are not supposed to be known to applications. * The contents of this struct are not supposed to be known to applications.
*/ */
...@@ -115,16 +110,17 @@ extern "C" ...@@ -115,16 +110,17 @@ extern "C"
typedef void (*PQnoticeProcessor) (void *arg, const char *message); typedef void (*PQnoticeProcessor) (void *arg, const char *message);
/* Print options for PQprint() */ /* Print options for PQprint() */
typedef char pqbool;
typedef struct _PQprintOpt typedef struct _PQprintOpt
{ {
int header; /* print output field headings and row pqbool header; /* print output field headings and row
* count */ * count */
int align; /* fill align the fields */ pqbool align; /* fill align the fields */
int standard; /* old brain dead format */ pqbool standard; /* old brain dead format */
int html3; /* output html tables */ pqbool html3; /* output html tables */
int expanded; /* expand tables */ pqbool expanded; /* expand tables */
int pager; /* use pager for output if needed */ pqbool pager; /* use pager for output if needed */
char *fieldSep; /* field separator */ char *fieldSep; /* field separator */
char *tableOpt; /* insert to HTML <table ...> */ char *tableOpt; /* insert to HTML <table ...> */
char *caption; /* HTML <caption> */ char *caption; /* HTML <caption> */
...@@ -207,15 +203,15 @@ extern "C" ...@@ -207,15 +203,15 @@ extern "C"
extern int PQrequestCancel(PGconn *conn); extern int PQrequestCancel(PGconn *conn);
/* Accessor functions for PGconn objects */ /* Accessor functions for PGconn objects */
extern const char *PQdb(const PGconn *conn); extern char *PQdb(const PGconn *conn);
extern const char *PQuser(const PGconn *conn); extern char *PQuser(const PGconn *conn);
extern const char *PQpass(const PGconn *conn); extern char *PQpass(const PGconn *conn);
extern const char *PQhost(const PGconn *conn); extern char *PQhost(const PGconn *conn);
extern const char *PQport(const PGconn *conn); extern char *PQport(const PGconn *conn);
extern const char *PQtty(const PGconn *conn); extern char *PQtty(const PGconn *conn);
extern const char *PQoptions(const PGconn *conn); extern char *PQoptions(const PGconn *conn);
extern ConnStatusType PQstatus(const PGconn *conn); extern ConnStatusType PQstatus(const PGconn *conn);
extern const char *PQerrorMessage(const PGconn *conn); extern char *PQerrorMessage(const PGconn *conn);
extern int PQsocket(const PGconn *conn); extern int PQsocket(const PGconn *conn);
extern int PQbackendPID(const PGconn *conn); extern int PQbackendPID(const PGconn *conn);
extern int PQclientEncoding(const PGconn *conn); extern int PQclientEncoding(const PGconn *conn);
...@@ -279,21 +275,21 @@ extern "C" ...@@ -279,21 +275,21 @@ extern "C"
/* Accessor functions for PGresult objects */ /* Accessor functions for PGresult objects */
extern ExecStatusType PQresultStatus(const PGresult *res); extern ExecStatusType PQresultStatus(const PGresult *res);
extern const char *PQresStatus(ExecStatusType status); extern char *PQresStatus(ExecStatusType status);
extern const char *PQresultErrorMessage(const PGresult *res); extern char *PQresultErrorMessage(const PGresult *res);
extern int PQntuples(const PGresult *res); extern int PQntuples(const PGresult *res);
extern int PQnfields(const PGresult *res); extern int PQnfields(const PGresult *res);
extern int PQbinaryTuples(const PGresult *res); extern int PQbinaryTuples(const PGresult *res);
extern const char *PQfname(const PGresult *res, int field_num); extern char *PQfname(const PGresult *res, int field_num);
extern int PQfnumber(const PGresult *res, const char *field_name); extern int PQfnumber(const PGresult *res, const char *field_name);
extern Oid PQftype(const PGresult *res, int field_num); extern Oid PQftype(const PGresult *res, int field_num);
extern int PQfsize(const PGresult *res, int field_num); extern int PQfsize(const PGresult *res, int field_num);
extern int PQfmod(const PGresult *res, int field_num); extern int PQfmod(const PGresult *res, int field_num);
extern const char *PQcmdStatus(const PGresult *res); extern char *PQcmdStatus(PGresult *res);
extern const char *PQoidStatus(const PGresult *res); /* old and ugly */ extern char *PQoidStatus(const PGresult *res); /* old and ugly */
extern Oid PQoidValue(const PGresult *res); /* new and improved */ extern Oid PQoidValue(const PGresult *res); /* new and improved */
extern const char *PQcmdTuples(const PGresult *res); extern char *PQcmdTuples(PGresult *res);
extern const char *PQgetvalue(const PGresult *res, int tup_num, int field_num); extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
extern int PQgetlength(const PGresult *res, int tup_num, int field_num); extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
extern int PQgetisnull(const PGresult *res, int tup_num, int field_num); extern int PQgetisnull(const PGresult *res, int tup_num, int field_num);
...@@ -313,7 +309,6 @@ extern "C" ...@@ -313,7 +309,6 @@ extern "C"
const PGresult *res, const PGresult *res,
const PQprintOpt *ps); /* option structure */ const PQprintOpt *ps); /* option structure */
#if 0
/* /*
* really old printing routines * really old printing routines
*/ */
...@@ -330,7 +325,7 @@ extern "C" ...@@ -330,7 +325,7 @@ extern "C"
int terseOutput, /* delimiter bars */ int terseOutput, /* delimiter bars */
int width); /* width of column, if int width); /* width of column, if
* 0, use variable width */ * 0, use variable width */
#endif
/* === in fe-lobj.c === */ /* === in fe-lobj.c === */
...@@ -338,7 +333,7 @@ extern "C" ...@@ -338,7 +333,7 @@ extern "C"
extern int lo_open(PGconn *conn, Oid lobjId, int mode); extern int lo_open(PGconn *conn, Oid lobjId, int mode);
extern int lo_close(PGconn *conn, int fd); extern int lo_close(PGconn *conn, int fd);
extern int lo_read(PGconn *conn, int fd, char *buf, size_t len); extern int lo_read(PGconn *conn, int fd, char *buf, size_t len);
extern int lo_write(PGconn *conn, int fd, const char *buf, size_t len); extern int lo_write(PGconn *conn, int fd, char *buf, size_t len);
extern int lo_lseek(PGconn *conn, int fd, int offset, int whence); extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
extern Oid lo_creat(PGconn *conn, int mode); extern Oid lo_creat(PGconn *conn, int mode);
extern int lo_tell(PGconn *conn, int fd); extern int lo_tell(PGconn *conn, int fd);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: libpq-int.h,v 1.18 2000/01/26 05:58:46 momjian Exp $ * $Id: libpq-int.h,v 1.19 2000/02/07 23:10:11 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -244,6 +244,11 @@ struct pg_conn ...@@ -244,6 +244,11 @@ struct pg_conn
int client_encoding; /* encoding id */ int client_encoding; /* encoding id */
}; };
/* String descriptions of the ExecStatusTypes.
* direct use of this array is deprecated; call PQresStatus() instead.
*/
extern char *const pgresStatus[];
/* ---------------- /* ----------------
* Internal functions of libpq * Internal functions of libpq
* Functions declared here need to be visible across files of libpq, * Functions declared here need to be visible across files of libpq,
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.4 2000/01/26 05:58:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.5 2000/02/07 23:10:11 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -124,9 +124,9 @@ resetPQExpBuffer(PQExpBuffer str) ...@@ -124,9 +124,9 @@ resetPQExpBuffer(PQExpBuffer str)
* Returns 1 if OK, 0 if failed to enlarge buffer. * Returns 1 if OK, 0 if failed to enlarge buffer.
*/ */
int int
enlargePQExpBuffer(PQExpBuffer str, int needed) enlargePQExpBuffer(PQExpBuffer str, size_t needed)
{ {
int newlen; size_t newlen;
char *newdata; char *newdata;
needed += str->len + 1; /* total space required now */ needed += str->len + 1; /* total space required now */
...@@ -164,8 +164,8 @@ void ...@@ -164,8 +164,8 @@ void
printfPQExpBuffer(PQExpBuffer str, const char *fmt,...) printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
{ {
va_list args; va_list args;
int avail, size_t avail;
nprinted; int nprinted;
resetPQExpBuffer(str); resetPQExpBuffer(str);
...@@ -214,8 +214,8 @@ void ...@@ -214,8 +214,8 @@ void
appendPQExpBuffer(PQExpBuffer str, const char *fmt,...) appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
{ {
va_list args; va_list args;
int avail, size_t avail;
nprinted; int nprinted;
for (;;) for (;;)
{ {
...@@ -286,7 +286,7 @@ appendPQExpBufferChar(PQExpBuffer str, char ch) ...@@ -286,7 +286,7 @@ appendPQExpBufferChar(PQExpBuffer str, char ch)
* if necessary. * if necessary.
*/ */
void void
appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, int datalen) appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
{ {
/* Make more room if needed */ /* Make more room if needed */
if (! enlargePQExpBuffer(str, datalen)) if (! enlargePQExpBuffer(str, datalen))
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pqexpbuffer.h,v 1.3 2000/01/26 05:58:46 momjian Exp $ * $Id: pqexpbuffer.h,v 1.4 2000/02/07 23:10:11 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
typedef struct PQExpBufferData typedef struct PQExpBufferData
{ {
char *data; char *data;
int len; size_t len;
int maxlen; size_t maxlen;
} PQExpBufferData; } PQExpBufferData;
typedef PQExpBufferData *PQExpBuffer; typedef PQExpBufferData *PQExpBuffer;
...@@ -113,7 +113,7 @@ extern void resetPQExpBuffer(PQExpBuffer str); ...@@ -113,7 +113,7 @@ extern void resetPQExpBuffer(PQExpBuffer str);
* *
* Returns 1 if OK, 0 if failed to enlarge buffer. * Returns 1 if OK, 0 if failed to enlarge buffer.
*/ */
extern int enlargePQExpBuffer(PQExpBuffer str, int needed); extern int enlargePQExpBuffer(PQExpBuffer str, size_t needed);
/*------------------------ /*------------------------
* printfPQExpBuffer * printfPQExpBuffer
...@@ -153,6 +153,6 @@ extern void appendPQExpBufferChar(PQExpBuffer str, char ch); ...@@ -153,6 +153,6 @@ extern void appendPQExpBufferChar(PQExpBuffer str, char ch);
* if necessary. * if necessary.
*/ */
extern void appendBinaryPQExpBuffer(PQExpBuffer str, extern void appendBinaryPQExpBuffer(PQExpBuffer str,
const char *data, int datalen); const char *data, size_t datalen);
#endif /* PQEXPBUFFER_H */ #endif /* PQEXPBUFFER_H */
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
* Some compat functions * Some compat functions
*/ */
#define open(a,b,c) _open(a,b,c) #define open(a,b,c) _open(a,b,c)
#define close(a) _close(a)
#define read(a,b,c) _read(a,b,c) #define read(a,b,c) _read(a,b,c)
#define write(a,b,c) _write(a,b,c) #define write(a,b,c) _write(a,b,c)
#define popen(a,b) _popen(a,b)
#define pclose(a) _pclose(a)
/* /*
* crypt not available (yet) * crypt not available (yet)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment