diff options
Diffstat (limited to 'src/bin')
30 files changed, 1054 insertions, 969 deletions
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c index 64ece82bf8..d126bef2e7 100644 --- a/src/bin/pg_controldata/pg_controldata.c +++ b/src/bin/pg_controldata/pg_controldata.c @@ -6,7 +6,7 @@ * copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001; * licence: BSD * - * $Header: /cvsroot/pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.5 2002/09/02 22:18:26 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.6 2002/09/04 20:31:34 momjian Exp $ */ #include "postgres.h" @@ -127,11 +127,11 @@ main(int argc, char *argv[]) if (!EQ_CRC64(crc, ControlFile.crc)) printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n" "Either the file is corrupt, or it has a different layout than this program\n" - "is expecting. The results below are untrustworthy.\n\n")); + "is expecting. The results below are untrustworthy.\n\n")); /* - * Use variable for format to suppress overly-anal-retentive gcc warning - * about %c + * Use variable for format to suppress overly-anal-retentive gcc + * warning about %c */ strftime(pgctime_str, sizeof(pgctime_str), strftime_fmt, localtime(&(ControlFile.time))); diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index ddcb617974..bd7b1a0c00 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.69 2002/08/29 00:17:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.70 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -30,11 +30,11 @@ #endif static void findParentsByOid(TableInfo *tblinfo, int numTables, - InhInfo *inhinfo, int numInherits, - const char *oid, - int *numParentsPtr, int **parentIndexes); + InhInfo *inhinfo, int numInherits, + const char *oid, + int *numParentsPtr, int **parentIndexes); static void flagInhTables(TableInfo *tbinfo, int numTables, - InhInfo *inhinfo, int numInherits); + InhInfo *inhinfo, int numInherits); static void flagInhAttrs(TableInfo *tbinfo, int numTables, InhInfo *inhinfo, int numInherits); static int strInArray(const char *pattern, char **arr, int arr_size); diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index 314cf88b5c..ef71182fcc 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.c,v 1.1 2002/08/27 18:57:26 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.c,v 1.2 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,15 +31,17 @@ fmtId(const char *rawid) { static PQExpBuffer id_return = NULL; const char *cp; - bool need_quotes = false; + bool need_quotes = false; if (id_return) /* first time through? */ resetPQExpBuffer(id_return); else id_return = createPQExpBuffer(); - /* These checks need to match the identifier production in scan.l. - * Don't use islower() etc. */ + /* + * These checks need to match the identifier production in scan.l. + * Don't use islower() etc. + */ if (ScanKeywordLookup(rawid)) need_quotes = true; diff --git a/src/bin/pg_dump/dumputils.h b/src/bin/pg_dump/dumputils.h index b4e39a1bd2..a34d937a0e 100644 --- a/src/bin/pg_dump/dumputils.h +++ b/src/bin/pg_dump/dumputils.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.h,v 1.2 2002/08/27 21:50:23 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.h,v 1.3 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -23,4 +23,4 @@ extern char *simple_prompt(const char *prompt, int maxlen, bool echo); extern const char *fmtId(const char *identifier); extern void appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll); -#endif /* DUMPUTILS_H */ +#endif /* DUMPUTILS_H */ diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index de840e1b77..5226255f07 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.23 2002/08/27 18:57:26 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.24 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -68,7 +68,8 @@ typedef struct _restoreOptions * cirsumstances */ int use_setsessauth;/* use SET SESSSION AUTHORIZATION instead * of \connect */ - int disable_triggers;/* disable triggers during data-only restore */ + int disable_triggers; /* disable triggers during + * data-only restore */ char *superuser; /* Username to use as superuser */ int dataOnly; int dropSchema; @@ -132,14 +133,14 @@ PGconn *ConnectDatabase(Archive *AH, /* Called to add a TOC entry */ extern void ArchiveEntry(Archive *AHX, const char *oid, const char *tag, - const char *namespace, const char *owner, - const char *desc, const char *((*deps)[]), - const char *defn, const char *dropStmt, - const char *copyStmt, - DataDumperPtr dumpFn, void *dumpArg); + const char *namespace, const char *owner, + const char *desc, const char *((*deps)[]), + const char *defn, const char *dropStmt, + const char *copyStmt, + DataDumperPtr dumpFn, void *dumpArg); /* Called to write *data* to the archive */ -extern size_t WriteData(Archive *AH, const void *data, size_t dLen); +extern size_t WriteData(Archive *AH, const void *data, size_t dLen); /* extern int StartBlobs(Archive* AH); diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index aefd094b53..0885cfeac2 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.56 2002/08/27 18:57:26 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.57 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -170,8 +170,8 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) } /* - * Work out if we have an implied data-only restore. This can happen if - * the dump was data only or if the user has used a toc list to + * Work out if we have an implied data-only restore. This can happen + * if the dump was data only or if the user has used a toc list to * exclude all of the schema data. All we do is look for schema * entries - if none are found then we set the dataOnly flag. * @@ -453,10 +453,10 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop oldSchema = strdup(AH->currSchema); /* - * Become superuser if possible, since they are the only ones - * who can update pg_class. If -S was not given, but we are allowed - * to use SET SESSION AUTHORIZATION, assume the initial user identity - * is a superuser. Otherwise we just have to bull ahead anyway. + * Become superuser if possible, since they are the only ones who can + * update pg_class. If -S was not given, but we are allowed to use + * SET SESSION AUTHORIZATION, assume the initial user identity is a + * superuser. Otherwise we just have to bull ahead anyway. */ if (ropt->superuser) { @@ -465,9 +465,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop _selectOutputSchema(AH, oldSchema); } else if (AH->ropt->use_setsessauth) - { _doSetSessionAuth(AH, NULL); - } ahlog(AH, 1, "disabling triggers\n"); @@ -499,9 +497,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop _selectOutputSchema(AH, oldSchema); } else if (AH->ropt->use_setsessauth) - { _doSetSessionAuth(AH, oldUser); - } free(oldUser); free(oldSchema); } @@ -520,10 +516,10 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt oldSchema = strdup(AH->currSchema); /* - * Become superuser if possible, since they are the only ones - * who can update pg_class. If -S was not given, but we are allowed - * to use SET SESSION AUTHORIZATION, assume the initial user identity - * is a superuser. Otherwise we just have to bull ahead anyway. + * Become superuser if possible, since they are the only ones who can + * update pg_class. If -S was not given, but we are allowed to use + * SET SESSION AUTHORIZATION, assume the initial user identity is a + * superuser. Otherwise we just have to bull ahead anyway. */ if (ropt->superuser) { @@ -532,9 +528,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt _selectOutputSchema(AH, oldSchema); } else if (AH->ropt->use_setsessauth) - { _doSetSessionAuth(AH, NULL); - } ahlog(AH, 1, "enabling triggers\n"); @@ -569,9 +563,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt _selectOutputSchema(AH, oldSchema); } else if (AH->ropt->use_setsessauth) - { _doSetSessionAuth(AH, oldUser); - } free(oldUser); free(oldSchema); } @@ -814,7 +806,7 @@ EndRestoreBlob(ArchiveHandle *AH, Oid oid) if (AH->lo_buf_used > 0) { /* Write remaining bytes from the LO buffer */ - size_t res; + size_t res; res = lo_write(AH->connection, AH->loFd, (void *) AH->lo_buf, AH->lo_buf_used); @@ -822,7 +814,7 @@ EndRestoreBlob(ArchiveHandle *AH, Oid oid) (unsigned long) AH->lo_buf_used, (unsigned long) res); if (res != AH->lo_buf_used) die_horribly(AH, modulename, "could not write to large object (result: %lu, expected: %lu)\n", - (unsigned long) res, (unsigned long) AH->lo_buf_used); + (unsigned long) res, (unsigned long) AH->lo_buf_used); AH->lo_buf_used = 0; } @@ -1209,24 +1201,24 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH) if (AH->lo_buf_used + size * nmemb > AH->lo_buf_size) { /* Split LO buffer */ - size_t remaining = AH->lo_buf_size - AH->lo_buf_used; - size_t slack = nmemb * size - remaining; + size_t remaining = AH->lo_buf_size - AH->lo_buf_used; + size_t slack = nmemb * size - remaining; - memcpy((char *)AH->lo_buf + AH->lo_buf_used, ptr, remaining); + memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, remaining); res = lo_write(AH->connection, AH->loFd, AH->lo_buf, AH->lo_buf_size); ahlog(AH, 5, "wrote %lu bytes of large object data (result = %lu)\n", (unsigned long) AH->lo_buf_size, (unsigned long) res); if (res != AH->lo_buf_size) die_horribly(AH, modulename, "could not write to large object (result: %lu, expected: %lu)\n", - (unsigned long) res, (unsigned long) AH->lo_buf_size); - memcpy(AH->lo_buf, (char *)ptr + remaining, slack); + (unsigned long) res, (unsigned long) AH->lo_buf_size); + memcpy(AH->lo_buf, (char *) ptr + remaining, slack); AH->lo_buf_used = slack; } else { /* LO Buffer is still large enough, buffer it */ - memcpy((char *)AH->lo_buf + AH->lo_buf_used, ptr, size * nmemb); + memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, size * nmemb); AH->lo_buf_used += size * nmemb; } @@ -1635,7 +1627,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, AH->currUser = strdup(""); /* So it's valid, but we can free() it * later if necessary */ - AH->currSchema = strdup(""); /* ditto */ + AH->currSchema = strdup(""); /* ditto */ AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry)); if (!AH->toc) @@ -1957,10 +1949,13 @@ static void _doSetSessionAuth(ArchiveHandle *AH, const char *user) { PQExpBuffer cmd = createPQExpBuffer(); + appendPQExpBuffer(cmd, "SET SESSION AUTHORIZATION "); if (user) - /* SQL requires a string literal here. Might as well be - * correct. */ + + /* + * SQL requires a string literal here. Might as well be correct. + */ appendStringLiteral(cmd, user, false); else appendPQExpBuffer(cmd, "DEFAULT"); @@ -1992,7 +1987,7 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user) * user, this won't do anything. * * If we're currently restoring right into a database, this will - * actually establish a connection. Otherwise it puts a \connect into + * actually establish a connection. Otherwise it puts a \connect into * the script output. */ static void @@ -2007,9 +2002,7 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user) * needed */ if (!dbname && AH->ropt->use_setsessauth) - { _doSetSessionAuth(AH, user); - } else if (AH->ropt && AH->ropt->noReconnect) { /* When -R was given, don't do anything. */ diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h index e22320d19d..3572dd1103 100644 --- a/src/bin/pg_dump/pg_backup_archiver.h +++ b/src/bin/pg_dump/pg_backup_archiver.h @@ -17,7 +17,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.46 2002/08/20 17:54:44 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.47 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -229,7 +229,7 @@ typedef struct _archiveHandle RestoreOptions *ropt; /* Used to check restore options in * ahwrite etc */ - void *lo_buf; + void *lo_buf; size_t lo_buf_used; size_t lo_buf_size; } ArchiveHandle; @@ -241,7 +241,7 @@ typedef struct _tocEntry int id; int hadDumper; /* Archiver was passed a dumper routine * (used in restore) */ - char *tag; /* index tag */ + char *tag; /* index tag */ char *namespace; /* null or empty string if not in a schema */ char *owner; char *desc; @@ -282,10 +282,10 @@ extern int TocIDRequired(ArchiveHandle *AH, int id, RestoreOptions *ropt); * Mandatory routines for each supported format */ -extern size_t WriteInt(ArchiveHandle *AH, int i); +extern size_t WriteInt(ArchiveHandle *AH, int i); extern int ReadInt(ArchiveHandle *AH); extern char *ReadStr(ArchiveHandle *AH); -extern size_t WriteStr(ArchiveHandle *AH, const char *s); +extern size_t WriteStr(ArchiveHandle *AH, const char *s); extern void StartRestoreBlobs(ArchiveHandle *AH); extern void StartRestoreBlob(ArchiveHandle *AH, Oid oid); diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c index 3b220efa88..37597f7b06 100644 --- a/src/bin/pg_dump/pg_backup_custom.c +++ b/src/bin/pg_dump/pg_backup_custom.c @@ -19,7 +19,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.20 2002/08/20 17:54:44 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.21 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,12 +36,12 @@ static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te); static void _StartData(ArchiveHandle *AH, TocEntry *te); -static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen); +static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen); static void _EndData(ArchiveHandle *AH, TocEntry *te); static int _WriteByte(ArchiveHandle *AH, const int i); static int _ReadByte(ArchiveHandle *); -static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); -static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); +static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); +static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); static void _CloseArchive(ArchiveHandle *AH); static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te); @@ -147,7 +147,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH) /* Initialize LO buffering */ AH->lo_buf_size = LOBBUFSIZE; - AH->lo_buf = (void *)malloc(LOBBUFSIZE); + AH->lo_buf = (void *) malloc(LOBBUFSIZE); if (AH->lo_buf == NULL) die_horribly(AH, modulename, "out of memory\n"); @@ -567,7 +567,7 @@ _PrintData(ArchiveHandle *AH) cnt = fread(in, 1, blkLen, AH->FH); if (cnt != blkLen) die_horribly(AH, modulename, - "could not read data block - expected %lu, got %lu\n", + "could not read data block - expected %lu, got %lu\n", (unsigned long) blkLen, (unsigned long) cnt); ctx->filePos += blkLen; @@ -695,7 +695,7 @@ _skipData(ArchiveHandle *AH) cnt = fread(in, 1, blkLen, AH->FH); if (cnt != blkLen) die_horribly(AH, modulename, - "could not read data block - expected %lu, got %lu\n", + "could not read data block - expected %lu, got %lu\n", (unsigned long) blkLen, (unsigned long) cnt); ctx->filePos += blkLen; @@ -956,8 +956,8 @@ _DoDeflate(ArchiveHandle *AH, lclContext *ctx, int flush) if (zp->avail_out < zlibOutSize) { /* - * printf("Wrote %lu byte deflated chunk\n", (unsigned long) (zlibOutSize - - * zp->avail_out)); + * printf("Wrote %lu byte deflated chunk\n", (unsigned + * long) (zlibOutSize - zp->avail_out)); */ WriteInt(AH, zlibOutSize - zp->avail_out); if (fwrite(out, 1, zlibOutSize - zp->avail_out, AH->FH) != (zlibOutSize - zp->avail_out)) diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index f54153d4ae..c3bb6b0e6d 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -5,7 +5,7 @@ * Implements the basic DB functions used by the archiver. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.39 2002/08/27 18:57:26 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.40 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -279,7 +279,7 @@ ConnectDatabase(Archive *AHX, /* check to see that the backend connection was successfully made */ if (PQstatus(AH->connection) == CONNECTION_BAD) die_horribly(AH, modulename, "connection to database \"%s\" failed: %s", - PQdb(AH->connection), PQerrorMessage(AH->connection)); + PQdb(AH->connection), PQerrorMessage(AH->connection)); /* check for version mismatch */ _check_database_version(AH, ignoreVersion); @@ -598,8 +598,8 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te) appendPQExpBuffer(tblQry, "SELECT a.attname FROM " "pg_catalog.pg_attribute a, pg_catalog.pg_type t " - "WHERE a.attnum > 0 AND a.attrelid = '%s'::pg_catalog.regclass " - "AND a.atttypid = t.oid AND t.typname in ('oid', 'lo')", + "WHERE a.attnum > 0 AND a.attrelid = '%s'::pg_catalog.regclass " + "AND a.atttypid = t.oid AND t.typname in ('oid', 'lo')", tblName->data); res = PQexec(AH->blobConnection, tblQry->data); @@ -639,12 +639,12 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te) if (!uRes) die_horribly(AH, modulename, "could not update column \"%s\" of table \"%s\": %s", - attr, te->tag, PQerrorMessage(AH->blobConnection)); + attr, te->tag, PQerrorMessage(AH->blobConnection)); if (PQresultStatus(uRes) != PGRES_COMMAND_OK) die_horribly(AH, modulename, "error while updating column \"%s\" of table \"%s\": %s", - attr, te->tag, PQerrorMessage(AH->blobConnection)); + attr, te->tag, PQerrorMessage(AH->blobConnection)); PQclear(uRes); } @@ -686,7 +686,7 @@ InsertBlobXref(ArchiveHandle *AH, Oid old, Oid new) PQExpBuffer qry = createPQExpBuffer(); appendPQExpBuffer(qry, - "Insert Into %s(oldOid, newOid) Values ('%u', '%u');", + "Insert Into %s(oldOid, newOid) Values ('%u', '%u');", BLOB_XREF_TABLE, old, new); ExecuteSqlCommand(AH, qry, "could not create large object cross-reference entry", true); diff --git a/src/bin/pg_dump/pg_backup_files.c b/src/bin/pg_dump/pg_backup_files.c index 0183be6f5d..b471da6f4c 100644 --- a/src/bin/pg_dump/pg_backup_files.c +++ b/src/bin/pg_dump/pg_backup_files.c @@ -20,7 +20,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.17 2002/08/20 17:54:44 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.18 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -30,12 +30,12 @@ static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te); static void _StartData(ArchiveHandle *AH, TocEntry *te); -static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen); +static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen); static void _EndData(ArchiveHandle *AH, TocEntry *te); static int _WriteByte(ArchiveHandle *AH, const int i); static int _ReadByte(ArchiveHandle *); -static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); -static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); +static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); +static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); static void _CloseArchive(ArchiveHandle *AH); static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te); @@ -107,7 +107,7 @@ InitArchiveFmt_Files(ArchiveHandle *AH) /* Initialize LO buffering */ AH->lo_buf_size = LOBBUFSIZE; - AH->lo_buf = (void *)malloc(LOBBUFSIZE); + AH->lo_buf = (void *) malloc(LOBBUFSIZE); if (AH->lo_buf == NULL) die_horribly(AH, modulename, "out of memory\n"); diff --git a/src/bin/pg_dump/pg_backup_null.c b/src/bin/pg_dump/pg_backup_null.c index c5a01e3c96..2925dd1ef1 100644 --- a/src/bin/pg_dump/pg_backup_null.c +++ b/src/bin/pg_dump/pg_backup_null.c @@ -17,7 +17,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.10 2002/08/20 17:54:44 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.11 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,10 +29,10 @@ #include <string.h> #include <unistd.h> /* for dup */ -static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen); +static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen); static void _EndData(ArchiveHandle *AH, TocEntry *te); static int _WriteByte(ArchiveHandle *AH, const int i); -static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); +static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); static void _CloseArchive(ArchiveHandle *AH); static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c index 35c85c2cf6..eb6e9fca12 100644 --- a/src/bin/pg_dump/pg_backup_tar.c +++ b/src/bin/pg_dump/pg_backup_tar.c @@ -16,7 +16,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.27 2002/09/03 18:50:54 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.28 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,12 +32,12 @@ static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te); static void _StartData(ArchiveHandle *AH, TocEntry *te); -static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen); +static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen); static void _EndData(ArchiveHandle *AH, TocEntry *te); static int _WriteByte(ArchiveHandle *AH, const int i); static int _ReadByte(ArchiveHandle *); -static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); -static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); +static size_t _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); +static size_t _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); static void _CloseArchive(ArchiveHandle *AH); static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te); @@ -107,13 +107,13 @@ static int tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt,...); static void _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th); static int _tarChecksum(char *th); static TAR_MEMBER *_tarPositionTo(ArchiveHandle *AH, const char *filename); -static size_t tarRead(void *buf, size_t len, TAR_MEMBER *th); -static size_t tarWrite(const void *buf, size_t len, TAR_MEMBER *th); +static size_t tarRead(void *buf, size_t len, TAR_MEMBER *th); +static size_t tarWrite(const void *buf, size_t len, TAR_MEMBER *th); static void _tarWriteHeader(TAR_MEMBER *th); static int _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th); -static size_t _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh); +static size_t _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh); -static size_t _scriptOut(ArchiveHandle *AH, const void *buf, size_t len); +static size_t _scriptOut(ArchiveHandle *AH, const void *buf, size_t len); /* * Initializer @@ -152,7 +152,7 @@ InitArchiveFmt_Tar(ArchiveHandle *AH) /* Initialize LO buffering */ AH->lo_buf_size = LOBBUFSIZE; - AH->lo_buf = (void *)malloc(LOBBUFSIZE); + AH->lo_buf = (void *) malloc(LOBBUFSIZE); if (AH->lo_buf == NULL) die_horribly(AH, modulename, "out of memory\n"); @@ -537,7 +537,7 @@ tarWrite(const void *buf, size_t len, TAR_MEMBER *th) if (res != len) die_horribly(th->AH, modulename, - "could not write to tar member (wrote %lu, attempted %lu)\n", + "could not write to tar member (wrote %lu, attempted %lu)\n", (unsigned long) res, (unsigned long) len); th->pos += res; @@ -1025,7 +1025,9 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th) if (len != th->fileLen) { - char buf1[100], buf2[100]; + char buf1[100], + buf2[100]; + snprintf(buf1, 100, INT64_FORMAT, (int64) len); snprintf(buf2, 100, INT64_FORMAT, (int64) th->pos); die_horribly(AH, modulename, "actual file length (%s) does not match expected (%s)\n", @@ -1060,7 +1062,9 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename) /* Go to end of current file, if any */ if (ctx->tarFHpos != 0) { - char buf1[100], buf2[100]; + char buf1[100], + buf2[100]; + snprintf(buf1, 100, INT64_FORMAT, (int64) ctx->tarFHpos); snprintf(buf2, 100, INT64_FORMAT, (int64) ctx->tarNextMember); ahlog(AH, 4, "moving from position %s to next member at file position %s\n", @@ -1071,7 +1075,8 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename) } { - char buf[100]; + char buf[100]; + snprintf(buf, 100, INT64_FORMAT, (int64) ctx->tarFHpos); ahlog(AH, 4, "now at file position %s\n", buf); } @@ -1138,7 +1143,9 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th) #if 0 if (ftello(ctx->tarFH) != ctx->tarFHpos) { - char buf1[100], buf2[100]; + char buf1[100], + buf2[100]; + snprintf(buf1, 100, INT64_FORMAT, (int64) ftello(ctx->tarFH)); snprintf(buf2, 100, INT64_FORMAT, (int64) ftello(ctx->tarFHpos)); die_horribly(AH, modulename, @@ -1188,7 +1195,8 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th) sscanf(&h[148], "%8o", &sum); { - char buf[100]; + char buf[100]; + snprintf(buf, 100, INT64_FORMAT, (int64) hPos); ahlog(AH, 3, "TOC Entry %s at %s (length %lu, checksum %d)\n", &tag[0], buf, (unsigned long) len, sum); @@ -1196,7 +1204,8 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th) if (chk != sum) { - char buf[100]; + char buf[100]; + snprintf(buf, 100, INT64_FORMAT, (int64) ftello(ctx->tarFH)); die_horribly(AH, modulename, "corrupt tar header found in %s " diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 0e6500a707..6e37343459 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -22,7 +22,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.296 2002/09/02 06:11:42 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.297 2002/09/04 20:31:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -78,27 +78,27 @@ static void help(const char *progname); static int parse_version(const char *versionString); static NamespaceInfo *findNamespace(const char *nsoid, const char *objoid); static void dumpClasses(const TableInfo *tblinfo, const int numTables, - Archive *fout, const bool oids); + Archive *fout, const bool oids); static void dumpComment(Archive *fout, const char *target, - const char *namespace, const char *owner, - const char *oid, const char *classname, int subid, - const char *((*deps)[])); + const char *namespace, const char *owner, + const char *oid, const char *classname, int subid, + const char *((*deps)[])); static void dumpOneBaseType(Archive *fout, TypeInfo *tinfo, - FuncInfo *g_finfo, int numFuncs, - TypeInfo *g_tinfo, int numTypes); + FuncInfo *g_finfo, int numFuncs, + TypeInfo *g_tinfo, int numTypes); static void dumpOneDomain(Archive *fout, TypeInfo *tinfo); static void dumpOneCompositeType(Archive *fout, TypeInfo *tinfo); static void dumpOneTable(Archive *fout, TableInfo *tbinfo, - TableInfo *g_tblinfo); + TableInfo *g_tblinfo); static void dumpOneSequence(Archive *fout, TableInfo *tbinfo, - const bool schemaOnly, const bool dataOnly); + const bool schemaOnly, const bool dataOnly); static void dumpTableACL(Archive *fout, TableInfo *tbinfo); static void dumpFuncACL(Archive *fout, FuncInfo *finfo); static void dumpAggACL(Archive *fout, AggInfo *finfo); static void dumpACL(Archive *fout, const char *type, const char *name, - const char *tag, const char *nspname, - const char *usename, const char *acl, const char *objoid); + const char *tag, const char *nspname, + const char *usename, const char *acl, const char *objoid); static void dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables); static void dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables); @@ -106,10 +106,10 @@ static void dumpRules(Archive *fout, TableInfo *tblinfo, int numTables); static char *format_function_signature(FuncInfo *finfo, bool honor_quotes); static void dumpOneFunc(Archive *fout, FuncInfo *finfo); static void dumpOneOpr(Archive *fout, OprInfo *oprinfo, - OprInfo *g_oprinfo, int numOperators); + OprInfo *g_oprinfo, int numOperators); static const char *convertRegProcReference(const char *proc); static const char *convertOperatorReference(const char *opr, - OprInfo *g_oprinfo, int numOperators); + OprInfo *g_oprinfo, int numOperators); static void dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo); static void dumpOneAgg(Archive *fout, AggInfo *agginfo); static Oid findLastBuiltinOid_V71(const char *); @@ -361,7 +361,7 @@ main(int argc, char **argv) */ if (selectTablename[0] == '"') { - char *endptr; + char *endptr; endptr = selectTablename + strlen(selectTablename) - 1; if (*endptr == '"') @@ -434,8 +434,8 @@ main(int argc, char **argv) #ifndef HAVE_GETOPT_LONG case '-': fprintf(stderr, - _("%s was compiled without support for long options.\n" - "Use --help for help on invocation options.\n"), + _("%s was compiled without support for long options.\n" + "Use --help for help on invocation options.\n"), progname); exit(1); break; @@ -453,8 +453,8 @@ main(int argc, char **argv) if (optind < (argc - 1)) { fprintf(stderr, - _("%s: too many command line options (first is '%s')\n" - "Try '%s --help' for more information.\n"), + _("%s: too many command line options (first is '%s')\n" + "Try '%s --help' for more information.\n"), progname, argv[optind + 1], progname); exit(1); } @@ -656,69 +656,69 @@ help(const char *progname) printf(_("Options:\n")); #ifdef HAVE_GETOPT_LONG - printf(_( " -a, --data-only dump only the data, not the schema\n")); - printf(_( " -b, --blobs include large objects in dump\n")); - printf(_( " -c, --clean clean (drop) schema prior to create\n")); - printf(_( " -C, --create include commands to create database in dump\n")); - printf(_( " -d, --inserts dump data as INSERT, rather than COPY, commands\n")); - printf(_( " -D, --column-inserts dump data as INSERT commands with column names\n")); - printf(_( " -f, --file=FILENAME output file name\n")); - printf(_( " -F, --format {c|t|p} output file format (custom, tar, plain text)\n")); - printf(_( " -h, --host=HOSTNAME database server host name\n")); - printf(_( " -i, --ignore-version proceed even when server version mismatches\n" - " pg_dump version\n")); - printf(_( " -o, --oids include OIDs in dump\n")); - printf(_( " -O, --no-owner do not output \\connect commands in plain\n" - " text format\n")); - printf(_( " -p, --port=PORT database server port number\n")); - printf(_( " -R, --no-reconnect disable ALL reconnections to the database in\n" - " plain text format\n")); - printf(_( " -s, --schema-only dump only the schema, no data\n")); - printf(_( " -S, --superuser=NAME specify the superuser user name to use in\n" - " plain text format\n")); - printf(_( " -t, --table=TABLE dump this table only (* for all)\n")); - printf(_( " -U, --username=NAME connect as specified database user\n")); - printf(_( " -v, --verbose verbose mode\n")); - printf(_( " -W, --password force password prompt (should happen automatically)\n")); - printf(_( " -x, --no-privileges do not dump privileges (grant/revoke)\n")); - printf(_( " -X use-set-session-authorization, --use-set-session-authorization\n" - " output SET SESSION AUTHORIZATION commands rather\n" - " than \\connect commands\n")); - printf(_( " -X disable-triggers, --disable-triggers\n" - " disable triggers during data-only restore\n")); - printf(_( " -Z, --compress {0-9} compression level for compressed formats\n")); - -#else /* not HAVE_GETOPT_LONG */ - printf(_( " -a dump only the data, not the schema\n")); - printf(_( " -b include large objects in dump\n")); - printf(_( " -c clean (drop) schema prior to create\n")); - printf(_( " -C include commands to create database in dump\n")); - printf(_( " -d dump data as INSERT, rather than COPY, commands\n")); - printf(_( " -D dump data as INSERT commands with column names\n")); - printf(_( " -f FILENAME output file name\n")); - printf(_( " -F {c|t|p} output file format (custom, tar, plain text)\n")); - printf(_( " -h HOSTNAME database server host name\n")); - printf(_( " -i proceed even when server version mismatches\n" - " pg_dump version\n")); - printf(_( " -o include OIDs in dump\n")); - printf(_( " -O do not output \\connect commands in plain\n" - " text format\n")); - printf(_( " -p PORT database server port number\n")); - printf(_( " -R disable ALL reconnections to the database in\n" - " plain text format\n")); - printf(_( " -s dump only the schema, no data\n")); - printf(_( " -S NAME specify the superuser user name to use in\n" - " plain text format\n")); - printf(_( " -t TABLE dump this table only (* for all)\n")); - printf(_( " -U NAME connect as specified database user\n")); - printf(_( " -v verbose mode\n")); - printf(_( " -W force password prompt (should happen automatically)\n")); - printf(_( " -x do not dump privileges (grant/revoke)\n")); - printf(_( " -X use-set-session-authorization\n" - " output SET SESSION AUTHORIZATION commands rather\n" - " than \\connect commands\n")); - printf(_( " -X disable-triggers disable triggers during data-only restore\n")); - printf(_( " -Z {0-9} compression level for compressed formats\n")); + printf(_(" -a, --data-only dump only the data, not the schema\n")); + printf(_(" -b, --blobs include large objects in dump\n")); + printf(_(" -c, --clean clean (drop) schema prior to create\n")); + printf(_(" -C, --create include commands to create database in dump\n")); + printf(_(" -d, --inserts dump data as INSERT, rather than COPY, commands\n")); + printf(_(" -D, --column-inserts dump data as INSERT commands with column names\n")); + printf(_(" -f, --file=FILENAME output file name\n")); + printf(_(" -F, --format {c|t|p} output file format (custom, tar, plain text)\n")); + printf(_(" -h, --host=HOSTNAME database server host name\n")); + printf(_(" -i, --ignore-version proceed even when server version mismatches\n" + " pg_dump version\n")); + printf(_(" -o, --oids include OIDs in dump\n")); + printf(_(" -O, --no-owner do not output \\connect commands in plain\n" + " text format\n")); + printf(_(" -p, --port=PORT database server port number\n")); + printf(_(" -R, --no-reconnect disable ALL reconnections to the database in\n" + " plain text format\n")); + printf(_(" -s, --schema-only dump only the schema, no data\n")); + printf(_(" -S, --superuser=NAME specify the superuser user name to use in\n" + " plain text format\n")); + printf(_(" -t, --table=TABLE dump this table only (* for all)\n")); + printf(_(" -U, --username=NAME connect as specified database user\n")); + printf(_(" -v, --verbose verbose mode\n")); + printf(_(" -W, --password force password prompt (should happen automatically)\n")); + printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n")); + printf(_(" -X use-set-session-authorization, --use-set-session-authorization\n" + " output SET SESSION AUTHORIZATION commands rather\n" + " than \\connect commands\n")); + printf(_(" -X disable-triggers, --disable-triggers\n" + " disable triggers during data-only restore\n")); + printf(_(" -Z, --compress {0-9} compression level for compressed formats\n")); + +#else /* not HAVE_GETOPT_LONG */ + printf(_(" -a dump only the data, not the schema\n")); + printf(_(" -b include large objects in dump\n")); + printf(_(" -c clean (drop) schema prior to create\n")); + printf(_(" -C include commands to create database in dump\n")); + printf(_(" -d dump data as INSERT, rather than COPY, commands\n")); + printf(_(" -D dump data as INSERT commands with column names\n")); + printf(_(" -f FILENAME output file name\n")); + printf(_(" -F {c|t|p} output file format (custom, tar, plain text)\n")); + printf(_(" -h HOSTNAME database server host name\n")); + printf(_(" -i proceed even when server version mismatches\n" + " pg_dump version\n")); + printf(_(" -o include OIDs in dump\n")); + printf(_(" -O do not output \\connect commands in plain\n" + " text format\n")); + printf(_(" -p PORT database server port number\n")); + printf(_(" -R disable ALL reconnections to the database in\n" + " plain text format\n")); + printf(_(" -s dump only the schema, no data\n")); + printf(_(" -S NAME specify the superuser user name to use in\n" + " plain text format\n")); + printf(_(" -t TABLE dump this table only (* for all)\n")); + printf(_(" -U NAME connect as specified database user\n")); + printf(_(" -v verbose mode\n")); + printf(_(" -W force password prompt (should happen automatically)\n")); + printf(_(" -x do not dump privileges (grant/revoke)\n")); + printf(_(" -X use-set-session-authorization\n" + " output SET SESSION AUTHORIZATION commands rather\n" + " than \\connect commands\n")); + printf(_(" -X disable-triggers disable triggers during data-only restore\n")); + printf(_(" -Z {0-9} compression level for compressed formats\n")); #endif printf(_("\nIf no database name is not supplied, then the PGDATABASE environment\n" @@ -766,7 +766,7 @@ selectDumpableNamespace(NamespaceInfo *nsinfo) { /* * If a specific table is being dumped, do not dump any complete - * namespaces. Otherwise, dump all non-system namespaces. + * namespaces. Otherwise, dump all non-system namespaces. */ if (selectTablename != NULL) nsinfo->dump = false; @@ -785,8 +785,8 @@ selectDumpableTable(TableInfo *tbinfo) { /* * Always dump if dumping parent namespace; else, if a particular - * tablename has been specified, dump matching table name; else, - * do not dump. + * tablename has been specified, dump matching table name; else, do + * not dump. */ if (tbinfo->relnamespace->dump) tbinfo->dump = true; @@ -817,7 +817,7 @@ dumpClasses_nodumpData(Archive *fout, char *oid, void *dctxv) int ret; bool copydone; char copybuf[COPYBUFSIZ]; - const char* column_list; + const char *column_list; if (g_verbose) write_msg(NULL, "dumping out the contents of table %s\n", classname); @@ -906,46 +906,42 @@ dumpClasses_nodumpData(Archive *fout, char *oid, void *dctxv) /* * THROTTLE: * - * There was considerable discussion in late July, 2000 - * regarding slowing down pg_dump when backing up large - * tables. Users with both slow & fast (muti-processor) - * machines experienced performance degradation when doing - * a backup. + * There was considerable discussion in late July, 2000 regarding + * slowing down pg_dump when backing up large tables. Users with + * both slow & fast (muti-processor) machines experienced + * performance degradation when doing a backup. * - * Initial attempts based on sleeping for a number of ms for - * each ms of work were deemed too complex, then a simple - * 'sleep in each loop' implementation was suggested. The - * latter failed because the loop was too tight. Finally, - * the following was implemented: + * Initial attempts based on sleeping for a number of ms for each ms + * of work were deemed too complex, then a simple 'sleep in each + * loop' implementation was suggested. The latter failed because + * the loop was too tight. Finally, the following was implemented: * - * If throttle is non-zero, then See how long since the last - * sleep. Work out how long to sleep (based on ratio). If - * sleep is more than 100ms, then sleep reset timer EndIf - * EndIf + * If throttle is non-zero, then See how long since the last sleep. + * Work out how long to sleep (based on ratio). If sleep is more + * than 100ms, then sleep reset timer EndIf EndIf * - * where the throttle value was the number of ms to sleep per - * ms of work. The calculation was done in each loop. + * where the throttle value was the number of ms to sleep per ms of + * work. The calculation was done in each loop. * - * Most of the hard work is done in the backend, and this - * solution still did not work particularly well: on slow - * machines, the ratio was 50:1, and on medium paced - * machines, 1:1, and on fast multi-processor machines, it - * had little or no effect, for reasons that were unclear. + * Most of the hard work is done in the backend, and this solution + * still did not work particularly well: on slow machines, the + * ratio was 50:1, and on medium paced machines, 1:1, and on fast + * multi-processor machines, it had little or no effect, for + * reasons that were unclear. * * Further discussion ensued, and the proposal was dropped. * - * For those people who want this feature, it can be - * implemented using gettimeofday in each loop, - * calculating the time since last sleep, multiplying that - * by the sleep ratio, then if the result is more than a - * preset 'minimum sleep time' (say 100ms), call the - * 'select' function to sleep for a subsecond period ie. + * For those people who want this feature, it can be implemented + * using gettimeofday in each loop, calculating the time since + * last sleep, multiplying that by the sleep ratio, then if the + * result is more than a preset 'minimum sleep time' (say 100ms), + * call the 'select' function to sleep for a subsecond period ie. * * select(0, NULL, NULL, NULL, &tvi); * - * This will return after the interval specified in the - * structure tvi. Fianally, call gettimeofday again to - * save the 'last sleep time'. + * This will return after the interval specified in the structure + * tvi. Fianally, call gettimeofday again to save the 'last sleep + * time'. */ } archprintf(fout, "\\.\n\n\n"); @@ -1059,27 +1055,27 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) case FLOAT4OID: case FLOAT8OID: case NUMERICOID: - { - /* - * These types are printed without quotes - * unless they contain values that aren't - * accepted by the scanner unquoted (e.g., - * 'NaN'). Note that strtod() and friends - * might accept NaN, so we can't use that to - * test. - * - * In reality we only need to defend against - * infinity and NaN, so we need not get too - * crazy about pattern matching here. - */ - const char *s = PQgetvalue(res, tuple, field); - - if (strspn(s, "0123456789 +-eE.") == strlen(s)) - archprintf(fout, "%s", s); - else - archprintf(fout, "'%s'", s); - } - break; + { + /* + * These types are printed without quotes + * unless they contain values that aren't + * accepted by the scanner unquoted (e.g., + * 'NaN'). Note that strtod() and friends + * might accept NaN, so we can't use that to + * test. + * + * In reality we only need to defend against + * infinity and NaN, so we need not get too + * crazy about pattern matching here. + */ + const char *s = PQgetvalue(res, tuple, field); + + if (strspn(s, "0123456789 +-eE.") == strlen(s)) + archprintf(fout, "%s", s); + else + archprintf(fout, "'%s'", s); + } + break; case BITOID: case VARBITOID: @@ -1088,7 +1084,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) break; case BOOLOID: - if (strcmp(PQgetvalue(res, tuple, field), "t")==0) + if (strcmp(PQgetvalue(res, tuple, field), "t") == 0) archprintf(fout, "true"); else archprintf(fout, "false"); @@ -1134,7 +1130,7 @@ static void dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout, const bool oids) { - PQExpBuffer copyBuf = createPQExpBuffer(); + PQExpBuffer copyBuf = createPQExpBuffer(); DataDumperPtr dumpFn; DumpContext *dumpCtx; char *copyStmt; @@ -1173,7 +1169,7 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout, appendPQExpBuffer(copyBuf, "COPY %s %s %sFROM stdin;\n", fmtId(tblinfo[i].relname), column_list, - (oids && tblinfo[i].hasoids) ? "WITH OIDS " : ""); + (oids && tblinfo[i].hasoids) ? "WITH OIDS " : ""); copyStmt = copyBuf->data; } else @@ -1184,7 +1180,7 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout, } ArchiveEntry(fout, tblinfo[i].oid, tblinfo[i].relname, - tblinfo[i].relnamespace->nspname, tblinfo[i].usename, + tblinfo[i].relnamespace->nspname, tblinfo[i].usename, "TABLE DATA", NULL, "", "", copyStmt, dumpFn, dumpCtx); } @@ -1278,7 +1274,7 @@ dumpDatabase(Archive *AH) dba, /* Owner */ "DATABASE", /* Desc */ NULL, /* Deps */ - creaQry->data, /* Create */ + creaQry->data, /* Create */ delQry->data, /* Del */ NULL, /* Copy */ NULL, /* Dumper */ @@ -1451,9 +1447,9 @@ getNamespaces(int *numNamespaces) * we read in can be linked to a containing namespace. */ appendPQExpBuffer(query, "SELECT oid, nspname, " - "(select usename from pg_user where nspowner = usesysid) as usename, " - "nspacl " - "FROM pg_namespace"); + "(select usename from pg_user where nspowner = usesysid) as usename, " + "nspacl " + "FROM pg_namespace"); res = PQexec(g_conn, query->data); if (!res || @@ -1502,7 +1498,7 @@ getNamespaces(int *numNamespaces) * getNamespaces * * NB: for pre-7.3 source database, we use object OID to guess whether it's - * a system object or not. In 7.3 and later there is no guessing. + * a system object or not. In 7.3 and later there is no guessing. */ static NamespaceInfo * findNamespace(const char *nsoid, const char *objoid) @@ -1513,7 +1509,7 @@ findNamespace(const char *nsoid, const char *objoid) { for (i = 0; i < g_numNamespaces; i++) { - NamespaceInfo *nsinfo = &g_namespaces[i]; + NamespaceInfo *nsinfo = &g_namespaces[i]; if (strcmp(nsoid, nsinfo->oid) == 0) return nsinfo; @@ -1678,8 +1674,8 @@ getOperators(int *numOprs) int i_oprcode; /* - * find all operators, including builtin operators; - * we filter out system-defined operators at dump-out time. + * find all operators, including builtin operators; we filter out + * system-defined operators at dump-out time. */ /* Make sure we are in proper schema */ @@ -1756,15 +1752,15 @@ getOpclasses(int *numOpclasses) int ntups; int i; PQExpBuffer query = createPQExpBuffer(); - OpclassInfo *opcinfo; + OpclassInfo *opcinfo; int i_oid; int i_opcname; int i_opcnamespace; int i_usename; /* - * find all opclasses, including builtin opclasses; - * we filter out system-defined opclasses at dump-out time. + * find all opclasses, including builtin opclasses; we filter out + * system-defined opclasses at dump-out time. */ /* Make sure we are in proper schema */ @@ -1864,7 +1860,7 @@ getAggregates(int *numAggs) "FROM pg_proc " "WHERE proisagg " "AND pronamespace != " - "(select oid from pg_namespace where nspname = 'pg_catalog')"); + "(select oid from pg_namespace where nspname = 'pg_catalog')"); } else { @@ -1912,7 +1908,7 @@ getAggregates(int *numAggs) agginfo[i].aggname); agginfo[i].aggacl = strdup(PQgetvalue(res, i, i_aggacl)); agginfo[i].anybasetype = false; /* computed when it's dumped */ - agginfo[i].fmtbasetype = NULL; /* computed when it's dumped */ + agginfo[i].fmtbasetype = NULL; /* computed when it's dumped */ } PQclear(res); @@ -1963,7 +1959,7 @@ getFuncs(int *numFuncs) "FROM pg_proc " "WHERE NOT proisagg " "AND pronamespace != " - "(select oid from pg_namespace where nspname = 'pg_catalog')"); + "(select oid from pg_namespace where nspname = 'pg_catalog')"); } else { @@ -2078,15 +2074,15 @@ getTables(int *numTables) /* * Find all the tables (including views and sequences). * - * We include system catalogs, so that we can work if a user table - * is defined to inherit from a system catalog (pretty weird, but...) + * We include system catalogs, so that we can work if a user table is + * defined to inherit from a system catalog (pretty weird, but...) * * We ignore tables that are not type 'r' (ordinary relation) or 'S' * (sequence) or 'v' (view). * * Note: in this phase we should collect only a minimal amount of - * information about each table, basically just enough to decide if - * it is interesting. We must fetch all tables in this phase because + * information about each table, basically just enough to decide if it + * is interesting. We must fetch all tables in this phase because * otherwise we cannot correctly identify inherited columns, serial * columns, etc. */ @@ -2108,18 +2104,18 @@ getTables(int *numTables) "from pg_class c " "left join pg_depend d on " "(c.relkind = '%c' and " - "d.classid = c.tableoid and d.objid = c.oid and " + "d.classid = c.tableoid and d.objid = c.oid and " "d.objsubid = 0 and " - "d.refclassid = c.tableoid and d.deptype = 'i') " + "d.refclassid = c.tableoid and d.deptype = 'i') " "where relkind in ('%c', '%c', '%c') " "order by c.oid", RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW); + RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW); } else if (g_fout->remoteVersion >= 70200) { appendPQExpBuffer(query, - "SELECT pg_class.oid, relname, relacl, relkind, " + "SELECT pg_class.oid, relname, relacl, relkind, " "0::oid as relnamespace, " "(select usename from pg_user where relowner = usesysid) as usename, " "relchecks, reltriggers, " @@ -2242,8 +2238,8 @@ getTables(int *numTables) /* other fields were zeroed above */ /* - * Decide whether we want to dump this table. Sequences owned - * by serial columns are never dumpable on their own; we will + * Decide whether we want to dump this table. Sequences owned by + * serial columns are never dumpable on their own; we will * transpose their owning table's dump flag to them below. */ if (tblinfo[i].owning_tab == NULL) @@ -2270,8 +2266,8 @@ getTables(int *numTables) resetPQExpBuffer(lockquery); appendPQExpBuffer(lockquery, "LOCK TABLE %s IN ACCESS SHARE MODE", - fmtQualifiedId(tblinfo[i].relnamespace->nspname, - tblinfo[i].relname)); + fmtQualifiedId(tblinfo[i].relnamespace->nspname, + tblinfo[i].relname)); lres = PQexec(g_conn, lockquery->data); if (!lres || PQresultStatus(lres) != PGRES_COMMAND_OK) { @@ -2383,7 +2379,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) for (i = 0; i < numTables; i++) { - TableInfo *tbinfo = &tblinfo[i]; + TableInfo *tbinfo = &tblinfo[i]; /* Don't bother to collect info for sequences */ if (tbinfo->relkind == RELKIND_SEQUENCE) @@ -2419,7 +2415,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) { appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, attstattarget, " "attnotnull, atthasdef, attisdropped, " - "pg_catalog.format_type(atttypid,atttypmod) as atttypname " + "pg_catalog.format_type(atttypid,atttypmod) as atttypname " "from pg_catalog.pg_attribute a " "where attrelid = '%s'::pg_catalog.oid " "and attnum > 0::pg_catalog.int2 " @@ -2430,12 +2426,12 @@ getTableAttrs(TableInfo *tblinfo, int numTables) { /* * attstattarget doesn't exist in 7.1. It does exist in 7.2, - * but we don't dump it because we can't tell whether it's been - * explicitly set or was just a default. + * but we don't dump it because we can't tell whether it's + * been explicitly set or was just a default. */ appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, -1 as attstattarget, " - "attnotnull, atthasdef, false as attisdropped, " - "format_type(atttypid,atttypmod) as atttypname " + "attnotnull, atthasdef, false as attisdropped, " + "format_type(atttypid,atttypmod) as atttypname " "from pg_attribute a " "where attrelid = '%s'::oid " "and attnum > 0::int2 " @@ -2446,7 +2442,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) { /* format_type not available before 7.1 */ appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, -1 as attstattarget, " - "attnotnull, atthasdef, false as attisdropped, " + "attnotnull, atthasdef, false as attisdropped, " "(select typname from pg_type where oid = atttypid) as atttypname " "from pg_attribute a " "where attrelid = '%s'::oid " @@ -2494,9 +2490,9 @@ getTableAttrs(TableInfo *tblinfo, int numTables) tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod)); tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, i_attstattarget)); tbinfo->attisdropped[j] = (PQgetvalue(res, j, i_attisdropped)[0] == 't'); - tbinfo->attisserial[j] = false; /* fix below */ + tbinfo->attisserial[j] = false; /* fix below */ tbinfo->notnull[j] = (PQgetvalue(res, j, i_attnotnull)[0] == 't'); - tbinfo->adef_expr[j] = NULL; /* fix below */ + tbinfo->adef_expr[j] = NULL; /* fix below */ if (PQgetvalue(res, j, i_atthasdef)[0] == 't') hasdefaults = true; /* these flags will be set in flagInhAttrs() */ @@ -2519,7 +2515,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) if (g_fout->remoteVersion >= 70300) { appendPQExpBuffer(q, "SELECT adnum, " - "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc " + "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc " "FROM pg_catalog.pg_attrdef " "WHERE adrelid = '%s'::pg_catalog.oid", tbinfo->oid); @@ -2551,7 +2547,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) numDefaults = PQntuples(res); for (j = 0; j < numDefaults; j++) { - int adnum = atoi(PQgetvalue(res, j, 0)); + int adnum = atoi(PQgetvalue(res, j, 0)); if (adnum <= 0 || adnum > ntups) { @@ -2559,16 +2555,17 @@ getTableAttrs(TableInfo *tblinfo, int numTables) adnum, tbinfo->relname); exit_nicely(); } - tbinfo->adef_expr[adnum-1] = strdup(PQgetvalue(res, j, 1)); + tbinfo->adef_expr[adnum - 1] = strdup(PQgetvalue(res, j, 1)); } PQclear(res); } /* - * Check to see if any columns are serial columns. Our first quick - * filter is that it must be integer or bigint with a default. If - * so, we scan to see if we found a sequence linked to this column. - * If we did, mark the column and sequence appropriately. + * Check to see if any columns are serial columns. Our first + * quick filter is that it must be integer or bigint with a + * default. If so, we scan to see if we found a sequence linked + * to this column. If we did, mark the column and sequence + * appropriately. */ for (j = 0; j < ntups; j++) { @@ -2584,11 +2581,11 @@ getTableAttrs(TableInfo *tblinfo, int numTables) continue; for (k = 0; k < numTables; k++) { - TableInfo *seqinfo = &tblinfo[k]; + TableInfo *seqinfo = &tblinfo[k]; if (seqinfo->owning_tab != NULL && strcmp(seqinfo->owning_tab, tbinfo->oid) == 0 && - seqinfo->owning_col == j+1) + seqinfo->owning_col == j + 1) { /* * Found a match. Copy the table's interesting and @@ -2647,7 +2644,7 @@ dumpComment(Archive *fout, const char *target, if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT description FROM pg_catalog.pg_description " - "WHERE objoid = '%s'::pg_catalog.oid and classoid = " + "WHERE objoid = '%s'::pg_catalog.oid and classoid = " "'pg_catalog.%s'::pg_catalog.regclass " "and objsubid = %d", oid, classname, subid); @@ -2731,7 +2728,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT description, objsubid FROM pg_catalog.pg_description " - "WHERE objoid = '%s'::pg_catalog.oid and classoid = " + "WHERE objoid = '%s'::pg_catalog.oid and classoid = " "'pg_catalog.pg_class'::pg_catalog.regclass " "ORDER BY objoid, classoid, objsubid", tbinfo->oid); @@ -2740,7 +2737,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, { appendPQExpBuffer(query, "SELECT description, objsubid FROM pg_description " "WHERE objoid = '%s'::oid and classoid = " - "(SELECT oid FROM pg_class where relname = 'pg_class') " + "(SELECT oid FROM pg_class where relname = 'pg_class') " "ORDER BY objoid, classoid, objsubid", tbinfo->oid); } @@ -2768,7 +2765,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, for (i = 0; i < ntups; i++) { const char *descr = PQgetvalue(res, i, i_description); - int objsubid = atoi(PQgetvalue(res, i, i_objsubid)); + int objsubid = atoi(PQgetvalue(res, i, i_objsubid)); if (objsubid == 0) { @@ -2792,7 +2789,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, appendPQExpBuffer(target, "COLUMN %s.", fmtId(tbinfo->relname)); appendPQExpBuffer(target, "%s", - fmtId(tbinfo->attnames[objsubid-1])); + fmtId(tbinfo->attnames[objsubid - 1])); resetPQExpBuffer(query); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); @@ -2860,7 +2857,7 @@ dumpDBComment(Archive *fout) /* * dumpNamespaces - * writes out to fout the queries to recreate user-defined namespaces + * writes out to fout the queries to recreate user-defined namespaces */ void dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces) @@ -2885,10 +2882,10 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces) qnspname = strdup(fmtId(nspinfo->nspname)); /* - * If it's the PUBLIC namespace, don't emit a CREATE SCHEMA - * record for it, since we expect PUBLIC to exist already in - * the destination database. And emit ACL info only if the ACL - * isn't the standard value for PUBLIC. + * If it's the PUBLIC namespace, don't emit a CREATE SCHEMA record + * for it, since we expect PUBLIC to exist already in the + * destination database. And emit ACL info only if the ACL isn't + * the standard value for PUBLIC. */ if (strcmp(nspinfo->nspname, "public") == 0) { @@ -2933,8 +2930,8 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces) /* * dumpOneBaseType - * writes out to fout the queries to recreate a user-defined base type - * as requested by dumpTypes + * writes out to fout the queries to recreate a user-defined base type + * as requested by dumpTypes */ static void dumpOneBaseType(Archive *fout, TypeInfo *tinfo, @@ -3038,7 +3035,7 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo, /* * Before we create a type, we need to create the input and output * functions for it, if they haven't been created already. So make - * sure there are dependency entries for this. But don't include + * sure there are dependency entries for this. But don't include * dependencies if the functions aren't going to be dumped. */ funcInd = findFuncByOid(g_finfo, numFuncs, typinputoid); @@ -3049,7 +3046,10 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo, if (funcInd >= 0 && g_finfo[funcInd].pronamespace->dump) (*deps)[depIdx++] = strdup(typoutputoid); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delq, "DROP TYPE %s.", fmtId(tinfo->typnamespace->nspname)); appendPQExpBuffer(delq, "%s CASCADE;\n", @@ -3120,7 +3120,7 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo, appendPQExpBuffer(q, "\n);\n"); - (*deps)[depIdx++] = NULL; /* End of List */ + (*deps)[depIdx++] = NULL; /* End of List */ ArchiveEntry(fout, tinfo->oid, tinfo->typname, tinfo->typnamespace->nspname, @@ -3143,8 +3143,8 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo, /* * dumpOneDomain - * writes out to fout the queries to recreate a user-defined domain - * as requested by dumpTypes + * writes out to fout the queries to recreate a user-defined domain + * as requested by dumpTypes */ static void dumpOneDomain(Archive *fout, TypeInfo *tinfo) @@ -3169,7 +3169,7 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo) /* Fetch domain specific details */ /* We assume here that remoteVersion must be at least 70300 */ appendPQExpBuffer(query, "SELECT typnotnull, " - "pg_catalog.format_type(typbasetype, typtypmod) as typdefn, " + "pg_catalog.format_type(typbasetype, typtypmod) as typdefn, " "typdefault, typbasetype " "FROM pg_catalog.pg_type " "WHERE oid = '%s'::pg_catalog.oid", @@ -3200,7 +3200,10 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo) typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault")); typbasetype = PQgetvalue(res, 0, PQfnumber(res, "typbasetype")); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delq, "DROP DOMAIN %s.", fmtId(tinfo->typnamespace->nspname)); appendPQExpBuffer(delq, "%s;\n", @@ -3222,7 +3225,7 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo) appendPQExpBuffer(q, ";\n"); - (*deps)[depIdx++] = NULL; /* End of List */ + (*deps)[depIdx++] = NULL; /* End of List */ ArchiveEntry(fout, tinfo->oid, tinfo->typname, tinfo->typnamespace->nspname, @@ -3245,8 +3248,8 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo) /* * dumpOneCompositeType - * writes out to fout the queries to recreate a user-defined stand-alone - * composite type as requested by dumpTypes + * writes out to fout the queries to recreate a user-defined stand-alone + * composite type as requested by dumpTypes */ static void dumpOneCompositeType(Archive *fout, TypeInfo *tinfo) @@ -3256,8 +3259,8 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo) PQExpBuffer query = createPQExpBuffer(); PGresult *res; int ntups; - int i_attname; - int i_atttypdefn; + int i_attname; + int i_atttypdefn; int i; /* Set proper schema search path so type references list correctly */ @@ -3267,8 +3270,8 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo) /* We assume here that remoteVersion must be at least 70300 */ appendPQExpBuffer(query, "SELECT a.attname, " - "pg_catalog.format_type(a.atttypid, a.atttypmod) as atttypdefn " - "FROM pg_catalog.pg_type t, pg_catalog.pg_attribute a " + "pg_catalog.format_type(a.atttypid, a.atttypmod) as atttypdefn " + "FROM pg_catalog.pg_type t, pg_catalog.pg_attribute a " "WHERE t.oid = '%s'::pg_catalog.oid " "AND a.attrelid = t.typrelid " "AND NOT a.attisdropped " @@ -3311,7 +3314,10 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo) } appendPQExpBuffer(q, ");\n"); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delq, "DROP TYPE %s.", fmtId(tinfo->typnamespace->nspname)); appendPQExpBuffer(delq, "%s;\n", @@ -3468,11 +3474,11 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs) /* * Current theory is to dump PLs iff their underlying functions - * will be dumped (are in a dumpable namespace, or have a non-system - * OID in pre-7.3 databases). Actually, we treat the PL itself - * as being in the underlying function's namespace, though it - * isn't really. This avoids searchpath problems for the HANDLER - * clause. + * will be dumped (are in a dumpable namespace, or have a + * non-system OID in pre-7.3 databases). Actually, we treat the + * PL itself as being in the underlying function's namespace, + * though it isn't really. This avoids searchpath problems for + * the HANDLER clause. */ if (!finfo[fidx].pronamespace->dump) continue; @@ -3481,7 +3487,7 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs) resetPQExpBuffer(delqry); /* Make a dependency to ensure function is dumped first */ - deps = malloc(sizeof(char *) * (2 + (strcmp(lanvalidator, "0")!=0) ? 1 : 0)); + deps = malloc(sizeof(char *) * (2 + (strcmp(lanvalidator, "0") != 0) ? 1 : 0)); depIdx = 0; (*deps)[depIdx++] = strdup(lanplcallfoid); @@ -3495,13 +3501,13 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs) fmtId(lanname)); appendPQExpBuffer(defqry, " HANDLER %s", fmtId(finfo[fidx].proname)); - if (strcmp(lanvalidator, "0")!=0) + if (strcmp(lanvalidator, "0") != 0) { appendPQExpBuffer(defqry, " VALIDATOR "); /* Cope with possibility that validator is in different schema */ if (finfo[vidx].pronamespace != finfo[fidx].pronamespace) appendPQExpBuffer(defqry, "%s.", - fmtId(finfo[vidx].pronamespace->nspname)); + fmtId(finfo[vidx].pronamespace->nspname)); appendPQExpBuffer(defqry, "%s", fmtId(finfo[vidx].proname)); (*deps)[depIdx++] = strdup(lanvalidator); @@ -3517,7 +3523,8 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs) if (!aclsSkip) { - char *tmp = strdup(fmtId(lanname)); + char *tmp = strdup(fmtId(lanname)); + dumpACL(fout, "LANGUAGE", tmp, lanname, finfo[fidx].pronamespace->nspname, NULL, lanacl, lanoid); @@ -3588,7 +3595,8 @@ format_function_signature(FuncInfo *finfo, bool honor_quotes) static void dumpFuncACL(Archive *fout, FuncInfo *finfo) { - char *funcsig, *funcsig_tag; + char *funcsig, + *funcsig_tag; funcsig = format_function_signature(finfo, true); funcsig_tag = format_function_signature(finfo, false); @@ -3647,7 +3655,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo) { appendPQExpBuffer(query, "SELECT proretset, prosrc, probin, " - "case when proiscachable then 'i' else 'v' end as provolatile, " + "case when proiscachable then 'i' else 'v' end as provolatile, " "proisstrict, " "'f'::boolean as prosecdef, " "(SELECT lanname FROM pg_language WHERE oid = prolang) as lanname " @@ -3659,7 +3667,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo) { appendPQExpBuffer(query, "SELECT proretset, prosrc, probin, " - "case when proiscachable then 'i' else 'v' end as provolatile, " + "case when proiscachable then 'i' else 'v' end as provolatile, " "'f'::boolean as proisstrict, " "'f'::boolean as prosecdef, " "(SELECT lanname FROM pg_language WHERE oid = prolang) as lanname " @@ -3720,7 +3728,10 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo) funcsig = format_function_signature(finfo, true); funcsig_tag = format_function_signature(finfo, false); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delqry, "DROP FUNCTION %s.%s;\n", fmtId(finfo->pronamespace->nspname), funcsig); @@ -3818,21 +3829,21 @@ dumpCasts(Archive *fout, for (i = 0; i < ntups; i++) { - char * castoid = PQgetvalue(res, i, 0); - char * castsource = PQgetvalue(res, i, 1); - char * casttarget = PQgetvalue(res, i, 2); - char * castfunc = PQgetvalue(res, i, 3); - char * castimplicit = PQgetvalue(res, i, 4); - int fidx = -1; + char *castoid = PQgetvalue(res, i, 0); + char *castsource = PQgetvalue(res, i, 1); + char *casttarget = PQgetvalue(res, i, 2); + char *castfunc = PQgetvalue(res, i, 3); + char *castimplicit = PQgetvalue(res, i, 4); + int fidx = -1; const char *((*deps)[]); if (strcmp(castfunc, "0") != 0) fidx = findFuncByOid(finfo, numFuncs, castfunc); /* - * We treat the cast as being in the namespace of the - * underlying function. This doesn't handle binary compatible - * casts. Where should those go? + * We treat the cast as being in the namespace of the underlying + * function. This doesn't handle binary compatible casts. Where + * should those go? */ if (fidx < 0 || !finfo[fidx].pronamespace->dump) continue; @@ -3859,13 +3870,13 @@ dumpCasts(Archive *fout, getFormattedTypeName(castsource, zeroAsNone), getFormattedTypeName(casttarget, zeroAsNone)); - if (strcmp(castfunc, "0")==0) + if (strcmp(castfunc, "0") == 0) appendPQExpBuffer(defqry, "WITHOUT FUNCTION"); else appendPQExpBuffer(defqry, "WITH FUNCTION %s", - format_function_signature(&finfo[fidx], true)); + format_function_signature(&finfo[fidx], true)); - if (strcmp(castimplicit, "t")==0) + if (strcmp(castimplicit, "t") == 0) appendPQExpBuffer(defqry, " AS ASSIGNMENT"); appendPQExpBuffer(defqry, ";\n"); @@ -3982,9 +3993,9 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo, { appendPQExpBuffer(query, "SELECT oprkind, oprcode, " "CASE WHEN oprleft = 0 THEN '-' " - "ELSE format_type(oprleft, NULL) END as oprleft, " + "ELSE format_type(oprleft, NULL) END as oprleft, " "CASE WHEN oprright = 0 THEN '-' " - "ELSE format_type(oprright, NULL) END as oprright, " + "ELSE format_type(oprright, NULL) END as oprright, " "oprcom, oprnegate, oprrest, oprjoin, " "oprcanhash, oprlsortop, oprrsortop, " "0 as oprltcmpop, 0 as oprgtcmpop " @@ -4059,8 +4070,8 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo, oprinfo->oprname); /* - * right unary means there's a left arg and left unary means - * there's a right arg + * right unary means there's a left arg and left unary means there's a + * right arg */ if (strcmp(oprkind, "r") == 0 || strcmp(oprkind, "b") == 0) @@ -4123,7 +4134,10 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo, if (name) appendPQExpBuffer(details, ",\n GTCMP = %s", name); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delq, "DROP OPERATOR %s.%s;\n", fmtId(oprinfo->oprnamespace->nspname), oprid->data); @@ -4171,9 +4185,9 @@ convertRegProcReference(const char *proc) if (g_fout->remoteVersion >= 70300) { - char *name; - char *paren; - bool inquote; + char *name; + char *paren; + bool inquote; name = strdup(proc); /* find non-double-quoted left paren */ @@ -4208,7 +4222,7 @@ static const char * convertOperatorReference(const char *opr, OprInfo *g_oprinfo, int numOperators) { - char *name; + char *name; /* In all cases "0" means a null reference */ if (strcmp(opr, "0") == 0) @@ -4216,8 +4230,8 @@ convertOperatorReference(const char *opr, if (g_fout->remoteVersion >= 70300) { - char *paren; - bool inquote; + char *paren; + bool inquote; name = strdup(opr); /* find non-double-quoted left paren */ @@ -4312,7 +4326,7 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo) appendPQExpBuffer(query, "SELECT opcintype::pg_catalog.regtype, " "opckeytype::pg_catalog.regtype, " "opcdefault, " - "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opcamid) AS amname " + "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opcamid) AS amname " "FROM pg_catalog.pg_opclass " "WHERE oid = '%s'::pg_catalog.oid", opcinfo->oid); @@ -4344,7 +4358,10 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo) opcdefault = PQgetvalue(res, 0, i_opcdefault); amname = PQgetvalue(res, 0, i_amname); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delq, "DROP OPERATOR CLASS %s", fmtId(opcinfo->opcnamespace->nspname)); appendPQExpBuffer(delq, ".%s", @@ -4508,7 +4525,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes) initPQExpBuffer(&buf); if (honor_quotes) appendPQExpBuffer(&buf, "%s", - fmtId(agginfo->aggname)); + fmtId(agginfo->aggname)); else appendPQExpBuffer(&buf, "%s", agginfo->aggname); @@ -4536,7 +4553,8 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes) static void dumpAggACL(Archive *fout, AggInfo *finfo) { - char *aggsig, *aggsig_tag; + char *aggsig, + *aggsig_tag; aggsig = format_aggregate_signature(finfo, fout, true); aggsig_tag = format_aggregate_signature(finfo, fout, false); @@ -4586,9 +4604,9 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo) "aggfinalfn, aggtranstype::pg_catalog.regtype, " "agginitval, " "proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype as anybasetype, " - "proargtypes[0]::pg_catalog.regtype as fmtbasetype, " + "proargtypes[0]::pg_catalog.regtype as fmtbasetype, " "'t'::boolean as convertok " - "from pg_catalog.pg_aggregate a, pg_catalog.pg_proc p " + "from pg_catalog.pg_aggregate a, pg_catalog.pg_proc p " "where a.aggfnoid = p.oid " "and p.oid = '%s'::pg_catalog.oid", agginfo->oid); @@ -4596,11 +4614,11 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo) else if (g_fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT aggtransfn, aggfinalfn, " - "format_type(aggtranstype, NULL) as aggtranstype, " + "format_type(aggtranstype, NULL) as aggtranstype, " "agginitval, " "aggbasetype = 0 as anybasetype, " "CASE WHEN aggbasetype = 0 THEN '-' " - "ELSE format_type(aggbasetype, NULL) END as fmtbasetype, " + "ELSE format_type(aggbasetype, NULL) END as fmtbasetype, " "'t'::boolean as convertok " "from pg_aggregate " "where oid = '%s'::oid", @@ -4657,7 +4675,7 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo) convertok = (PQgetvalue(res, 0, i_convertok)[0] == 't'); aggsig = format_aggregate_signature(agginfo, g_fout, true); - aggsig_tag = format_aggregate_signature(agginfo, g_fout, false); + aggsig_tag = format_aggregate_signature(agginfo, g_fout, false); if (!convertok) { @@ -4716,7 +4734,10 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo) aggfinalfn); } - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n", fmtId(agginfo->aggnamespace->nspname), aggsig); @@ -4793,7 +4814,7 @@ GetPrivileges(Archive *AH, const char *s, const char *type) else \ all = false - if (strcmp(type, "TABLE")==0) + if (strcmp(type, "TABLE") == 0) { CONVERT_PRIV('a', "INSERT"); CONVERT_PRIV('r', "SELECT"); @@ -4812,15 +4833,11 @@ GetPrivileges(Archive *AH, const char *s, const char *type) CONVERT_PRIV('w', "UPDATE,DELETE"); } } - else if (strcmp(type, "FUNCTION")==0) - { + else if (strcmp(type, "FUNCTION") == 0) CONVERT_PRIV('X', "EXECUTE"); - } - else if (strcmp(type, "LANGUAGE")==0) - { + else if (strcmp(type, "LANGUAGE") == 0) CONVERT_PRIV('U', "USAGE"); - } - else if (strcmp(type, "SCHEMA")==0) + else if (strcmp(type, "SCHEMA") == 0) { CONVERT_PRIV('C', "CREATE"); CONVERT_PRIV('U', "USAGE"); @@ -4953,7 +4970,8 @@ dumpACL(Archive *fout, const char *type, const char *name, } /* - * If we didn't find any owner privs, the owner must have revoked 'em all + * If we didn't find any owner privs, the owner must have revoked 'em + * all */ if (!found_owner_privs && usename) { @@ -4973,8 +4991,8 @@ dumpACL(Archive *fout, const char *type, const char *name, static void dumpTableACL(Archive *fout, TableInfo *tbinfo) { - char *namecopy = strdup(fmtId(tbinfo->relname)); - char *dumpoid; + char *namecopy = strdup(fmtId(tbinfo->relname)); + char *dumpoid; /* * Choose OID to use for sorting ACL into position. For a view, sort @@ -4989,7 +5007,7 @@ dumpTableACL(Archive *fout, TableInfo *tbinfo) dumpoid = tbinfo->oid; dumpACL(fout, "TABLE", namecopy, tbinfo->relname, - tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relacl, + tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relacl, dumpoid); free(namecopy); @@ -5002,7 +5020,7 @@ dumpTableACL(Archive *fout, TableInfo *tbinfo) */ void dumpTables(Archive *fout, TableInfo tblinfo[], int numTables, - const bool aclsSkip, const bool schemaOnly, const bool dataOnly) + const bool aclsSkip, const bool schemaOnly, const bool dataOnly) { int i; @@ -5012,7 +5030,7 @@ dumpTables(Archive *fout, TableInfo tblinfo[], int numTables, */ for (i = 0; i < numTables; i++) { - TableInfo *tbinfo = &tblinfo[i]; + TableInfo *tbinfo = &tblinfo[i]; if (tbinfo->relkind != RELKIND_SEQUENCE) continue; @@ -5029,9 +5047,9 @@ dumpTables(Archive *fout, TableInfo tblinfo[], int numTables, { for (i = 0; i < numTables; i++) { - TableInfo *tbinfo = &tblinfo[i]; + TableInfo *tbinfo = &tblinfo[i]; - if (tbinfo->relkind == RELKIND_SEQUENCE) /* already dumped */ + if (tbinfo->relkind == RELKIND_SEQUENCE) /* already dumped */ continue; if (tbinfo->dump) @@ -5049,7 +5067,7 @@ dumpTables(Archive *fout, TableInfo tblinfo[], int numTables, */ for (i = 0; i < numTables; i++) { - TableInfo *tbinfo = &tblinfo[i]; + TableInfo *tbinfo = &tblinfo[i]; if (tbinfo->relkind != RELKIND_SEQUENCE) continue; @@ -5108,7 +5126,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) { appendPQExpBuffer(query, "SELECT definition as viewdef, " "(select oid from pg_rewrite where " - " rulename=('_RET' || viewname)::name) as view_oid" + " rulename=('_RET' || viewname)::name) as view_oid" " from pg_views where viewname = "); appendStringLiteral(query, tbinfo->relname, true); appendPQExpBuffer(query, ";"); @@ -5154,7 +5172,10 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) /* Save it for use by dumpACL, too */ tbinfo->viewoid = objoid; - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delq, "DROP VIEW %s.", fmtId(tbinfo->relnamespace->nspname)); appendPQExpBuffer(delq, "%s;\n", @@ -5167,8 +5188,8 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) /* * Views can have default values -- however, they must be - * specified in an ALTER TABLE command after the view has - * been created, not in the view definition itself. + * specified in an ALTER TABLE command after the view has been + * created, not in the view definition itself. */ for (j = 0; j < tbinfo->numatts; j++) { @@ -5194,7 +5215,10 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) numParents = tbinfo->numParents; parentIndexes = tbinfo->parentIndexes; - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delq, "DROP TABLE %s.", fmtId(tbinfo->relnamespace->nspname)); appendPQExpBuffer(delq, "%s;\n", @@ -5220,7 +5244,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) /* Attribute type */ if (g_fout->remoteVersion >= 70100) { - char *typname = tbinfo->atttypnames[j]; + char *typname = tbinfo->atttypnames[j]; if (tbinfo->attisserial[j]) { @@ -5263,10 +5287,10 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) } /* - * Add non-inherited CHECK constraints, if any. If a - * constraint matches by name and condition with a constraint - * belonging to a parent class (OR conditions match and both names - * start with '$'), we assume it was inherited. + * Add non-inherited CHECK constraints, if any. If a constraint + * matches by name and condition with a constraint belonging to a + * parent class (OR conditions match and both names start with + * '$'), we assume it was inherited. */ if (tbinfo->ncheck > 0) { @@ -5283,7 +5307,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) if (g_fout->remoteVersion >= 70300) appendPQExpBuffer(query, "SELECT conname, consrc" " from pg_catalog.pg_constraint c1" - " where conrelid = '%s'::pg_catalog.oid " + " where conrelid = '%s'::pg_catalog.oid " " and contype = 'c' " " and not exists " " (select 1 from " @@ -5350,13 +5374,13 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) } /* - * Primary Key: In versions of PostgreSQL prior to 7.2, we - * needed to include the primary key in the table definition. - * However, this is not ideal because it creates an index - * on the table, which makes COPY slower. As of release 7.2, - * we can add primary keys to a table after it has been created, - * using ALTER TABLE; see dumpIndexes() for more information. - * Therefore, we ignore primary keys in this function. + * Primary Key: In versions of PostgreSQL prior to 7.2, we needed + * to include the primary key in the table definition. However, + * this is not ideal because it creates an index on the table, + * which makes COPY slower. As of release 7.2, we can add primary + * keys to a table after it has been created, using ALTER TABLE; + * see dumpIndexes() for more information. Therefore, we ignore + * primary keys in this function. */ appendPQExpBuffer(q, "\n)"); @@ -5372,7 +5396,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) appendPQExpBuffer(q, ", "); if (parentRel->relnamespace != tbinfo->relnamespace) appendPQExpBuffer(q, "%s.", - fmtId(parentRel->relnamespace->nspname)); + fmtId(parentRel->relnamespace->nspname)); appendPQExpBuffer(q, "%s", fmtId(parentRel->relname)); } @@ -5385,11 +5409,11 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) appendPQExpBuffer(q, ";\n"); /* - * Dump per-column statistics information. We only issue an ALTER TABLE - * statement if the attstattarget entry for this column is non-negative - * (i.e. it's not the default value) + * Dump per-column statistics information. We only issue an ALTER + * TABLE statement if the attstattarget entry for this column is + * non-negative (i.e. it's not the default value) */ - for (j = 0; j < tbinfo->numatts; j++) + for (j = 0; j < tbinfo->numatts; j++) { if (tbinfo->attstattarget[j] >= 0 && !tbinfo->attisdropped[j]) @@ -5415,9 +5439,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) if (commentDeps) { for (j = 0; (*commentDeps)[j] != NULL; j++) - { free((void *) (*commentDeps)[j]); - } free(commentDeps); } @@ -5497,23 +5519,23 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) selectSourceSchema(tbinfo->relnamespace->nspname); /* - * The point of the messy-looking outer join is to find a constraint - * that is related by an internal dependency link to the index. - * If we find one, we emit an ADD CONSTRAINT command instead of - * a CREATE INDEX command. We assume an index won't have more than - * one internal dependency. + * The point of the messy-looking outer join is to find a + * constraint that is related by an internal dependency link to + * the index. If we find one, we emit an ADD CONSTRAINT command + * instead of a CREATE INDEX command. We assume an index won't + * have more than one internal dependency. */ resetPQExpBuffer(query); if (g_fout->remoteVersion >= 70300) appendPQExpBuffer(query, "SELECT i.indexrelid as indexreloid, " - "coalesce(c.conname, t.relname) as indexrelname, " - "pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, " + "coalesce(c.conname, t.relname) as indexrelname, " + "pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, " "i.indkey, " "t.relnatts as indnkeys, " - "coalesce(c.contype, '0') as contype " + "coalesce(c.contype, '0') as contype " "FROM pg_catalog.pg_index i " - "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " + "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " "LEFT JOIN pg_catalog.pg_depend d " "ON (d.classid = t.tableoid " "AND d.objid = t.oid " @@ -5528,7 +5550,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBuffer(query, "SELECT i.indexrelid as indexreloid, " "t.relname as indexrelname, " - "pg_get_indexdef(i.indexrelid) as indexdef, " + "pg_get_indexdef(i.indexrelid) as indexdef, " "i.indkey, " "t.relnatts as indnkeys, " "CASE WHEN i.indisprimary THEN 'p'::char " @@ -5561,7 +5583,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) const char *indexreloid = PQgetvalue(res, j, i_indexreloid); const char *indexrelname = PQgetvalue(res, j, i_indexrelname); const char *indexdef = PQgetvalue(res, j, i_indexdef); - char contype = *(PQgetvalue(res, j, i_contype)); + char contype = *(PQgetvalue(res, j, i_contype)); resetPQExpBuffer(q); resetPQExpBuffer(delq); @@ -5569,14 +5591,14 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) if (contype == 'p' || contype == 'u') { /* - * If we found a constraint matching the index, emit - * ADD CONSTRAINT not CREATE INDEX. + * If we found a constraint matching the index, emit ADD + * CONSTRAINT not CREATE INDEX. * - * In a pre-7.3 database, we take this path iff the index - * was marked indisprimary. + * In a pre-7.3 database, we take this path iff the index was + * marked indisprimary. */ - int indnkeys = atoi(PQgetvalue(res, j, i_indnkeys)); - char **indkeys = (char **) malloc(indnkeys * sizeof(char *)); + int indnkeys = atoi(PQgetvalue(res, j, i_indnkeys)); + char **indkeys = (char **) malloc(indnkeys * sizeof(char *)); int k; parseNumericArray(PQgetvalue(res, j, i_indkey), @@ -5586,7 +5608,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) fmtId(tbinfo->relname)); appendPQExpBuffer(q, " ADD CONSTRAINT %s %s (", fmtId(indexrelname), - contype == 'p' ? "PRIMARY KEY" : "UNIQUE"); + contype == 'p' ? "PRIMARY KEY" : "UNIQUE"); for (k = 0; k < indnkeys; k++) { @@ -5604,7 +5626,10 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) appendPQExpBuffer(q, ");\n"); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears + * in pg_catalog + */ appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.", fmtId(tbinfo->relnamespace->nspname)); appendPQExpBuffer(delq, "%s ", @@ -5629,7 +5654,10 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) /* Plain secondary index */ appendPQExpBuffer(q, "%s;\n", indexdef); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears + * in pg_catalog + */ appendPQExpBuffer(delq, "DROP INDEX %s.", fmtId(tbinfo->relnamespace->nspname)); appendPQExpBuffer(delq, "%s;\n", @@ -5870,7 +5898,10 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo, { resetPQExpBuffer(delqry); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delqry, "DROP SEQUENCE %s.", fmtId(tbinfo->relnamespace->nspname)); appendPQExpBuffer(delqry, "%s;\n", @@ -5878,8 +5909,8 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo, resetPQExpBuffer(query); appendPQExpBuffer(query, - "CREATE SEQUENCE %s\n START %s\n INCREMENT %s\n" - " MAXVALUE %s\n MINVALUE %s\n CACHE %s%s;\n", + "CREATE SEQUENCE %s\n START %s\n INCREMENT %s\n" + " MAXVALUE %s\n MINVALUE %s\n CACHE %s%s;\n", fmtId(tbinfo->relname), (called ? minv : last), incby, maxv, minv, cache, @@ -5955,7 +5986,7 @@ dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables) for (i = 0; i < numTables; i++) { - TableInfo *tbinfo = &tblinfo[i]; + TableInfo *tbinfo = &tblinfo[i]; if (tbinfo->ntrig == 0 || !tbinfo->dump) continue; @@ -5964,13 +5995,16 @@ dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables) write_msg(NULL, "dumping foreign key constraints for table %s\n", tbinfo->relname); - /* select table schema to ensure regproc name is qualified if needed */ + /* + * select table schema to ensure regproc name is qualified if + * needed + */ selectSourceSchema(tbinfo->relnamespace->nspname); resetPQExpBuffer(query); appendPQExpBuffer(query, "SELECT oid, conname, " - "pg_catalog.pg_get_constraintdef(oid) as condef " + "pg_catalog.pg_get_constraintdef(oid) as condef " "FROM pg_catalog.pg_constraint " "WHERE conrelid = '%s'::pg_catalog.oid " "AND contype = 'f'", @@ -5987,7 +6021,7 @@ dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables) i_conoid = PQfnumber(res, "oid"); i_conname = PQfnumber(res, "conname"); i_condef = PQfnumber(res, "condef"); - + for (j = 0; j < ntups; j++) { const char *conOid = PQgetvalue(res, j, i_conoid); @@ -6001,7 +6035,10 @@ dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables) fmtId(conName), conDef); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ resetPQExpBuffer(delqry); appendPQExpBuffer(delqry, "ALTER TABLE ONLY %s.", fmtId(tbinfo->relnamespace->nspname)); @@ -6060,7 +6097,7 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) for (i = 0; i < numTables; i++) { - TableInfo *tbinfo = &tblinfo[i]; + TableInfo *tbinfo = &tblinfo[i]; if (tbinfo->ntrig == 0 || !tbinfo->dump) continue; @@ -6069,20 +6106,26 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) write_msg(NULL, "dumping triggers for table %s\n", tbinfo->relname); - /* select table schema to ensure regproc name is qualified if needed */ + /* + * select table schema to ensure regproc name is qualified if + * needed + */ selectSourceSchema(tbinfo->relnamespace->nspname); resetPQExpBuffer(query); if (g_fout->remoteVersion >= 70300) { - /* We ignore triggers that are tied to a foreign-key constraint */ + /* + * We ignore triggers that are tied to a foreign-key + * constraint + */ appendPQExpBuffer(query, "SELECT tgname, " "tgfoid::pg_catalog.regproc as tgfname, " "tgtype, tgnargs, tgargs, " - "tgisconstraint, tgconstrname, tgdeferrable, " + "tgisconstraint, tgconstrname, tgdeferrable, " "tgconstrrelid, tginitdeferred, oid, " - "tgconstrrelid::pg_catalog.regclass as tgconstrrelname " + "tgconstrrelid::pg_catalog.regclass as tgconstrrelname " "from pg_catalog.pg_trigger t " "where tgrelid = '%s'::pg_catalog.oid " "and (not tgisconstraint " @@ -6095,11 +6138,11 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) else { appendPQExpBuffer(query, - "SELECT tgname, tgfoid::regproc as tgfname, " + "SELECT tgname, tgfoid::regproc as tgfname, " "tgtype, tgnargs, tgargs, " - "tgisconstraint, tgconstrname, tgdeferrable, " + "tgisconstraint, tgconstrname, tgdeferrable, " "tgconstrrelid, tginitdeferred, oid, " - "(select relname from pg_class where oid = tgconstrrelid) " + "(select relname from pg_class where oid = tgconstrrelid) " " as tgconstrrelname " "from pg_trigger " "where tgrelid = '%s'::oid", @@ -6113,9 +6156,10 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) exit_nicely(); } ntups = PQntuples(res); + /* - * We may have less triggers than recorded due to constraint triggers - * which are dumped by dumpConstraints + * We may have less triggers than recorded due to constraint + * triggers which are dumped by dumpConstraints */ if (ntups > tbinfo->ntrig) { @@ -6167,7 +6211,11 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) tginitdeferred = 1; resetPQExpBuffer(delqry); - /* DROP must be fully qualified in case same name appears in pg_catalog */ + + /* + * DROP must be fully qualified in case same name appears in + * pg_catalog + */ appendPQExpBuffer(delqry, "DROP TRIGGER %s ", fmtId(tgname)); appendPQExpBuffer(delqry, "ON %s.", @@ -6233,10 +6281,10 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) /* If we are using regclass, name is already quoted */ if (g_fout->remoteVersion >= 70300) appendPQExpBuffer(query, " FROM %s\n ", - PQgetvalue(res, j, i_tgconstrrelname)); + PQgetvalue(res, j, i_tgconstrrelname)); else appendPQExpBuffer(query, " FROM %s\n ", - fmtId(PQgetvalue(res, j, i_tgconstrrelname))); + fmtId(PQgetvalue(res, j, i_tgconstrrelname))); } if (!tgdeferrable) appendPQExpBuffer(query, "NOT "); @@ -6342,7 +6390,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) */ for (t = 0; t < numTables; t++) { - TableInfo *tbinfo = &tblinfo[t]; + TableInfo *tbinfo = &tblinfo[t]; if (!tbinfo->hasrules || !tbinfo->dump) continue; @@ -6358,7 +6406,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) if (g_fout->remoteVersion >= 70300) { appendPQExpBuffer(query, - "SELECT pg_catalog.pg_get_ruledef(oid) AS definition," + "SELECT pg_catalog.pg_get_ruledef(oid) AS definition," " oid, rulename " "FROM pg_catalog.pg_rewrite " "WHERE ev_class = '%s'::pg_catalog.oid " @@ -6369,8 +6417,8 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) else { /* - * We include pg_rules in the cross since it filters out all view - * rules (pjw 15-Sep-2000). + * We include pg_rules in the cross since it filters out all + * view rules (pjw 15-Sep-2000). */ appendPQExpBuffer(query, "SELECT definition," " pg_rewrite.oid, pg_rewrite.rulename " @@ -6378,9 +6426,9 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) "WHERE pg_class.relname = "); appendStringLiteral(query, tbinfo->relname, true); appendPQExpBuffer(query, - " AND pg_rewrite.ev_class = pg_class.oid " - " AND pg_rules.tablename = pg_class.relname " - " AND pg_rules.rulename = pg_rewrite.rulename " + " AND pg_rewrite.ev_class = pg_class.oid " + " AND pg_rules.tablename = pg_class.relname " + " AND pg_rules.rulename = pg_rewrite.rulename " "ORDER BY pg_rewrite.oid"); } @@ -6448,7 +6496,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) static void selectSourceSchema(const char *schemaName) { - static char *curSchemaName = NULL; + static char *curSchemaName = NULL; PQExpBuffer query; PGresult *res; @@ -6606,11 +6654,12 @@ myFormatType(const char *typname, int32 typmod) precision, scale); } } + /* * char is an internal single-byte data type; Let's make sure we force * it through with quotes. - thomas 1998-12-13 */ - else if (strcmp(typname, "char")==0) + else if (strcmp(typname, "char") == 0) appendPQExpBuffer(buf, "\"char\""); else appendPQExpBuffer(buf, "%s", fmtId(typname)); @@ -6657,12 +6706,12 @@ fmtCopyColumnList(const TableInfo *ti) { static PQExpBuffer q = NULL; int numatts = ti->numatts; - char** attnames = ti->attnames; - bool* attisdropped = ti->attisdropped; - bool needComma; - int i; + char **attnames = ti->attnames; + bool *attisdropped = ti->attisdropped; + bool needComma; + int i; - if (q) /* first time through? */ + if (q) /* first time through? */ resetPQExpBuffer(q); else q = createPQExpBuffer(); diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index d89a06c186..d7e214c972 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pg_dump.h,v 1.98 2002/08/22 00:01:46 tgl Exp $ + * $Id: pg_dump.h,v 1.99 2002/09/04 20:31:35 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -21,10 +21,10 @@ * * NOTE: the structures described here live for the entire pg_dump run; * and in most cases we make a struct for every object we can find in the - * catalogs, not only those we are actually going to dump. Hence, it's + * catalogs, not only those we are actually going to dump. Hence, it's * best to store a minimal amount of per-object info in these structs, * and retrieve additional per-object info when and if we dump a specific - * object. In particular, try to avoid retrieving expensive-to-compute + * object. In particular, try to avoid retrieving expensive-to-compute * information until it's known to be needed. */ @@ -60,7 +60,7 @@ typedef struct _funcInfo char *usename; /* name of owner, or empty string */ Oid lang; int nargs; - char **argtypes; /* OIDs */ + char **argtypes; /* OIDs */ char *prorettype; /* OID */ char *proacl; bool dumped; /* true if already dumped */ @@ -119,8 +119,9 @@ typedef struct _tableInfo bool dump; /* true if we want to dump it */ /* - * These fields are computed only if we decide the table is interesting - * (it's either a table to dump, or a direct parent of a dumpable table). + * These fields are computed only if we decide the table is + * interesting (it's either a table to dump, or a direct parent of a + * dumpable table). */ int numatts; /* number of attributes */ char **attnames; /* the attribute names */ @@ -129,6 +130,7 @@ typedef struct _tableInfo int *attstattarget; /* attribute statistics targets */ bool *attisdropped; /* true if attr is dropped; don't dump it */ bool *attisserial; /* true if attr is serial or bigserial */ + /* * Note: we need to store per-attribute notnull and default stuff for * all interesting tables so that we can tell which constraints were @@ -214,20 +216,20 @@ extern InhInfo *getInherits(int *numInherits); extern void getTableAttrs(TableInfo *tbinfo, int numTables); extern void dumpDBComment(Archive *outfile); extern void dumpNamespaces(Archive *fout, - NamespaceInfo *nsinfo, int numNamespaces); + NamespaceInfo *nsinfo, int numNamespaces); extern void dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs, TypeInfo *tinfo, int numTypes); extern void dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs); extern void dumpFuncs(Archive *fout, FuncInfo finfo[], int numFuncs); extern void dumpCasts(Archive *fout, FuncInfo *finfo, int numFuncs, - TypeInfo *tinfo, int numTypes); + TypeInfo *tinfo, int numTypes); extern void dumpAggs(Archive *fout, AggInfo agginfo[], int numAggregates); extern void dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators); extern void dumpOpclasses(Archive *fout, - OpclassInfo *opcinfo, int numOpclasses); + OpclassInfo *opcinfo, int numOpclasses); extern void dumpTables(Archive *fout, TableInfo tblinfo[], int numTables, - const bool aclsSkip, - const bool schemaOnly, const bool dataOnly); + const bool aclsSkip, + const bool schemaOnly, const bool dataOnly); extern void dumpIndexes(Archive *fout, TableInfo *tbinfo, int numTables); /* sprompt.h */ diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 3103561db2..1ff698ef5b 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.5 2002/09/02 22:18:56 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.6 2002/09/04 20:31:35 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -45,17 +45,17 @@ static void dumpUserConfig(PGconn *conn, const char *username); static void makeAlterConfigCommand(const char *arrayitem, const char *type, const char *name); static void dumpDatabases(PGconn *conn); -static int runPgDump(const char *dbname); +static int runPgDump(const char *dbname); static PGconn *connectDatabase(const char *dbname, const char *pghost, const char *pgport, - const char *pguser, bool require_password); + const char *pguser, bool require_password); static PGresult *executeQuery(PGconn *conn, const char *query); static char *findPgDump(const char *argv0); -char *pgdumploc; +char *pgdumploc; PQExpBuffer pgdumpopts; -bool output_clean = false; -bool verbose = false; +bool output_clean = false; +bool verbose = false; @@ -169,20 +169,20 @@ main(int argc, char *argv[]) appendPQExpBuffer(pgdumpopts, " -W"); break; - default: - fprintf(stderr, _("Try '%s --help' for more information.\n"), progname); - exit(1); + default: + fprintf(stderr, _("Try '%s --help' for more information.\n"), progname); + exit(1); } } - if (optind < argc) - { - fprintf(stderr, + if (optind < argc) + { + fprintf(stderr, _("%s: too many command line options (first is '%s')\n" "Try '%s --help' for more information.\n"), - progname, argv[optind], progname); - exit(1); - } + progname, argv[optind], progname); + exit(1); + } conn = connectDatabase("template1", pghost, pgport, pguser, force_password); @@ -217,32 +217,32 @@ help(void) printf(_("Options:\n")); #ifdef HAVE_GETOPT_LONG - printf(_(" -c, --clean clean (drop) schema prior to create\n")); + printf(_(" -c, --clean clean (drop) schema prior to create\n")); printf(_(" -d, --inserts dump data as INSERT, rather than COPY, commands\n")); printf(_(" -D, --column-inserts dump data as INSERT commands with column names\n")); printf(_(" -g, --globals-only only dump global objects, no databases\n")); - printf(_(" -h, --host=HOSTNAME database server host name\n")); + printf(_(" -h, --host=HOSTNAME database server host name\n")); printf(_(" -i, --ignore-version proceed even when server version mismatches\n" " pg_dumpall version\n")); printf(_(" -o, --oids include OIDs in dump\n")); - printf(_(" -p, --port=PORT database server port number\n")); - printf(_(" -U, --username=NAME connect as specified database user\n")); + printf(_(" -p, --port=PORT database server port number\n")); + printf(_(" -U, --username=NAME connect as specified database user\n")); printf(_(" -v, --verbose verbose mode\n")); - printf(_(" -W, --password force password prompt (should happen automatically)\n")); -#else /* not HAVE_GETOPT_LONG */ - printf(_(" -c clean (drop) schema prior to create\n")); + printf(_(" -W, --password force password prompt (should happen automatically)\n")); +#else /* not HAVE_GETOPT_LONG */ + printf(_(" -c clean (drop) schema prior to create\n")); printf(_(" -d dump data as INSERT, rather than COPY, commands\n")); printf(_(" -D dump data as INSERT commands with column names\n")); printf(_(" -g only dump global objects, no databases\n")); - printf(_(" -h HOSTNAME database server host name\n")); + printf(_(" -h HOSTNAME database server host name\n")); printf(_(" -i proceed even when server version mismatches\n" " pg_dumpall version\n")); printf(_(" -o include OIDs in dump\n")); - printf(_(" -p PORT database server port number\n")); - printf(_(" -U NAME connect as specified database user\n")); + printf(_(" -p PORT database server port number\n")); + printf(_(" -U NAME connect as specified database user\n")); printf(_(" -v verbose mode\n")); - printf(_(" -W force password prompt (should happen automatically)\n")); -#endif /* not HAVE_GETOPT_LONG */ + printf(_(" -W force password prompt (should happen automatically)\n")); +#endif /* not HAVE_GETOPT_LONG */ printf(_("\nThe SQL script will be written to the standard output.\n\n")); printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n")); @@ -256,8 +256,8 @@ help(void) static void dumpUsers(PGconn *conn) { - PGresult *res; - int i; + PGresult *res; + int i; printf("--\n-- Users\n--\n\n"); printf("DELETE FROM pg_shadow WHERE usesysid <> (SELECT datdba FROM pg_database WHERE datname = 'template0');\n\n"); @@ -283,12 +283,12 @@ dumpUsers(PGconn *conn) appendStringLiteral(buf, PQgetvalue(res, i, 2), true); } - if (strcmp(PQgetvalue(res, i, 3), "t")==0) + if (strcmp(PQgetvalue(res, i, 3), "t") == 0) appendPQExpBuffer(buf, " CREATEDB"); else appendPQExpBuffer(buf, " NOCREATEDB"); - if (strcmp(PQgetvalue(res, i, 4), "t")==0) + if (strcmp(PQgetvalue(res, i, 4), "t") == 0) appendPQExpBuffer(buf, " CREATEUSER"); else appendPQExpBuffer(buf, " NOCREATEUSER"); @@ -316,8 +316,8 @@ dumpUsers(PGconn *conn) static void dumpGroups(PGconn *conn) { - PGresult *res; - int i; + PGresult *res; + int i; printf("--\n-- Groups\n--\n\n"); printf("DELETE FROM pg_group;\n\n"); @@ -327,8 +327,8 @@ dumpGroups(PGconn *conn) for (i = 0; i < PQntuples(res); i++) { PQExpBuffer buf = createPQExpBuffer(); - char *val; - char *tok; + char *val; + char *tok; appendPQExpBuffer(buf, "CREATE GROUP %s WITH SYSID %s;\n", fmtId(PQgetvalue(res, i, 0)), @@ -338,9 +338,9 @@ dumpGroups(PGconn *conn) tok = strtok(val, ",{}"); do { - PGresult *res2; + PGresult *res2; PQExpBuffer buf2 = createPQExpBuffer(); - int j; + int j; appendPQExpBuffer(buf2, "SELECT usename FROM pg_shadow WHERE usesysid = %s;", tok); res2 = executeQuery(conn, buf2->data); @@ -382,24 +382,27 @@ dumpGroups(PGconn *conn) static void dumpCreateDB(PGconn *conn) { - PGresult *res; - int i; + PGresult *res; + int i; printf("--\n-- Database creation\n--\n\n"); - /* Basically this query returns: dbname, dbowner, encoding, istemplate, dbpath */ + /* + * Basically this query returns: dbname, dbowner, encoding, + * istemplate, dbpath + */ res = executeQuery(conn, "SELECT datname, coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), pg_encoding_to_char(d.encoding), datistemplate, datpath FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) WHERE datallowconn ORDER BY 1;"); for (i = 0; i < PQntuples(res); i++) { PQExpBuffer buf = createPQExpBuffer(); - char *dbname = PQgetvalue(res, i, 0); - char *dbowner = PQgetvalue(res, i, 1); - char *dbencoding = PQgetvalue(res, i, 2); - char *dbistemplate = PQgetvalue(res, i, 3); - char *dbpath = PQgetvalue(res, i, 4); + char *dbname = PQgetvalue(res, i, 0); + char *dbowner = PQgetvalue(res, i, 1); + char *dbencoding = PQgetvalue(res, i, 2); + char *dbistemplate = PQgetvalue(res, i, 3); + char *dbpath = PQgetvalue(res, i, 4); - if (strcmp(dbname, "template1")==0) + if (strcmp(dbname, "template1") == 0) continue; if (output_clean) @@ -408,7 +411,7 @@ dumpCreateDB(PGconn *conn) appendPQExpBuffer(buf, "CREATE DATABASE %s", fmtId(dbname)); appendPQExpBuffer(buf, " WITH OWNER = %s TEMPLATE = template0", fmtId(dbowner)); - if (strcmp(dbpath, "")!=0) + if (strcmp(dbpath, "") != 0) { appendPQExpBuffer(buf, " LOCATION = "); appendStringLiteral(buf, dbpath, true); @@ -419,7 +422,7 @@ dumpCreateDB(PGconn *conn) appendPQExpBuffer(buf, ";\n"); - if (strcmp(dbistemplate, "t")==0) + if (strcmp(dbistemplate, "t") == 0) { appendPQExpBuffer(buf, "UPDATE pg_database SET datistemplate = 't' WHERE datname = "); appendStringLiteral(buf, dbname, true); @@ -444,9 +447,9 @@ static void dumpDatabaseConfig(PGconn *conn, const char *dbname) { PQExpBuffer buf = createPQExpBuffer(); - int count = 1; + int count = 1; - for(;;) + for (;;) { PGresult *res; @@ -480,9 +483,9 @@ static void dumpUserConfig(PGconn *conn, const char *username) { PQExpBuffer buf = createPQExpBuffer(); - int count = 1; + int count = 1; - for(;;) + for (;;) { PGresult *res; @@ -515,8 +518,8 @@ dumpUserConfig(PGconn *conn, const char *username) static void makeAlterConfigCommand(const char *arrayitem, const char *type, const char *name) { - char *pos; - char *mine; + char *pos; + char *mine; PQExpBuffer buf = createPQExpBuffer(); mine = strdup(arrayitem); @@ -543,15 +546,16 @@ makeAlterConfigCommand(const char *arrayitem, const char *type, const char *name static void dumpDatabases(PGconn *conn) { - PGresult *res; - int i; + PGresult *res; + int i; res = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;"); for (i = 0; i < PQntuples(res); i++) { - int ret; + int ret; + + char *dbname = PQgetvalue(res, i, 0); - char *dbname = PQgetvalue(res, i, 0); if (verbose) fprintf(stderr, _("%s: dumping database \"%s\"...\n"), progname, dbname); @@ -576,7 +580,7 @@ static int runPgDump(const char *dbname) { PQExpBuffer cmd = createPQExpBuffer(); - int ret; + int ret; appendPQExpBuffer(cmd, "%s %s -X use-set-session-authorization -Fp %s", pgdumploc, pgdumpopts->data, dbname); @@ -644,7 +648,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport, if (PQstatus(conn) == CONNECTION_BAD) { fprintf(stderr, _("%s: could not connect to database %s: %s\n"), - progname, dbname, PQerrorMessage(conn)); + progname, dbname, PQerrorMessage(conn)); exit(0); } @@ -659,7 +663,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport, static PGresult * executeQuery(PGconn *conn, const char *query) { - PGresult *res; + PGresult *res; res = PQexec(conn, query); if (!res || @@ -696,7 +700,8 @@ findPgDump(const char *argv0) appendPQExpBuffer(cmd, "pg_dump"); else { - char *dir = strdup(argv0); + char *dir = strdup(argv0); + *(dir + (last - argv0)) = '\0'; appendPQExpBuffer(cmd, "%s/pg_dump", dir); } @@ -704,15 +709,15 @@ findPgDump(const char *argv0) result = strdup(cmd->data); appendPQExpBuffer(cmd, " -V >/dev/null 2>&1"); - if (system(cmd->data)==0) + if (system(cmd->data) == 0) goto end; result = BINDIR "/pg_dump"; - if (system(BINDIR "/pg_dump -V >/dev/null 2>&1")==0) + if (system(BINDIR "/pg_dump -V >/dev/null 2>&1") == 0) goto end; fprintf(stderr, _("%s: could not find pg_dump\n" - "Make sure it is in the path or in the same directory as %s.\n"), + "Make sure it is in the path or in the same directory as %s.\n"), progname, progname); exit(1); diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 4aa9270b73..382b0db3b0 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -34,7 +34,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.40 2002/08/28 20:57:22 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.41 2002/09/04 20:31:35 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -379,75 +379,75 @@ usage(const char *progname) printf(_("Options:\n")); #ifdef HAVE_GETOPT_LONG - printf(_( " -a, --data-only restore only the data, no schema\n")); - printf(_( " -c, --clean clean (drop) schema prior to create\n")); - printf(_( " -C, --create issue commands to create the database\n")); - printf(_( " -d, --dbname=NAME output database name\n")); - printf(_( " -f, --file=FILENAME output file name\n")); - printf(_( " -F, --format={c|t} specify backup file format\n")); - printf(_( " -h, --host=HOSTNAME database server host name\n")); - printf(_( " -i, --ignore-version proceed even when server version mismatches\n")); - printf(_( " -I, --index=NAME restore named index\n")); - printf(_( " -l, --list print summarized TOC of the archive\n")); - printf(_( " -L, --use-list=FILENAME use specified table of contents for ordering\n" - " output from this file\n")); - printf(_( " -N, --orig-order restore in original dump order\n")); - printf(_( " -o, --oid-order restore in OID order\n")); - printf(_( " -O, --no-owner do not reconnect to database to match\n" - " object owner\n")); - printf(_( " -p, --port=PORT database server port number\n")); - printf(_( " -P, --function=NAME(args)restore named function\n")); - printf(_( " -r, --rearrange rearrange output to put indexes etc. at end\n")); - printf(_( " -R, --no-reconnect disallow ALL reconnections to the database\n")); - printf(_( " -s, --schema-only restore only the schema, no data\n")); - printf(_( " -S, --superuser=NAME specify the superuser user name to use for\n" - " disabling triggers\n")); - printf(_( " -t, --table=NAME restore named table\n")); - printf(_( " -T, --trigger=NAME restore named trigger\n")); - printf(_( " -U, --username=NAME connect as specified database user\n")); - printf(_( " -v, --verbose verbose mode\n")); - printf(_( " -W, --password force password prompt (should happen automatically)\n")); - printf(_( " -x, --no-privileges skip restoration of access privileges (grant/revoke)\n")); - printf(_( " -X use-set-session-authorization, --use-set-session-authorization\n" - " use SET SESSION AUTHORIZATION commands instead\n" - " of reconnecting, if possible\n")); - printf(_( " -X disable-triggers, --disable-triggers\n" - " disable triggers during data-only restore\n")); + printf(_(" -a, --data-only restore only the data, no schema\n")); + printf(_(" -c, --clean clean (drop) schema prior to create\n")); + printf(_(" -C, --create issue commands to create the database\n")); + printf(_(" -d, --dbname=NAME output database name\n")); + printf(_(" -f, --file=FILENAME output file name\n")); + printf(_(" -F, --format={c|t} specify backup file format\n")); + printf(_(" -h, --host=HOSTNAME database server host name\n")); + printf(_(" -i, --ignore-version proceed even when server version mismatches\n")); + printf(_(" -I, --index=NAME restore named index\n")); + printf(_(" -l, --list print summarized TOC of the archive\n")); + printf(_(" -L, --use-list=FILENAME use specified table of contents for ordering\n" + " output from this file\n")); + printf(_(" -N, --orig-order restore in original dump order\n")); + printf(_(" -o, --oid-order restore in OID order\n")); + printf(_(" -O, --no-owner do not reconnect to database to match\n" + " object owner\n")); + printf(_(" -p, --port=PORT database server port number\n")); + printf(_(" -P, --function=NAME(args)restore named function\n")); + printf(_(" -r, --rearrange rearrange output to put indexes etc. at end\n")); + printf(_(" -R, --no-reconnect disallow ALL reconnections to the database\n")); + printf(_(" -s, --schema-only restore only the schema, no data\n")); + printf(_(" -S, --superuser=NAME specify the superuser user name to use for\n" + " disabling triggers\n")); + printf(_(" -t, --table=NAME restore named table\n")); + printf(_(" -T, --trigger=NAME restore named trigger\n")); + printf(_(" -U, --username=NAME connect as specified database user\n")); + printf(_(" -v, --verbose verbose mode\n")); + printf(_(" -W, --password force password prompt (should happen automatically)\n")); + printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n")); + printf(_(" -X use-set-session-authorization, --use-set-session-authorization\n" + " use SET SESSION AUTHORIZATION commands instead\n" + " of reconnecting, if possible\n")); + printf(_(" -X disable-triggers, --disable-triggers\n" + " disable triggers during data-only restore\n")); #else /* not HAVE_GETOPT_LONG */ - printf(_( " -a restore only the data, no schema\n")); - printf(_( " -c clean (drop) schema prior to create\n")); - printf(_( " -C issue commands to create the database\n")); - printf(_( " -d NAME output database name\n")); - printf(_( " -f FILENAME output file name\n")); - printf(_( " -F {c|t} specify backup file format\n")); - printf(_( " -h HOSTNAME database server host name\n")); - printf(_( " -i proceed even when server version mismatches\n")); - printf(_( " -I NAME restore named index\n")); - printf(_( " -l print summarized TOC of the archive\n")); - printf(_( " -L FILENAME use specified table of contents for ordering\n" - " output from this file\n")); - printf(_( " -N restore in original dump order\n")); - printf(_( " -o restore in OID order\n")); - printf(_( " -O do not reconnect to database to match\n" - " object owner\n")); - printf(_( " -p PORT database server port number\n")); - printf(_( " -P NAME(args) restore named function\n")); - printf(_( " -r rearrange output to put indexes etc. at end\n")); - printf(_( " -R disallow ALL reconnections to the database\n")); - printf(_( " -s restore only the schema, no data\n")); - printf(_( " -S NAME specify the superuser user name to use for\n" - " disabling triggers\n")); - printf(_( " -t NAME restore named table\n")); - printf(_( " -T NAME restore named trigger\n")); - printf(_( " -U NAME connect as specified database user\n")); - printf(_( " -v verbose mode\n")); - printf(_( " -W force password prompt (should happen automatically)\n")); - printf(_( " -x skip restoration of access privileges (grant/revoke)\n")); - printf(_( " -X use-set-session-authorization\n" - " use SET SESSION AUTHORIZATION commands instead\n" - " of reconnecting, if possible\n")); - printf(_( " -X disable-triggers disable triggers during data-only restore\n")); + printf(_(" -a restore only the data, no schema\n")); + printf(_(" -c clean (drop) schema prior to create\n")); + printf(_(" -C issue commands to create the database\n")); + printf(_(" -d NAME output database name\n")); + printf(_(" -f FILENAME output file name\n")); + printf(_(" -F {c|t} specify backup file format\n")); + printf(_(" -h HOSTNAME database server host name\n")); + printf(_(" -i proceed even when server version mismatches\n")); + printf(_(" -I NAME restore named index\n")); + printf(_(" -l print summarized TOC of the archive\n")); + printf(_(" -L FILENAME use specified table of contents for ordering\n" + " output from this file\n")); + printf(_(" -N restore in original dump order\n")); + printf(_(" -o restore in OID order\n")); + printf(_(" -O do not reconnect to database to match\n" + " object owner\n")); + printf(_(" -p PORT database server port number\n")); + printf(_(" -P NAME(args) restore named function\n")); + printf(_(" -r rearrange output to put indexes etc. at end\n")); + printf(_(" -R disallow ALL reconnections to the database\n")); + printf(_(" -s restore only the schema, no data\n")); + printf(_(" -S NAME specify the superuser user name to use for\n" + " disabling triggers\n")); + printf(_(" -t NAME restore named table\n")); + printf(_(" -T NAME restore named trigger\n")); + printf(_(" -U NAME connect as specified database user\n")); + printf(_(" -v verbose mode\n")); + printf(_(" -W force password prompt (should happen automatically)\n")); + printf(_(" -x skip restoration of access privileges (grant/revoke)\n")); + printf(_(" -X use-set-session-authorization\n" + " use SET SESSION AUTHORIZATION commands instead\n" + " of reconnecting, if possible\n")); + printf(_(" -X disable-triggers disable triggers during data-only restore\n")); #endif printf(_("\nIf no input file name is supplied, then standard input is used.\n\n")); @@ -486,8 +486,8 @@ static char * _cleanupFuncName(char *name) { int i; - char *ch; - + char *ch; + if (!name || !name[0]) return NULL; @@ -497,7 +497,7 @@ _cleanupFuncName(char *name) { strcpy(name, &name[1]); if (strchr(name, '"') != NULL) - strcpy(strchr(name, '"'), strchr(name, '"')+1); + strcpy(strchr(name, '"'), strchr(name, '"') + 1); } /* otherwise, convert function name to lowercase... */ else @@ -508,21 +508,20 @@ _cleanupFuncName(char *name) } /* strip out any space before paren */ - ch = strchr(name,'('); - while (ch && ch > name && *(ch-1) == ' ') + ch = strchr(name, '('); + while (ch && ch > name && *(ch - 1) == ' ') { strcpy(ch - 1, ch); ch--; } /* - * Strip out spaces after commas in parameter list. - * We can't remove all spaces because some types, like - * 'double precision' have spaces. + * Strip out spaces after commas in parameter list. We can't remove + * all spaces because some types, like 'double precision' have spaces. */ - if ((ch = strchr(name,'(')) != NULL) + if ((ch = strchr(name, '(')) != NULL) { - while ((ch = strstr(ch,", ")) != NULL) + while ((ch = strstr(ch, ", ")) != NULL) strcpy(ch + 1, ch + 2); } diff --git a/src/bin/pg_dump/sprompt.c b/src/bin/pg_dump/sprompt.c index 6bc0d986a1..9c15b3fdbd 100644 --- a/src/bin/pg_dump/sprompt.c +++ b/src/bin/pg_dump/sprompt.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/sprompt.c,v 1.1 2002/07/06 20:12:30 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/sprompt.c,v 1.2 2002/09/04 20:31:35 momjian Exp $ */ /* @@ -24,7 +24,7 @@ #include <termios.h> #endif -bool prompt_state = false; +bool prompt_state = false; extern char *simple_prompt(const char *prompt, int maxlen, bool echo); char * diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index 11986cd3db..0d230076ee 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -23,7 +23,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.4 2002/09/02 02:47:07 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.5 2002/09/04 20:31:35 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -220,8 +220,8 @@ main(int argc, char *argv[]) if (ControlFile.state != DB_SHUTDOWNED && !force) { printf(_("The database server was not shut down cleanly.\n" - "Resetting the transaction log may cause data to be lost.\n" - "If you want to proceed anyway, use -f to force reset.\n")); + "Resetting the transaction log may cause data to be lost.\n" + "If you want to proceed anyway, use -f to force reset.\n")); exit(1); } @@ -234,7 +234,7 @@ main(int argc, char *argv[]) ControlFile.checkPointCopy.nextXid = set_xid; if (minXlogId > ControlFile.logId || - (minXlogId == ControlFile.logId && minXlogSeg > ControlFile.logSeg)) + (minXlogId == ControlFile.logId && minXlogSeg > ControlFile.logSeg)) { ControlFile.logId = minXlogId; ControlFile.logSeg = minXlogSeg; @@ -640,7 +640,7 @@ static void usage(void) { printf(_("%s resets the PostgreSQL transaction log.\n\n"), progname); - printf(_("Usage:\n %s [OPTIONS] DATADIR\n\n"), progname); + printf(_("Usage:\n %s [OPTIONS] DATADIR\n\n"), progname); printf(_("Options:\n")); printf(_(" -f force update to be done\n")); printf(_(" -l FILEID,SEG force minimum WAL starting location for new transaction log\n")); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 000402216a..b1e451c704 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.79 2002/09/02 06:11:42 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.80 2002/09/04 20:31:35 momjian Exp $ */ #include "postgres_fe.h" #include "command.h" @@ -58,7 +58,7 @@ enum option_type }; static char *scan_option(char **string, enum option_type type, - char *quote, bool semicolon); + char *quote, bool semicolon); static char *unescape(const unsigned char *source, size_t len); static bool do_edit(const char *filename_arg, PQExpBuffer query_buf); @@ -246,13 +246,13 @@ exec_command(const char *cmd, opt2q; /* - * Ideally we should treat the arguments as SQL identifiers. But for - * backwards compatibility with 7.2 and older pg_dump files, we have - * to take unquoted arguments verbatim (don't downcase them). - * For now, double-quoted arguments may be stripped of double quotes - * (as if SQL identifiers). By 7.4 or so, pg_dump files can be - * expected to double-quote all mixed-case \connect arguments, - * and then we can get rid of OT_SQLIDHACK. + * Ideally we should treat the arguments as SQL identifiers. But + * for backwards compatibility with 7.2 and older pg_dump files, + * we have to take unquoted arguments verbatim (don't downcase + * them). For now, double-quoted arguments may be stripped of + * double quotes (as if SQL identifiers). By 7.4 or so, pg_dump + * files can be expected to double-quote all mixed-case \connect + * arguments, and then we can get rid of OT_SQLIDHACK. */ opt1 = scan_option(&string, OT_SQLIDHACK, &opt1q, true); opt2 = scan_option(&string, OT_SQLIDHACK, &opt2q, true); @@ -723,9 +723,7 @@ exec_command(const char *cmd, if (!quiet) { if (pset.timing) - { puts(gettext(("Timing is on."))); - } else { puts(gettext(("Timing is off."))); @@ -733,7 +731,7 @@ exec_command(const char *cmd, } } } - + /* \unset */ else if (strcmp(cmd, "unset") == 0) { @@ -931,8 +929,8 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon) /* * Next command: treat like end of line * - * XXX this means we can't conveniently accept options that - * start with a backslash; therefore, option processing that + * XXX this means we can't conveniently accept options that start + * with a backslash; therefore, option processing that * encourages use of backslashes is rather broken. */ case '\\': @@ -1088,7 +1086,8 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon) * * If we are processing the option as a SQL identifier, then * downcase unquoted letters and remove double-quotes --- but - * doubled double-quotes become output double-quotes, per spec. + * doubled double-quotes become output double-quotes, per + * spec. * * Note that a string like FOO"BAR"BAZ will be converted to * fooBARbaz; this is somewhat inconsistent with the SQL spec, @@ -1124,7 +1123,7 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon) else { if (*cp != '"') - break; /* whitespace or end of string */ + break; /* whitespace or end of string */ if (quote) *quote = '"'; inquotes = true; @@ -1150,12 +1149,12 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon) /* Strip any trailing semi-colons if requested */ if (semicolon) { - int i; + int i; for (i = token_len - 1; i >= 0 && return_val[i] == ';'; i--) - /* skip */; + /* skip */ ; if (i < 0) { @@ -1169,9 +1168,9 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon) } /* - * If SQL identifier processing was requested, - * then we strip out excess double quotes and downcase - * unquoted letters. + * If SQL identifier processing was requested, then we + * strip out excess double quotes and downcase unquoted + * letters. */ if (type == OT_SQLID || type == OT_SQLIDHACK) { @@ -1189,7 +1188,7 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon) } inquotes = !inquotes; /* Collapse out quote at *cp */ - memmove(cp, cp+1, strlen(cp)); + memmove(cp, cp + 1, strlen(cp)); /* do not advance cp */ } else @@ -1550,8 +1549,8 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf) const char *tmpdirenv = getenv("TMPDIR"); snprintf(fnametmp, sizeof(fnametmp), "%s/psql.edit.%ld.%ld", - tmpdirenv ? tmpdirenv : "/tmp", - (long) geteuid(), (long) getpid()); + tmpdirenv ? tmpdirenv : "/tmp", + (long) geteuid(), (long) getpid()); #else GetTempFileName(".", "psql", 0, fnametmp); #endif diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index f8bf9c9a35..0277301074 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.43 2002/08/27 20:16:48 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.44 2002/09/04 20:31:35 momjian Exp $ */ #include "postgres_fe.h" @@ -295,7 +295,8 @@ SendQuery(const char *query) bool success = false; PGresult *results; PGnotify *notify; - struct timeval before,after; + struct timeval before, + after; struct timezone tz; if (!pset.db) @@ -327,14 +328,10 @@ SendQuery(const char *query) cancelConn = pset.db; if (pset.timing) - { gettimeofday(&before, &tz); - } results = PQexec(pset.db, query); if (pset.timing) - { gettimeofday(&after, &tz); - } if (PQresultStatus(results) == PGRES_COPY_IN) copy_in_state = true; /* keep cancel connection for copy out state */ @@ -467,7 +464,7 @@ SendQuery(const char *query) /* Possible microtiming output */ if (pset.timing && success) printf(gettext("Time: %.2f ms\n"), - ((after.tv_sec-before.tv_sec)*1000000 + after.tv_usec - before.tv_usec) / 1000.0); + ((after.tv_sec - before.tv_sec) * 1000000 + after.tv_usec - before.tv_usec) / 1000.0); return success; } diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 32f875db84..90a9006d2b 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.23 2002/06/20 16:00:44 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.24 2002/09/04 20:31:35 momjian Exp $ */ #include "postgres_fe.h" #include "copy.h" @@ -123,7 +123,10 @@ parse_slash_copy(const char *args) error = true; else { - /* Allows old COPY syntax for backward compatibility 2002-06-19 */ + /* + * Allows old COPY syntax for backward compatibility + * 2002-06-19 + */ if (strcasecmp(token, "with") == 0) { token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); @@ -165,7 +168,10 @@ parse_slash_copy(const char *args) token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); if (token) { - /* Allows old COPY syntax for backward compatibility 2002-06-19 */ + /* + * Allows old COPY syntax for backward compatibility + * 2002-06-19 + */ if (strcasecmp(token, "using") == 0) { token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); @@ -212,10 +218,12 @@ parse_slash_copy(const char *args) else error = true; } - else error = true; + else + error = true; } } - else error = true; + else + error = true; } free(line); @@ -305,7 +313,7 @@ do_copy(const char *args) /* make sure the specified file is not a directory */ fstat(fileno(copystream), &st); - if( S_ISDIR(st.st_mode) ) + if (S_ISDIR(st.st_mode)) { fclose(copystream); psql_error("%s: cannot COPY TO/FROM a directory\n", diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 4bf3b6cc49..239d984a08 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.67 2002/08/29 00:17:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.68 2002/09/04 20:31:35 momjian Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -21,13 +21,13 @@ #define _(x) gettext((x)) static bool describeOneTableDetails(const char *schemaname, - const char *relationname, - const char *oid, - bool verbose); + const char *relationname, + const char *oid, + bool verbose); static void processNamePattern(PQExpBuffer buf, const char *pattern, - bool have_where, bool force_escape, - const char *schemavar, const char *namevar, - const char *altnamevar, const char *visibilityrule); + bool have_where, bool force_escape, + const char *schemavar, const char *namevar, + const char *altnamevar, const char *visibilityrule); static void * @@ -71,19 +71,19 @@ describeAggregates(const char *pattern, bool verbose) * types and ones that work on all (denoted by input type = "any") */ printfPQExpBuffer(&buf, - "SELECT n.nspname as \"%s\",\n" - " p.proname AS \"%s\",\n" - " CASE p.proargtypes[0]\n" - " WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype\n" - " THEN CAST('%s' AS pg_catalog.text)\n" - " ELSE pg_catalog.format_type(p.proargtypes[0], NULL)\n" - " END AS \"%s\",\n" + "SELECT n.nspname as \"%s\",\n" + " p.proname AS \"%s\",\n" + " CASE p.proargtypes[0]\n" + " WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype\n" + " THEN CAST('%s' AS pg_catalog.text)\n" + " ELSE pg_catalog.format_type(p.proargtypes[0], NULL)\n" + " END AS \"%s\",\n" " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n" - "FROM pg_catalog.pg_proc p\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" - "WHERE p.proisagg\n", - _("Schema"), _("Name"), _("(all types)"), - _("Data type"), _("Description")); + "FROM pg_catalog.pg_proc p\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" + "WHERE p.proisagg\n", + _("Schema"), _("Name"), _("(all types)"), + _("Data type"), _("Description")); processNamePattern(&buf, pattern, true, false, "n.nspname", "p.proname", NULL, @@ -119,38 +119,39 @@ describeFunctions(const char *pattern, bool verbose) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n" - " n.nspname as \"%s\",\n" - " p.proname as \"%s\",\n" - " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\"", - _("Result data type"), _("Schema"), _("Name"), - _("Argument data types")); + "SELECT pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n" + " n.nspname as \"%s\",\n" + " p.proname as \"%s\",\n" + " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\"", + _("Result data type"), _("Schema"), _("Name"), + _("Argument data types")); if (verbose) appendPQExpBuffer(&buf, - ",\n u.usename as \"%s\",\n" - " l.lanname as \"%s\",\n" - " p.prosrc as \"%s\",\n" - " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"", - _("Owner"), _("Language"), - _("Source code"), _("Description")); + ",\n u.usename as \"%s\",\n" + " l.lanname as \"%s\",\n" + " p.prosrc as \"%s\",\n" + " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"", + _("Owner"), _("Language"), + _("Source code"), _("Description")); if (!verbose) appendPQExpBuffer(&buf, - "\nFROM pg_catalog.pg_proc p" - "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"); + "\nFROM pg_catalog.pg_proc p" + "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"); else appendPQExpBuffer(&buf, - "\nFROM pg_catalog.pg_proc p" - "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace" - "\n LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang" - "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = p.proowner\n"); + "\nFROM pg_catalog.pg_proc p" + "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace" + "\n LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang" + "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = p.proowner\n"); /* - * we skip in/out funcs by excluding functions that take or return cstring + * we skip in/out funcs by excluding functions that take or return + * cstring */ appendPQExpBuffer(&buf, - "WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n" + "WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n" " AND p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype\n" " AND NOT p.proisagg\n"); @@ -190,33 +191,34 @@ describeTypes(const char *pattern, bool verbose) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT n.nspname as \"%s\",\n" - " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n", - _("Schema"), _("Name")); + "SELECT n.nspname as \"%s\",\n" + " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n", + _("Schema"), _("Name")); if (verbose) appendPQExpBuffer(&buf, - " t.typname AS \"%s\",\n" - " CASE WHEN t.typrelid != 0\n" - " THEN CAST('tuple' AS pg_catalog.text)\n" - " WHEN t.typlen < 0\n" - " THEN CAST('var' AS pg_catalog.text)\n" - " ELSE CAST(t.typlen AS pg_catalog.text)\n" - " END AS \"%s\",\n", - _("Internal name"), _("Size")); + " t.typname AS \"%s\",\n" + " CASE WHEN t.typrelid != 0\n" + " THEN CAST('tuple' AS pg_catalog.text)\n" + " WHEN t.typlen < 0\n" + " THEN CAST('var' AS pg_catalog.text)\n" + " ELSE CAST(t.typlen AS pg_catalog.text)\n" + " END AS \"%s\",\n", + _("Internal name"), _("Size")); appendPQExpBuffer(&buf, - " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n", - _("Description")); + " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n", + _("Description")); appendPQExpBuffer(&buf, "FROM pg_catalog.pg_type t\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"); + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"); /* * do not include array types (start with underscore); do not include - * complex types (typrelid!=0) unless they are standalone composite types + * complex types (typrelid!=0) unless they are standalone composite + * types */ appendPQExpBuffer(&buf, "WHERE (t.typrelid = 0 "); appendPQExpBuffer(&buf, "OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c " - "WHERE c.oid = t.typrelid)) "); + "WHERE c.oid = t.typrelid)) "); appendPQExpBuffer(&buf, "AND t.typname !~ '^_'\n"); /* Match name pattern against either internal or external name */ @@ -255,18 +257,18 @@ describeOperators(const char *pattern) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT n.nspname as \"%s\",\n" - " o.oprname AS \"%s\",\n" - " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n" - " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n" - " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n" - " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n" - " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n" - "FROM pg_catalog.pg_operator o\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n", - _("Schema"), _("Name"), - _("Left arg type"), _("Right arg type"), - _("Result type"), _("Description")); + "SELECT n.nspname as \"%s\",\n" + " o.oprname AS \"%s\",\n" + " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n" + " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n" + " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n" + " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n" + " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n" + "FROM pg_catalog.pg_operator o\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n", + _("Schema"), _("Name"), + _("Left arg type"), _("Right arg type"), + _("Result type"), _("Description")); processNamePattern(&buf, pattern, false, true, "n.nspname", "o.oprname", NULL, @@ -304,20 +306,20 @@ listAllDbs(bool verbose) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT d.datname as \"%s\",\n" - " u.usename as \"%s\"", - _("Name"), _("Owner")); + "SELECT d.datname as \"%s\",\n" + " u.usename as \"%s\"", + _("Name"), _("Owner")); appendPQExpBuffer(&buf, - ",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\"", - _("Encoding")); + ",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\"", + _("Encoding")); if (verbose) appendPQExpBuffer(&buf, - ",\n pg_catalog.obj_description(d.oid, 'pg_database') as \"%s\"", - _("Description")); + ",\n pg_catalog.obj_description(d.oid, 'pg_database') as \"%s\"", + _("Description")); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_database d" - "\n LEFT JOIN pg_catalog.pg_user u ON d.datdba = u.usesysid\n" - "ORDER BY 1;"); + "\n LEFT JOIN pg_catalog.pg_user u ON d.datdba = u.usesysid\n" + "ORDER BY 1;"); res = PSQLexec(buf.data); termPQExpBuffer(&buf); @@ -348,26 +350,27 @@ permissionsList(const char *pattern) initPQExpBuffer(&buf); /* - * we ignore indexes and toast tables since they have no meaningful rights + * we ignore indexes and toast tables since they have no meaningful + * rights */ printfPQExpBuffer(&buf, - "SELECT n.nspname as \"%s\",\n" - " c.relname as \"%s\",\n" - " c.relacl as \"%s\"\n" - "FROM pg_catalog.pg_class c\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" - "WHERE c.relkind IN ('r', 'v', 'S')\n", - _("Schema"), _("Table"), _("Access privileges")); + "SELECT n.nspname as \"%s\",\n" + " c.relname as \"%s\",\n" + " c.relacl as \"%s\"\n" + "FROM pg_catalog.pg_class c\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + "WHERE c.relkind IN ('r', 'v', 'S')\n", + _("Schema"), _("Table"), _("Access privileges")); /* * Unless a schema pattern is specified, we suppress system and temp - * tables, since they normally aren't very interesting from a permissions - * point of view. You can see 'em by explicit request though, - * eg with \z pg_catalog.* + * tables, since they normally aren't very interesting from a + * permissions point of view. You can see 'em by explicit request + * though, eg with \z pg_catalog.* */ processNamePattern(&buf, pattern, true, false, "n.nspname", "c.relname", NULL, - "pg_catalog.pg_table_is_visible(c.oid) AND n.nspname !~ '^pg_'"); + "pg_catalog.pg_table_is_visible(c.oid) AND n.nspname !~ '^pg_'"); appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); @@ -409,99 +412,99 @@ objectDescription(const char *pattern) initPQExpBuffer(&buf); appendPQExpBuffer(&buf, - "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n" - "FROM (\n", - _("Schema"), _("Name"), _("Object"), _("Description")); + "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n" + "FROM (\n", + _("Schema"), _("Name"), _("Object"), _("Description")); /* Aggregate descriptions */ appendPQExpBuffer(&buf, - " SELECT p.oid as oid, p.tableoid as tableoid,\n" - " n.nspname as nspname,\n" - " CAST(p.proname AS pg_catalog.text) as name," - " CAST('%s' AS pg_catalog.text) as object\n" - " FROM pg_catalog.pg_proc p\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" - " WHERE p.proisagg\n", - _("aggregate")); + " SELECT p.oid as oid, p.tableoid as tableoid,\n" + " n.nspname as nspname,\n" + " CAST(p.proname AS pg_catalog.text) as name," + " CAST('%s' AS pg_catalog.text) as object\n" + " FROM pg_catalog.pg_proc p\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" + " WHERE p.proisagg\n", + _("aggregate")); processNamePattern(&buf, pattern, true, false, "n.nspname", "p.proname", NULL, "pg_catalog.pg_function_is_visible(p.oid)"); /* Function descriptions (except in/outs for datatypes) */ appendPQExpBuffer(&buf, - "UNION ALL\n" - " SELECT p.oid as oid, p.tableoid as tableoid,\n" - " n.nspname as nspname,\n" - " CAST(p.proname AS pg_catalog.text) as name," - " CAST('%s' AS pg_catalog.text) as object\n" - " FROM pg_catalog.pg_proc p\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" - - " WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n" - " AND p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype\n" - " AND NOT p.proisagg\n", - _("function")); + "UNION ALL\n" + " SELECT p.oid as oid, p.tableoid as tableoid,\n" + " n.nspname as nspname,\n" + " CAST(p.proname AS pg_catalog.text) as name," + " CAST('%s' AS pg_catalog.text) as object\n" + " FROM pg_catalog.pg_proc p\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" + + " WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n" + " AND p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype\n" + " AND NOT p.proisagg\n", + _("function")); processNamePattern(&buf, pattern, true, false, "n.nspname", "p.proname", NULL, "pg_catalog.pg_function_is_visible(p.oid)"); /* Operator descriptions (only if operator has its own comment) */ appendPQExpBuffer(&buf, - "UNION ALL\n" - " SELECT o.oid as oid, o.tableoid as tableoid,\n" - " n.nspname as nspname,\n" - " CAST(o.oprname AS pg_catalog.text) as name," - " CAST('%s' AS pg_catalog.text) as object\n" - " FROM pg_catalog.pg_operator o\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n", - _("operator")); + "UNION ALL\n" + " SELECT o.oid as oid, o.tableoid as tableoid,\n" + " n.nspname as nspname,\n" + " CAST(o.oprname AS pg_catalog.text) as name," + " CAST('%s' AS pg_catalog.text) as object\n" + " FROM pg_catalog.pg_operator o\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n", + _("operator")); processNamePattern(&buf, pattern, false, false, "n.nspname", "o.oprname", NULL, "pg_catalog.pg_operator_is_visible(o.oid)"); /* Type description */ appendPQExpBuffer(&buf, - "UNION ALL\n" - " SELECT t.oid as oid, t.tableoid as tableoid,\n" - " n.nspname as nspname,\n" - " pg_catalog.format_type(t.oid, NULL) as name," - " CAST('%s' AS pg_catalog.text) as object\n" - " FROM pg_catalog.pg_type t\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n", - _("data type")); + "UNION ALL\n" + " SELECT t.oid as oid, t.tableoid as tableoid,\n" + " n.nspname as nspname,\n" + " pg_catalog.format_type(t.oid, NULL) as name," + " CAST('%s' AS pg_catalog.text) as object\n" + " FROM pg_catalog.pg_type t\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n", + _("data type")); processNamePattern(&buf, pattern, false, false, - "n.nspname", "pg_catalog.format_type(t.oid, NULL)", NULL, + "n.nspname", "pg_catalog.format_type(t.oid, NULL)", NULL, "pg_catalog.pg_type_is_visible(t.oid)"); /* Relation (tables, views, indexes, sequences) descriptions */ appendPQExpBuffer(&buf, - "UNION ALL\n" - " SELECT c.oid as oid, c.tableoid as tableoid,\n" - " n.nspname as nspname,\n" - " CAST(c.relname AS pg_catalog.text) as name,\n" - " CAST(\n" - " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' END" - " AS pg_catalog.text) as object\n" - " FROM pg_catalog.pg_class c\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" - " WHERE c.relkind IN ('r', 'v', 'i', 'S')\n", - _("table"), _("view"), _("index"), _("sequence")); + "UNION ALL\n" + " SELECT c.oid as oid, c.tableoid as tableoid,\n" + " n.nspname as nspname,\n" + " CAST(c.relname AS pg_catalog.text) as name,\n" + " CAST(\n" + " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' END" + " AS pg_catalog.text) as object\n" + " FROM pg_catalog.pg_class c\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + " WHERE c.relkind IN ('r', 'v', 'i', 'S')\n", + _("table"), _("view"), _("index"), _("sequence")); processNamePattern(&buf, pattern, true, false, "n.nspname", "c.relname", NULL, "pg_catalog.pg_table_is_visible(c.oid)"); /* Rule description (ignore rules for views) */ appendPQExpBuffer(&buf, - "UNION ALL\n" - " SELECT r.oid as oid, r.tableoid as tableoid,\n" - " n.nspname as nspname,\n" - " CAST(r.rulename AS pg_catalog.text) as name," - " CAST('%s' AS pg_catalog.text) as object\n" - " FROM pg_catalog.pg_rewrite r\n" - " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" - " WHERE r.rulename != '_RETURN'\n", - _("rule")); + "UNION ALL\n" + " SELECT r.oid as oid, r.tableoid as tableoid,\n" + " n.nspname as nspname,\n" + " CAST(r.rulename AS pg_catalog.text) as name," + " CAST('%s' AS pg_catalog.text) as object\n" + " FROM pg_catalog.pg_rewrite r\n" + " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + " WHERE r.rulename != '_RETURN'\n", + _("rule")); /* XXX not sure what to do about visibility rule here? */ processNamePattern(&buf, pattern, true, false, "n.nspname", "r.rulename", NULL, @@ -509,23 +512,23 @@ objectDescription(const char *pattern) /* Trigger description */ appendPQExpBuffer(&buf, - "UNION ALL\n" - " SELECT t.oid as oid, t.tableoid as tableoid,\n" - " n.nspname as nspname,\n" - " CAST(t.tgname AS pg_catalog.text) as name," - " CAST('%s' AS pg_catalog.text) as object\n" - " FROM pg_catalog.pg_trigger t\n" - " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n", - _("trigger")); + "UNION ALL\n" + " SELECT t.oid as oid, t.tableoid as tableoid,\n" + " n.nspname as nspname,\n" + " CAST(t.tgname AS pg_catalog.text) as name," + " CAST('%s' AS pg_catalog.text) as object\n" + " FROM pg_catalog.pg_trigger t\n" + " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n", + _("trigger")); /* XXX not sure what to do about visibility rule here? */ processNamePattern(&buf, pattern, false, false, "n.nspname", "t.tgname", NULL, "pg_catalog.pg_table_is_visible(c.oid)"); appendPQExpBuffer(&buf, - ") AS tt\n" - " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid and tt.tableoid = d.classoid and d.objsubid = 0)\n"); + ") AS tt\n" + " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid and tt.tableoid = d.classoid and d.objsubid = 0)\n"); appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;"); @@ -561,11 +564,11 @@ describeTableDetails(const char *pattern, bool verbose) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT c.oid,\n" - " n.nspname,\n" - " c.relname\n" - "FROM pg_catalog.pg_class c\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"); + "SELECT c.oid,\n" + " n.nspname,\n" + " c.relname\n" + "FROM pg_catalog.pg_class c\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"); processNamePattern(&buf, pattern, false, false, "n.nspname", "c.relname", NULL, @@ -625,7 +628,7 @@ describeOneTableDetails(const char *schemaname, PGresult *res = NULL; printTableOpt myopt = pset.popt.topt; int i; - char *view_def = NULL; + char *view_def = NULL; const char *headers[5]; char **cells = NULL; char **footers = NULL; @@ -649,7 +652,7 @@ describeOneTableDetails(const char *schemaname, /* Get general table info */ printfPQExpBuffer(&buf, - "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules\n" + "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules\n" "FROM pg_catalog.pg_class WHERE oid = '%s'", oid); res = PSQLexec(buf.data); @@ -757,7 +760,7 @@ describeOneTableDetails(const char *schemaname, printfPQExpBuffer(&buf, "SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d\n" - "WHERE d.adrelid = '%s' AND d.adnum = %s", + "WHERE d.adrelid = '%s' AND d.adnum = %s", oid, PQgetvalue(res, i, 4)); result = PSQLexec(buf.data); @@ -809,7 +812,7 @@ describeOneTableDetails(const char *schemaname, break; default: printfPQExpBuffer(&title, _("?%c? \"%s.%s\""), - tableinfo.relkind, schemaname, relationname); + tableinfo.relkind, schemaname, relationname); break; } @@ -818,9 +821,10 @@ describeOneTableDetails(const char *schemaname, { /* Footer information about an index */ PGresult *result; + printfPQExpBuffer(&buf, - "SELECT i.indisunique, i.indisprimary, a.amname, c2.relname,\n" - " pg_catalog.pg_get_expr(i.indpred, i.indrelid)\n" + "SELECT i.indisunique, i.indisprimary, a.amname, c2.relname,\n" + " pg_catalog.pg_get_expr(i.indpred, i.indrelid)\n" "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n" "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n" "AND i.indrelid = c2.oid", @@ -878,10 +882,10 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.hasrules) { printfPQExpBuffer(&buf, - "SELECT r.rulename\n" - "FROM pg_catalog.pg_rewrite r\n" - "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN'", - oid); + "SELECT r.rulename\n" + "FROM pg_catalog.pg_rewrite r\n" + "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN'", + oid); result = PSQLexec(buf.data); if (!result) goto error_return; @@ -934,12 +938,12 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.hasindex) { printfPQExpBuffer(&buf, - "SELECT c2.relname, i.indisprimary, i.indisunique, " - "pg_catalog.pg_get_indexdef(i.indexrelid)\n" - "FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n" - "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n" - "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname", - oid); + "SELECT c2.relname, i.indisprimary, i.indisunique, " + "pg_catalog.pg_get_indexdef(i.indexrelid)\n" + "FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n" + "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n" + "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname", + oid); result1 = PSQLexec(buf.data); if (!result1) goto error_return; @@ -951,10 +955,10 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.checks) { printfPQExpBuffer(&buf, - "SELECT consrc, conname\n" - "FROM pg_catalog.pg_constraint r\n" - "WHERE r.conrelid = '%s' AND r.contype = 'c'", - oid); + "SELECT consrc, conname\n" + "FROM pg_catalog.pg_constraint r\n" + "WHERE r.conrelid = '%s' AND r.contype = 'c'", + oid); result2 = PSQLexec(buf.data); if (!result2) goto error_return; @@ -966,10 +970,10 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.hasrules) { printfPQExpBuffer(&buf, - "SELECT r.rulename\n" - "FROM pg_catalog.pg_rewrite r\n" - "WHERE r.ev_class = '%s'", - oid); + "SELECT r.rulename\n" + "FROM pg_catalog.pg_rewrite r\n" + "WHERE r.ev_class = '%s'", + oid); result3 = PSQLexec(buf.data); if (!result3) goto error_return; @@ -981,15 +985,15 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.triggers) { printfPQExpBuffer(&buf, - "SELECT t.tgname\n" - "FROM pg_catalog.pg_trigger t\n" - "WHERE t.tgrelid = '%s' " - "and (not tgisconstraint " - " OR NOT EXISTS" - " (SELECT 1 FROM pg_catalog.pg_depend d " - " JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) " - " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))", - oid); + "SELECT t.tgname\n" + "FROM pg_catalog.pg_trigger t\n" + "WHERE t.tgrelid = '%s' " + "and (not tgisconstraint " + " OR NOT EXISTS" + " (SELECT 1 FROM pg_catalog.pg_depend d " + " JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) " + " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))", + oid); result4 = PSQLexec(buf.data); if (!result4) goto error_return; @@ -997,15 +1001,15 @@ describeOneTableDetails(const char *schemaname, trigger_count = PQntuples(result4); } - /* count foreign-key constraints (there are none if no triggers) */ + /* count foreign-key constraints (there are none if no triggers) */ if (tableinfo.triggers) { printfPQExpBuffer(&buf, - "SELECT conname,\n" - " pg_catalog.pg_get_constraintdef(oid) as condef\n" - "FROM pg_catalog.pg_constraint r\n" - "WHERE r.conrelid = '%s' AND r.contype = 'f'", - oid); + "SELECT conname,\n" + " pg_catalog.pg_get_constraintdef(oid) as condef\n" + "FROM pg_catalog.pg_constraint r\n" + "WHERE r.conrelid = '%s' AND r.contype = 'f'", + oid); result5 = PSQLexec(buf.data); if (!result5) goto error_return; @@ -1022,7 +1026,7 @@ describeOneTableDetails(const char *schemaname, char *s = _("Indexes"); const char *indexdef; const char *usingpos; - + if (i == 0) printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result1, i, 0)); @@ -1032,9 +1036,9 @@ describeOneTableDetails(const char *schemaname, /* Label as primary key or unique (but not both) */ appendPQExpBuffer(&buf, - strcmp(PQgetvalue(result1,i,1),"t") == 0 + strcmp(PQgetvalue(result1, i, 1), "t") == 0 ? _(" primary key") : - (strcmp(PQgetvalue(result1,i,2),"t") == 0 + (strcmp(PQgetvalue(result1, i, 2), "t") == 0 ? _(" unique") : "")); @@ -1184,18 +1188,18 @@ describeUsers(const char *pattern) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT u.usename AS \"%s\",\n" - " u.usesysid AS \"%s\",\n" - " CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n" - " WHEN u.usesuper THEN CAST('%s' AS pg_catalog.text)\n" - " WHEN u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n" - " ELSE CAST('' AS pg_catalog.text)\n" - " END AS \"%s\"\n" - "FROM pg_catalog.pg_user u\n", - _("User name"), _("User ID"), - _("superuser, create database"), - _("superuser"), _("create database"), - _("Attributes")); + "SELECT u.usename AS \"%s\",\n" + " u.usesysid AS \"%s\",\n" + " CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n" + " WHEN u.usesuper THEN CAST('%s' AS pg_catalog.text)\n" + " WHEN u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n" + " ELSE CAST('' AS pg_catalog.text)\n" + " END AS \"%s\"\n" + "FROM pg_catalog.pg_user u\n", + _("User name"), _("User ID"), + _("superuser, create database"), + _("superuser"), _("create database"), + _("Attributes")); processNamePattern(&buf, pattern, false, false, NULL, "u.usename", NULL, NULL); @@ -1249,32 +1253,32 @@ listTables(const char *tabtypes, const char *pattern, bool verbose) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT n.nspname as \"%s\",\n" - " c.relname as \"%s\",\n" - " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' WHEN 's' THEN '%s' END as \"%s\",\n" - " u.usename as \"%s\"", - _("Schema"), _("Name"), - _("table"), _("view"), _("index"), _("sequence"), - _("special"), _("Type"), _("Owner")); + "SELECT n.nspname as \"%s\",\n" + " c.relname as \"%s\",\n" + " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' WHEN 's' THEN '%s' END as \"%s\",\n" + " u.usename as \"%s\"", + _("Schema"), _("Name"), + _("table"), _("view"), _("index"), _("sequence"), + _("special"), _("Type"), _("Owner")); if (verbose) appendPQExpBuffer(&buf, - ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"", - _("Description")); + ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"", + _("Description")); - if (showIndexes) + if (showIndexes) appendPQExpBuffer(&buf, ",\n c2.relname as \"%s\"" "\nFROM pg_catalog.pg_class c" - "\n JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid" - "\n JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid" - "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner" + "\n JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid" + "\n JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid" + "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner" "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n", _("Table")); else appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_class c" - "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner" + "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner" "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"); appendPQExpBuffer(&buf, "WHERE c.relkind IN ("); @@ -1288,12 +1292,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose) appendPQExpBuffer(&buf, "'S',"); if (showSystem && showTables) appendPQExpBuffer(&buf, "'s',"); - appendPQExpBuffer(&buf, "''"); /* dummy */ + appendPQExpBuffer(&buf, "''"); /* dummy */ appendPQExpBuffer(&buf, ")\n"); /* - * Unless showSystem is specified, we suppress system tables, ie, those - * in pg_catalog and pg_toast. (We don't want to hide temp tables though.) + * Unless showSystem is specified, we suppress system tables, ie, + * those in pg_catalog and pg_toast. (We don't want to hide temp + * tables though.) */ if (showSystem) processNamePattern(&buf, pattern, true, false, @@ -1346,21 +1351,21 @@ listDomains(const char *pattern) initPQExpBuffer(&buf); printfPQExpBuffer(&buf, - "SELECT n.nspname as \"%s\",\n" - " t.typname as \"%s\",\n" - " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n" - " CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n" - " WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n" - " WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n" - " ELSE ''\n" - " END as \"%s\"\n" - "FROM pg_catalog.pg_type t\n" - " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n" - "WHERE t.typtype = 'd'\n", - _("Schema"), - _("Name"), - _("Type"), - _("Modifier")); + "SELECT n.nspname as \"%s\",\n" + " t.typname as \"%s\",\n" + " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n" + " CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n" + " WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n" + " WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n" + " ELSE ''\n" + " END as \"%s\"\n" + "FROM pg_catalog.pg_type t\n" + " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n" + "WHERE t.typtype = 'd'\n", + _("Schema"), + _("Name"), + _("Type"), + _("Modifier")); processNamePattern(&buf, pattern, true, false, "n.nspname", "t.typname", NULL, @@ -1397,7 +1402,7 @@ listDomains(const char *pattern) * namevar: name of WHERE variable to match against an object-name pattern. * altnamevar: NULL, or name of an alternate variable to match against name. * visibilityrule: clause to use if we want to restrict to visible objects - * (for example, "pg_catalog.pg_table_is_visible(p.oid)"). Can be NULL. + * (for example, "pg_catalog.pg_table_is_visible(p.oid)"). Can be NULL. */ static void processNamePattern(PQExpBuffer buf, const char *pattern, @@ -1479,10 +1484,11 @@ processNamePattern(PQExpBuffer buf, const char *pattern, * Ordinary data character, transfer to pattern * * Inside double quotes, or at all times if parsing an operator - * name, quote regexp special characters with a backslash to avoid - * regexp errors. Outside quotes, however, let them pass through - * as-is; this lets knowledgeable users build regexp expressions - * that are more powerful than shell-style patterns. + * name, quote regexp special characters with a backslash to + * avoid regexp errors. Outside quotes, however, let them + * pass through as-is; this lets knowledgeable users build + * regexp expressions that are more powerful than shell-style + * patterns. */ if ((inquotes || force_escape) && strchr("|*+?()[]{}.^$\\", *cp)) @@ -1511,8 +1517,8 @@ processNamePattern(PQExpBuffer buf, const char *pattern, appendPQExpBufferChar(&schemabuf, '$'); /* Optimize away ".*$", and possibly the whole pattern */ if (schemabuf.len >= 3 && - strcmp(schemabuf.data + (schemabuf.len-3), ".*$") == 0) - schemabuf.data[schemabuf.len-3] = '\0'; + strcmp(schemabuf.data + (schemabuf.len - 3), ".*$") == 0) + schemabuf.data[schemabuf.len - 3] = '\0'; if (schemabuf.data[0] && schemavar) { @@ -1538,8 +1544,8 @@ processNamePattern(PQExpBuffer buf, const char *pattern, appendPQExpBufferChar(&namebuf, '$'); /* Optimize away ".*$", and possibly the whole pattern */ if (namebuf.len >= 3 && - strcmp(namebuf.data + (namebuf.len-3), ".*$") == 0) - namebuf.data[namebuf.len-3] = '\0'; + strcmp(namebuf.data + (namebuf.len - 3), ".*$") == 0) + namebuf.data[namebuf.len - 3] = '\0'; if (namebuf.data[0]) { diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index a224898d12..45d9c1e2f9 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.55 2002/08/27 18:28:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.56 2002/09/04 20:31:35 momjian Exp $ */ #include "postgres_fe.h" #include "print.h" @@ -70,13 +70,13 @@ usage(void) psql_error("could not get current user name: %s\n", strerror(errno)); exit(EXIT_FAILURE); } -#else /* WIN32 */ +#else /* WIN32 */ char buf[128]; DWORD bufsize = sizeof(buf) - 1; if (GetUserName(buf, &bufsize)) user = buf; -#endif /* WIN32 */ +#endif /* WIN32 */ } /* If this " is the start of the string then it ought to end there to fit in 80 columns >> " */ @@ -161,7 +161,8 @@ struct winsize void slashUsage(bool pager) { - FILE *output, *pagerfd = NULL; + FILE *output, + *pagerfd = NULL; /* check whether we need / can / are supposed to use pager */ if (pager @@ -202,10 +203,14 @@ slashUsage(bool pager) output = stdout; /* if you add/remove a line here, change the row test above */ - /* 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 >> " + */ fprintf(output, _(" \\a toggle between unaligned and aligned output mode\n")); fprintf(output, _(" \\c[onnect] [DBNAME|- [USER]]\n" - " connect to new database (currently \"%s\")\n"), + " connect to new database (currently \"%s\")\n"), PQdb(pset.db)); fprintf(output, _(" \\C [STRING] set table title, or unset if none\n")); fprintf(output, _(" \\cd [DIR] change the current working directory\n")); @@ -234,11 +239,11 @@ slashUsage(bool pager) fprintf(output, _(" \\i FILE execute commands from file\n")); fprintf(output, _(" \\l list all databases\n")); fprintf(output, _(" \\lo_export, \\lo_import, \\lo_list, \\lo_unlink\n" - " large object operations\n")); + " large object operations\n")); fprintf(output, _(" \\o FILE send all query results to file or |pipe\n")); fprintf(output, _(" \\p show the contents of the query buffer\n")); fprintf(output, _(" \\pset NAME [VALUE] set table output option (NAME := {format|border|expanded|\n" - " fieldsep|null|recordsep|tuples_only|title|tableattr|pager})\n")); + " fieldsep|null|recordsep|tuples_only|title|tableattr|pager})\n")); fprintf(output, _(" \\q quit psql\n")); fprintf(output, _(" \\qecho [STRING] write string to query output stream (see \\o)\n")); fprintf(output, _(" \\r reset (clear) the query buffer\n")); diff --git a/src/bin/psql/input.h b/src/bin/psql/input.h index e893b8c539..fbb52f20da 100644 --- a/src/bin/psql/input.h +++ b/src/bin/psql/input.h @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.16 2002/04/10 22:47:03 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.17 2002/09/04 20:31:36 momjian Exp $ */ #ifndef INPUT_H #define INPUT_H @@ -15,17 +15,17 @@ * USE_READLINE is the definite pointers regarding existence or not. */ #ifdef HAVE_LIBREADLINE -# define USE_READLINE 1 -# if defined(HAVE_READLINE_READLINE_H) -# include <readline/readline.h> -# elif defined(HAVE_READLINE_H) -# include <readline.h> -# endif -# if defined(HAVE_READLINE_HISTORY_H) -# include <readline/history.h> -# elif defined(HAVE_HISTORY_H) -# include <history.h> -# endif +#define USE_READLINE 1 +#if defined(HAVE_READLINE_READLINE_H) +#include <readline/readline.h> +#elif defined(HAVE_READLINE_H) +#include <readline.h> +#endif +#if defined(HAVE_READLINE_HISTORY_H) +#include <readline/history.h> +#elif defined(HAVE_HISTORY_H) +#include <history.h> +#endif #endif char *gets_interactive(char *prompt); diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c index 0e90fceb6c..2bca9da05e 100644 --- a/src/bin/psql/large_obj.c +++ b/src/bin/psql/large_obj.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.20 2002/08/10 03:56:24 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.21 2002/09/04 20:31:36 momjian Exp $ */ #include "postgres_fe.h" #include "large_obj.h" @@ -358,7 +358,7 @@ do_lo_list(void) snprintf(buf, sizeof(buf), "SELECT loid as \"ID\", pg_catalog.obj_description(loid, 'pg_largeobject') as \"%s\"\n" - "FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) x\n" + "FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) x\n" "ORDER BY \"ID\"", gettext("Description")); diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c index d3fe2657b4..6d9367f761 100644 --- a/src/bin/psql/mainloop.c +++ b/src/bin/psql/mainloop.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.49 2002/07/03 16:47:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.50 2002/09/04 20:31:36 momjian Exp $ */ #include "postgres_fe.h" #include "mainloop.h" @@ -396,15 +396,15 @@ MainLoop(FILE *source) if (i < len) { - thislen = PQmblen(line+i, pset.encoding); + thislen = PQmblen(line + i, pset.encoding); goto rescan; /* reparse the just substituted */ } } else { /* - * if the variable doesn't exist we'll leave the string as - * is ... move on ... + * if the variable doesn't exist we'll leave the + * string as is ... move on ... */ } } diff --git a/src/bin/psql/print.h b/src/bin/psql/print.h index bcb3495bc6..09ec685bfe 100644 --- a/src/bin/psql/print.h +++ b/src/bin/psql/print.h @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.13 2002/07/15 01:56:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.14 2002/09/04 20:31:36 momjian Exp $ */ #ifndef PRINT_H #define PRINT_H @@ -72,7 +72,7 @@ typedef struct _printQueryOpt * * It calls the printTable above with all the things set straight. */ -void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout); +void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout); #ifndef __CYGWIN__ #define DEFAULT_PAGER "more" diff --git a/src/bin/psql/sprompt.c b/src/bin/psql/sprompt.c index 183b8e97ed..d05b294bfa 100644 --- a/src/bin/psql/sprompt.c +++ b/src/bin/psql/sprompt.c @@ -3,13 +3,13 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.2 2002/07/06 20:14:58 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.3 2002/09/04 20:31:36 momjian Exp $ */ /* This file is shared by psql and pg_dump. */ - + /* * simple_prompt * @@ -28,7 +28,7 @@ #include <termios.h> #endif -bool prompt_state = false; +bool prompt_state = false; extern char *simple_prompt(const char *prompt, int maxlen, bool echo); char * diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index a93219d22f..ef84d9410b 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.63 2002/08/27 20:16:48 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.64 2002/09/04 20:31:36 momjian Exp $ */ #include "postgres_fe.h" @@ -11,7 +11,7 @@ #ifndef WIN32 #include <unistd.h> -#else /* WIN32 */ +#else /* WIN32 */ #include <io.h> #include <windows.h> #include <win32.h> @@ -541,7 +541,11 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) } break; #ifndef HAVE_GETOPT_LONG - /* FreeBSD has a broken getopt that causes this test to fail. */ + + /* + * FreeBSD has a broken getopt that causes this test to + * fail. + */ case '-': fprintf(stderr, gettext("%s was compiled without support for long options.\n" diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index cc95a602dd..ce4a2b5a80 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.63 2002/09/02 06:19:38 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.64 2002/09/04 20:31:36 momjian Exp $ */ /*---------------------------------------------------------------------- @@ -145,7 +145,8 @@ pgsql_thing_t words_after_create[] = { {"FUNCTION", "SELECT DISTINCT proname FROM pg_catalog.pg_proc WHERE substr(proname,1,%d)='%s'"}, {"GROUP", "SELECT groname FROM pg_catalog.pg_group WHERE substr(groname,1,%d)='%s'"}, {"INDEX", Query_for_list_of_indexes}, - {"OPERATOR", NULL}, /* Querying for this is probably not such a good idea. */ + {"OPERATOR", NULL}, /* Querying for this is probably not such + * a good idea. */ {"RULE", "SELECT rulename FROM pg_catalog.pg_rules WHERE substr(rulename,1,%d)='%s'"}, {"SCHEMA", "SELECT nspname FROM pg_catalog.pg_namespace WHERE substr(nspname,1,%d)='%s'"}, {"SEQUENCE", "SELECT relname FROM pg_catalog.pg_class WHERE relkind='S' and substr(relname,1,%d)='%s'"}, @@ -330,7 +331,8 @@ psql_completion(char *text, int start, int end) } /* - * If we detect ALTER TABLE <name>, suggest either ADD, ALTER, or RENAME + * If we detect ALTER TABLE <name>, suggest either ADD, ALTER, or + * RENAME */ else if (strcasecmp(prev3_wd, "ALTER") == 0 && strcasecmp(prev2_wd, "TABLE") == 0) { @@ -400,8 +402,8 @@ psql_completion(char *text, int start, int end) { char *list_COMMENT[] = {"DATABASE", "INDEX", "RULE", "SCHEMA", "SEQUENCE", "TABLE", "TYPE", "VIEW", - "COLUMN", "AGGREGATE", "FUNCTION", "OPERATOR", "TRIGGER", "CONSTRAINT", - "DOMAIN", NULL}; + "COLUMN", "AGGREGATE", "FUNCTION", "OPERATOR", "TRIGGER", "CONSTRAINT", + "DOMAIN", NULL}; COMPLETE_WITH_LIST(list_COMMENT); } @@ -604,7 +606,7 @@ psql_completion(char *text, int start, int end) else if (strcasecmp(prev2_wd, "INSERT") == 0 && strcasecmp(prev_wd, "INTO") == 0) COMPLETE_WITH_QUERY(Query_for_list_of_tables); /* Complete "INSERT INTO <table> (" with attribute names */ - else if (rl_line_buffer[start-1]=='(' && strcasecmp(prev3_wd, "INSERT") == 0 && strcasecmp(prev2_wd, "INTO") == 0) + else if (rl_line_buffer[start - 1] == '(' && strcasecmp(prev3_wd, "INSERT") == 0 && strcasecmp(prev2_wd, "INTO") == 0) COMPLETE_WITH_ATTR(prev_wd); /* @@ -614,13 +616,15 @@ psql_completion(char *text, int start, int end) else if (strcasecmp(prev3_wd, "INSERT") == 0 && strcasecmp(prev2_wd, "INTO") == 0) { char *list_INSERT[] = {"DEFAULT VALUES", "SELECT", "VALUES", NULL}; + COMPLETE_WITH_LIST(list_INSERT); } /* Complete INSERT INTO <table> (attribs) with "VALUES" or "SELECT" */ else if (strcasecmp(prev4_wd, "INSERT") == 0 && strcasecmp(prev3_wd, "INTO") == 0 && - prev_wd[strlen(prev_wd)-1]==')') + prev_wd[strlen(prev_wd) - 1] == ')') { char *list_INSERT[] = {"SELECT", "VALUES", NULL}; + COMPLETE_WITH_LIST(list_INSERT); } @@ -631,25 +635,26 @@ psql_completion(char *text, int start, int end) /* LOCK */ /* Complete LOCK [TABLE] with a list of tables */ else if ((strcasecmp(prev_wd, "LOCK") == 0) || - (strcasecmp(prev_wd, "TABLE") == 0 && strcasecmp(prev2_wd, "LOCK"))) + (strcasecmp(prev_wd, "TABLE") == 0 && strcasecmp(prev2_wd, "LOCK"))) COMPLETE_WITH_QUERY(Query_for_list_of_tables); /* For the following, handle the case of a single table only for now */ /* Complete LOCK [TABLE] <table> with "IN" */ - else if ((strcasecmp(prev2_wd, "LOCK") == 0 && strcasecmp(prev_wd, "TABLE")) || + else if ((strcasecmp(prev2_wd, "LOCK") == 0 && strcasecmp(prev_wd, "TABLE")) || (strcasecmp(prev2_wd, "TABLE") == 0 && strcasecmp(prev3_wd, "LOCK") == 0)) - COMPLETE_WITH_CONST("IN"); + COMPLETE_WITH_CONST("IN"); /* Complete LOCK [TABLE] <table> IN with a lock mode */ else if (strcasecmp(prev_wd, "IN") == 0 && (strcasecmp(prev3_wd, "LOCK") == 0 || - (strcasecmp(prev3_wd, "TABLE") == 0 && strcasecmp(prev3_wd, "LOCK")))) + (strcasecmp(prev3_wd, "TABLE") == 0 && strcasecmp(prev3_wd, "LOCK")))) { - char *lock_modes[] = {"ACCESS SHARE MODE", "ROW SHARE MODE", "ROW EXCLUSIVE MODE", - "SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", "SHARE ROW EXCLUSIVE MODE", - "EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE", NULL}; - COMPLETE_WITH_LIST(lock_modes); + char *lock_modes[] = {"ACCESS SHARE MODE", "ROW SHARE MODE", "ROW EXCLUSIVE MODE", + "SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", "SHARE ROW EXCLUSIVE MODE", + "EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE", NULL}; + + COMPLETE_WITH_LIST(lock_modes); } /* NOTIFY */ @@ -784,7 +789,7 @@ psql_completion(char *text, int start, int end) /* WHERE */ /* Simple case of the word before the where being the table name */ - else if (strcasecmp(prev_wd, "WHERE") == 0) + else if (strcasecmp(prev_wd, "WHERE") == 0) COMPLETE_WITH_ATTR(prev2_wd); /* ... FROM ... */ @@ -1063,7 +1068,7 @@ previous_word(int point, int skip) int i, start = 0, end = -1, - inquotes=0; + inquotes = 0; char *s; while (skip-- >= 0) @@ -1093,11 +1098,12 @@ previous_word(int point, int skip) * last character before any space going backwards from the end, * or it's simply character 0 */ - for (start = end; start > 0; start--) { - if (rl_line_buffer[start] == '"') - inquotes = !inquotes; - if ((rl_line_buffer[start - 1] == ' ') && inquotes==0) - break; + for (start = end; start > 0; start--) + { + if (rl_line_buffer[start] == '"') + inquotes = !inquotes; + if ((rl_line_buffer[start - 1] == ' ') && inquotes == 0) + break; } point = start; |
