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 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * 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 "postgres_fe.h"
#include "command.h" #include "command.h"
...@@ -1433,14 +1433,16 @@ bool ...@@ -1433,14 +1433,16 @@ bool
test_superuser(const char *username) test_superuser(const char *username)
{ {
PGresult *res; PGresult *res;
char buf[64 + NAMEDATALEN]; PQExpBufferData buf;
bool answer; bool answer;
if (!username) if (!username)
return false; return false;
sprintf(buf, "SELECT usesuper FROM pg_user WHERE usename = '%.*s'", NAMEDATALEN, username); initPQExpBuffer(&buf);
res = PSQLexec(buf); printfPQExpBuffer(&buf, "SELECT usesuper FROM pg_user WHERE usename = '%s'", username);
res = PSQLexec(buf.data);
termPQExpBuffer(&buf);
answer = answer =
(PQntuples(res) > 0 && PQnfields(res) > 0 (PQntuples(res) > 0 && PQnfields(res) > 0
......
...@@ -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/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 "postgres_fe.h"
#include "copy.h" #include "copy.h"
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#endif #endif
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqexpbuffer.h"
#include "pqsignal.h" #include "pqsignal.h"
#include "settings.h" #include "settings.h"
...@@ -229,7 +230,7 @@ parse_slash_copy(const char *args) ...@@ -229,7 +230,7 @@ parse_slash_copy(const char *args)
bool bool
do_copy(const char *args) do_copy(const char *args)
{ {
char query[128 + NAMEDATALEN]; PQExpBufferData query;
FILE *copystream; FILE *copystream;
struct copy_options *options; struct copy_options *options;
PGresult *result; PGresult *result;
...@@ -242,35 +243,27 @@ do_copy(const char *args) ...@@ -242,35 +243,27 @@ do_copy(const char *args)
if (!options) if (!options)
return false; return false;
strcpy(query, "COPY "); initPQExpBuffer(&query);
printfPQExpBuffer(&query, "COPY ");
if (options->binary) if (options->binary)
strcat(query, "BINARY "); appendPQExpBuffer(&query, "BINARY ");
strcat(query, "\""); appendPQExpBuffer(&query, "\"%s\" ", options->table);
strncat(query, options->table, NAMEDATALEN);
strcat(query, "\" ");
if (options->oids) if (options->oids)
strcat(query, "WITH OIDS "); appendPQExpBuffer(&query, "WITH OIDS ");
if (options->from) if (options->from)
strcat(query, "FROM STDIN"); appendPQExpBuffer(&query, "FROM STDIN");
else else
strcat(query, "TO STDOUT"); appendPQExpBuffer(&query, "TO STDOUT");
if (options->delim) if (options->delim)
{ appendPQExpBuffer(&query, " USING DELIMITERS '%s'", options->delim);
strcat(query, " USING DELIMITERS '");
strcat(query, options->delim);
strcat(query, "'");
}
if (options->null) if (options->null)
{ appendPQExpBuffer(&query, " WITH NULL AS '%s'", options->null);
strcat(query, " WITH NULL AS '");
strcat(query, options->null);
strcat(query, "'");
}
if (options->from) if (options->from)
{ {
...@@ -294,9 +287,11 @@ do_copy(const char *args) ...@@ -294,9 +287,11 @@ do_copy(const char *args)
free_copy_options(options); free_copy_options(options);
return false; return false;
} }
/* make sure the specified file is not a directory */ /* make sure the specified file is not a directory */
fstat(fileno(copystream),&st); fstat(fileno(copystream), &st);
if( S_ISDIR(st.st_mode) ){ if( S_ISDIR(st.st_mode) )
{
fclose(copystream); fclose(copystream);
psql_error("%s: cannot COPY TO/FROM a directory\n", psql_error("%s: cannot COPY TO/FROM a directory\n",
options->file); options->file);
...@@ -304,7 +299,8 @@ do_copy(const char *args) ...@@ -304,7 +299,8 @@ do_copy(const char *args)
return false; return false;
} }
result = PSQLexec(query); result = PSQLexec(query.data);
termPQExpBuffer(&query);
switch (PQresultStatus(result)) 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