Skip to content

Commit 3d72629

Browse files
committed
Remove traces of NAMEDATALEN and INDEX_MAX_KEYS from psql. Build buffers
dynamically with PQExpBuffer.
1 parent 246f47f commit 3d72629

File tree

3 files changed

+292
-293
lines changed

3 files changed

+292
-293
lines changed

src/bin/psql/command.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.71 2002/03/27 19:16:13 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.72 2002/04/24 05:24:00 petere Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -1433,14 +1433,16 @@ bool
14331433
test_superuser(const char *username)
14341434
{
14351435
PGresult *res;
1436-
char buf[64 + NAMEDATALEN];
1436+
PQExpBufferData buf;
14371437
bool answer;
14381438

14391439
if (!username)
14401440
return false;
14411441

1442-
sprintf(buf, "SELECT usesuper FROM pg_user WHERE usename = '%.*s'", NAMEDATALEN, username);
1443-
res = PSQLexec(buf);
1442+
initPQExpBuffer(&buf);
1443+
printfPQExpBuffer(&buf, "SELECT usesuper FROM pg_user WHERE usename = '%s'", username);
1444+
res = PSQLexec(buf.data);
1445+
termPQExpBuffer(&buf);
14441446

14451447
answer =
14461448
(PQntuples(res) > 0 && PQnfields(res) > 0

src/bin/psql/copy.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.20 2002/02/23 21:46:03 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.21 2002/04/24 05:24:00 petere Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "copy.h"
@@ -19,6 +19,7 @@
1919
#endif
2020

2121
#include "libpq-fe.h"
22+
#include "pqexpbuffer.h"
2223
#include "pqsignal.h"
2324

2425
#include "settings.h"
@@ -229,48 +230,40 @@ parse_slash_copy(const char *args)
229230
bool
230231
do_copy(const char *args)
231232
{
232-
char query[128 + NAMEDATALEN];
233+
PQExpBufferData query;
233234
FILE *copystream;
234235
struct copy_options *options;
235236
PGresult *result;
236237
bool success;
237-
struct stat st;
238+
struct stat st;
238239

239240
/* parse options */
240241
options = parse_slash_copy(args);
241242

242243
if (!options)
243244
return false;
244245

245-
strcpy(query, "COPY ");
246+
initPQExpBuffer(&query);
247+
248+
printfPQExpBuffer(&query, "COPY ");
246249
if (options->binary)
247-
strcat(query, "BINARY ");
250+
appendPQExpBuffer(&query, "BINARY ");
248251

249-
strcat(query, "\"");
250-
strncat(query, options->table, NAMEDATALEN);
251-
strcat(query, "\" ");
252+
appendPQExpBuffer(&query, "\"%s\" ", options->table);
252253
if (options->oids)
253-
strcat(query, "WITH OIDS ");
254+
appendPQExpBuffer(&query, "WITH OIDS ");
254255

255256
if (options->from)
256-
strcat(query, "FROM STDIN");
257+
appendPQExpBuffer(&query, "FROM STDIN");
257258
else
258-
strcat(query, "TO STDOUT");
259+
appendPQExpBuffer(&query, "TO STDOUT");
259260

260261

261262
if (options->delim)
262-
{
263-
strcat(query, " USING DELIMITERS '");
264-
strcat(query, options->delim);
265-
strcat(query, "'");
266-
}
263+
appendPQExpBuffer(&query, " USING DELIMITERS '%s'", options->delim);
267264

268265
if (options->null)
269-
{
270-
strcat(query, " WITH NULL AS '");
271-
strcat(query, options->null);
272-
strcat(query, "'");
273-
}
266+
appendPQExpBuffer(&query, " WITH NULL AS '%s'", options->null);
274267

275268
if (options->from)
276269
{
@@ -294,17 +287,20 @@ do_copy(const char *args)
294287
free_copy_options(options);
295288
return false;
296289
}
297-
/* make sure the specified file is not a directory */
298-
fstat(fileno(copystream),&st);
299-
if( S_ISDIR(st.st_mode) ){
300-
fclose(copystream);
290+
291+
/* make sure the specified file is not a directory */
292+
fstat(fileno(copystream), &st);
293+
if( S_ISDIR(st.st_mode) )
294+
{
295+
fclose(copystream);
301296
psql_error("%s: cannot COPY TO/FROM a directory\n",
302297
options->file);
303298
free_copy_options(options);
304299
return false;
305-
}
300+
}
306301

307-
result = PSQLexec(query);
302+
result = PSQLexec(query.data);
303+
termPQExpBuffer(&query);
308304

309305
switch (PQresultStatus(result))
310306
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy