Commit 3d726290 authored by Peter Eisentraut's avatar Peter Eisentraut

Remove traces of NAMEDATALEN and INDEX_MAX_KEYS from psql. Build buffers

dynamically with PQExpBuffer.
parent 246f47fd
......@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.71 2002/03/27 19:16:13 petere Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.72 2002/04/24 05:24:00 petere Exp $
*/
#include "postgres_fe.h"
#include "command.h"
......@@ -1433,14 +1433,16 @@ bool
test_superuser(const char *username)
{
PGresult *res;
char buf[64 + NAMEDATALEN];
PQExpBufferData buf;
bool answer;
if (!username)
return false;
sprintf(buf, "SELECT usesuper FROM pg_user WHERE usename = '%.*s'", NAMEDATALEN, username);
res = PSQLexec(buf);
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, "SELECT usesuper FROM pg_user WHERE usename = '%s'", username);
res = PSQLexec(buf.data);
termPQExpBuffer(&buf);
answer =
(PQntuples(res) > 0 && PQnfields(res) > 0
......
......@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.20 2002/02/23 21:46:03 momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.21 2002/04/24 05:24:00 petere Exp $
*/
#include "postgres_fe.h"
#include "copy.h"
......@@ -19,6 +19,7 @@
#endif
#include "libpq-fe.h"
#include "pqexpbuffer.h"
#include "pqsignal.h"
#include "settings.h"
......@@ -229,12 +230,12 @@ parse_slash_copy(const char *args)
bool
do_copy(const char *args)
{
char query[128 + NAMEDATALEN];
PQExpBufferData query;
FILE *copystream;
struct copy_options *options;
PGresult *result;
bool success;
struct stat st;
struct stat st;
/* parse options */
options = parse_slash_copy(args);
......@@ -242,35 +243,27 @@ do_copy(const char *args)
if (!options)
return false;
strcpy(query, "COPY ");
initPQExpBuffer(&query);
printfPQExpBuffer(&query, "COPY ");
if (options->binary)
strcat(query, "BINARY ");
appendPQExpBuffer(&query, "BINARY ");
strcat(query, "\"");
strncat(query, options->table, NAMEDATALEN);
strcat(query, "\" ");
appendPQExpBuffer(&query, "\"%s\" ", options->table);
if (options->oids)
strcat(query, "WITH OIDS ");
appendPQExpBuffer(&query, "WITH OIDS ");
if (options->from)
strcat(query, "FROM STDIN");
appendPQExpBuffer(&query, "FROM STDIN");
else
strcat(query, "TO STDOUT");
appendPQExpBuffer(&query, "TO STDOUT");
if (options->delim)
{
strcat(query, " USING DELIMITERS '");
strcat(query, options->delim);
strcat(query, "'");
}
appendPQExpBuffer(&query, " USING DELIMITERS '%s'", options->delim);
if (options->null)
{
strcat(query, " WITH NULL AS '");
strcat(query, options->null);
strcat(query, "'");
}
appendPQExpBuffer(&query, " WITH NULL AS '%s'", options->null);
if (options->from)
{
......@@ -294,17 +287,20 @@ do_copy(const char *args)
free_copy_options(options);
return false;
}
/* make sure the specified file is not a directory */
fstat(fileno(copystream),&st);
if( S_ISDIR(st.st_mode) ){
fclose(copystream);
/* make sure the specified file is not a directory */
fstat(fileno(copystream), &st);
if( S_ISDIR(st.st_mode) )
{
fclose(copystream);
psql_error("%s: cannot COPY TO/FROM a directory\n",
options->file);
free_copy_options(options);
return false;
}
}
result = PSQLexec(query);
result = PSQLexec(query.data);
termPQExpBuffer(&query);
switch (PQresultStatus(result))
{
......
This diff is collapsed.
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