* indexes
* aggregates
* operators
- * ACL - grant/revoke
+ * privileges
*
* the output script is SQL that is understood by PostgreSQL
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.220 2001/08/10 22:50:09 tgl Exp $
- *
- * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
- *
- * Applied 'insert string' patch from "Marc G. Fournier" <scrappy@ki.net>
- * Added '-t table' option
- * Added '-a' option
- * Added '-da' option
- *
- * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
- *
- * - Fixed dumpTable output to output lengths for char and varchar types!
- * - Added single. quote to twin single quote expansion for 'insert' string
- * mode.
- *
- * Modifications - 7/26/96 - asussman@vidya.com
- *
- * - Fixed ouput lengths for char and varchar type where the length is variable (-1)
- *
- * Modifications - 6/1/97 - igor@sba.miami.edu
- * - Added functions to free allocated memory used for retrieving
- * indexes,tables,inheritance,types,functions and aggregates.
- * No more leaks reported by Purify.
- *
- *
- * Modifications - 1/26/98 - pjlobo@euitt.upm.es
- * - Added support for password authentication
- *
- * Modifications - 28-Jun-2000 - Philip Warner pjw@rhyme.com.au
- * - Used custom IO routines to allow for more
- * output formats and simple rearrangement of order.
- * - Discouraged operations more appropriate to the 'restore'
- * operation. (eg. -c "clear schema" - now always dumps
- * commands, but pg_restore can be told not to output them).
- * - Added RI warnings to the 'as insert strings' output mode
- * - Added a small number of comments
- * - Added a -Z option for compression level on compressed formats
- * - Restored '-f' in usage output
- *
- *
- * Modifications - 17-Jul-2000 - Philip Warner pjw@rhyme.com.au
- * - Support for BLOB output.
- * - Sort archive by OID, put some items at end (out of OID order)
- *
- * Modifications - 28-Jul-2000 - pjw@rhyme.com.au (1.45)
- *
- * Added --create, --no-owner, --superuser, --no-reconnect (pg_dump & pg_restore)
- * Added code to dump 'Create Schema' statement (pg_dump)
- * Don't bother to disable/enable triggers if we don't have a superuser (pg_restore)
- * Cleaned up code for reconnecting to database.
- * Force a reconnect as superuser before enabling/disabling triggers.
- *
- * Modifications - 31-Jul-2000 - pjw@rhyme.com.au (1.46, 1.47)
- * Added & Removed --throttle (pg_dump)
- * Fixed minor bug in language dumping code: expbuffres were not being reset.
- * Fixed version number initialization in _allocAH (pg_backup_archiver.c)
- *
- * Modifications - 14-Sep-2000 - pjw@rhyme.com.au
- * Use symbols for tests on relkind (ie. use RELKIND_VIEW, not 'v')
- * Support for relkind = RELKIND_VIEW.
- * Fix bug in support for -b option (== --blobs).
- * Dump views as views (using 'create view').
- * Remove 'isViewRule' since we check the relkind when getting tables.
- * Now uses temp table 'pgdump_oid' rather than 'pg_dump_oid' (errors otherwise).
- *
- * Modifications - 02-Oct-2000 - pjw@rhyme.com.au
- *
- * - Be more paranoid when getting views: call get_viewdef in separate statement
- * so we can be more informative in error messages.
- * - Support for 'isstrict' procedure attribute.
- * - Disable --blobs and --table since (a) it's a pain to get ONLY the blobs for the
- * table with the currently implementation, and (b) it's not clear how to restore
- * a partial BLOB backup (given the current OID-based BLOB implementation).
- *
- * Modifications - 04-Jan-2001 - pjw@rhyme.com.au
- *
- * - Check ntuples == 1 for various SELECT statements.
- * - Fix handling of --tables=* (multiple tables never worked properly, AFAICT)
- *
- * Modifications - 13-Feb-2001 - pjw@rhyme.com.au
- *
- * - Fix help output: replace 'f' with 't' and change desc.
- * - Add extra arg to formatStringLiteral to specify how to handle LF & TAB.
- * I opted for encoding them except in procedure bodies.
- * - Dump relevant parts of sequences only when doing schemaOnly & dataOnly
- * - Prevent double-dumping of sequences when dataOnly.
- *
- * Modifications - 19-Mar-2001 - pjw@rhyme.com.au
- *
- * - Remove fmtId calls for all ArchiveEntry name fields. This fixes
- * quoting problems in trigger enable/disable code for mixed case
- * table names, and avoids commands like 'pg_restore -t '"TblA"''
- *
- * Modifications - 31-Mar-2001 - pjw@rhyme.com.au
- *
- * - Dump dependency information in dumpType. This is necessary
- * because placeholder types will have an OID less than the
- * OID of the type functions, but type must be created after
- * the functions.
- *
- * Modifications - 4-Apr-2001 - pjw@rhyme.com.au
- *
- * - Don't dump CHECK constraints with same source and names both
- * starting with '$'.
- *
- * Modifications - 10-May-2001 - pjw@rhyme.com.au
- *
- * - Don't dump COMMENTs in data-only dumps
- * - Fix view dumping SQL for V7.0
- * - Fix bug when getting view oid with long view names
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.221 2001/08/12 19:02:39 petere Exp $
*
*-------------------------------------------------------------------------
*/
static void setMaxOid(Archive *fout);
static void AddAcl(char *aclbuf, const char *keyword);
-static char *GetPrivileges(const char *s);
+static char *GetPrivileges(Archive *AH, const char *s);
static int dumpBlobs(Archive *AH, char *, void *);
static int dumpDatabase(Archive *AH);
" -c, --clean clean (drop) schema prior to create\n"
" -C, --create include commands to create database in dump\n"
" -d, --inserts dump data as INSERT, rather than COPY, commands\n"
- " -D, --attribute-inserts dump data as INSERT commands with column names\n"
+ " -D, --column-inserts dump data as INSERT commands with column names\n"
" -f, --file=FILENAME output file name\n"
" -F, --format {c|t|p} output file format (custom, tar, plain text)\n"
" -h, --host=HOSTNAME database server host name\n"
" -U, --username=NAME connect as specified database user\n"
" -v, --verbose verbose mode\n"
" -W, --password force password prompt (should happen automatically)\n"
- " -x, --no-acl do not dump privileges (grant/revoke)\n"
+ " -x, --no-privileges do not dump privileges (grant/revoke)\n"
" -Z, --compress {0-9} compression level for compressed formats\n"
));
#else
}
}
+
+
+static int
+parse_version(const char* versionString)
+{
+ int cnt;
+ int vmaj, vmin, vrev;
+
+ cnt = sscanf(versionString, "%d.%d.%d", &vmaj, &vmin, &vrev);
+
+ if (cnt < 2)
+ {
+ write_msg(NULL, "unable to parse version string \"%s\"\n", versionString);
+ exit(1);
+ }
+
+ if (cnt == 2)
+ vrev = 0;
+
+ return (100 * vmaj + vmin) * 100 + vrev;
+}
+
+
+
int
main(int argc, char **argv)
{
{"format", required_argument, NULL, 'F'},
{"inserts", no_argument, NULL, 'd'},
{"attribute-inserts", no_argument, NULL, 'D'},
+ {"column-inserts", no_argument, NULL, 'D'},
{"host", required_argument, NULL, 'h'},
{"ignore-version", no_argument, NULL, 'i'},
{"no-reconnect", no_argument, NULL, 'R'},
{"password", no_argument, NULL, 'W'},
{"username", required_argument, NULL, 'U'},
{"verbose", no_argument, NULL, 'v'},
+ {"no-privileges", no_argument, NULL, 'x'},
{"no-acl", no_argument, NULL, 'x'},
{"compress", required_argument, NULL, 'Z'},
{"help", no_argument, NULL, '?'},
/*
* Open the database using the Archiver, so it knows about it. Errors
- * mean death. Accept 7.0 & 7.1 database versions.
+ * mean death.
*/
- g_fout->minRemoteVersion = 70000;
- g_fout->maxRemoteVersion = 70199;
+ g_fout->minRemoteVersion = 70000; /* we can handle back to 7.0 */
+ g_fout->maxRemoteVersion = parse_version(PG_VERSION);
g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, username, force_password, ignore_version);
/*
* comma delimited string of SELECT,INSERT,UPDATE,DELETE,RULE
*/
static char *
-GetPrivileges(const char *s)
+GetPrivileges(Archive *AH, const char *s)
{
char aclbuf[100];
if (strchr(s, 'a'))
AddAcl(aclbuf, "INSERT");
- if (strchr(s, 'w'))
- AddAcl(aclbuf, "UPDATE,DELETE");
-
if (strchr(s, 'r'))
AddAcl(aclbuf, "SELECT");
if (strchr(s, 'R'))
AddAcl(aclbuf, "RULE");
- /* Special-case when they're all there */
- if (strcmp(aclbuf, "INSERT,UPDATE,DELETE,SELECT,RULE") == 0)
- return strdup("ALL");
+ if (AH->remoteVersion >= 70200)
+ {
+ if (strchr(s, 'w'))
+ AddAcl(aclbuf, "UPDATE");
+ if (strchr(s, 'd'))
+ AddAcl(aclbuf, "DELETE");
+ if (strchr(s, 'x'))
+ AddAcl(aclbuf, "REFERENCES");
+ if (strchr(s, 't'))
+ AddAcl(aclbuf, "TRIGGER");
+ }
+ else
+ {
+ if (strchr(s, 'w'))
+ AddAcl(aclbuf, "UPDATE,DELETE");
+ }
return strdup(aclbuf);
}
* Parse the privileges (right-hand side). Skip if there are
* none.
*/
- priv = GetPrivileges(eqpos + 1);
+ priv = GetPrivileges(fout, eqpos + 1);
if (*priv)
{
sprintf(tmp, "GRANT %s on %s to ",
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.22 2001/07/03 20:21:50 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.23 2001/08/12 19:02:39 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
{"dbname", 1, NULL, 'd'},
{"file", 1, NULL, 'f'},
{"format", 1, NULL, 'F'},
- {"function", 2, NULL, 'P'},
+ {"function", 1, NULL, 'P'},
{"host", 1, NULL, 'h'},
{"ignore-version", 0, NULL, 'i'},
- {"index", 2, NULL, 'I'},
+ {"index", 1, NULL, 'I'},
{"list", 0, NULL, 'l'},
+ {"no-privileges", 0, NULL, 'x'},
{"no-acl", 0, NULL, 'x'},
{"no-owner", 0, NULL, 'O'},
{"no-reconnect", 0, NULL, 'R'},
{"rearrange", 0, NULL, 'r'},
{"schema-only", 0, NULL, 's'},
{"superuser", 1, NULL, 'S'},
- {"table", 2, NULL, 't'},
- {"trigger", 2, NULL, 'T'},
+ {"table", 1, NULL, 't'},
+ {"trigger", 1, NULL, 'T'},
{"use-list", 1, NULL, 'L'},
{"username", 1, NULL, 'U'},
{"verbose", 0, NULL, 'v'},
" -f, --file=FILENAME script output file name\n"
" -F, --format {c|f} specify backup file format\n"
" -h, --host HOSTNAME server host name\n"
- " -i, --index[=NAME] restore indexes or named index\n"
+ " -i, --index=NAME restore indexes or named index\n"
" -l, --list dump summarized TOC for this file\n"
" -L, --use-list=FILENAME use specified table of contents for ordering\n"
" output from this file\n"
" -O, --no-owner do not reconnect to database to match\n"
" object owner\n"
" -p, --port PORT server port number\n"
- " -P, --function[=NAME] restore functions or named function\n"
+ " -P, --function=NAME restore functions or named function\n"
" -r, --rearrange rearrange output to put indexes etc. at end\n"
" -R, --no-reconnect disallow ALL reconnections to the database\n"
" -s, --schema-only restore only the schema, no data\n"
" -S, --superuser=NAME specify the superuser user name to use for\n"
" disabling triggers\n"
- " -t, --table[=TABLE] restore this table only\n"
- " -T, --trigger[=NAME] restore triggers or named trigger\n"
+ " -t, --table=TABLE restore this table only\n"
+ " -T, --trigger=NAME restore triggers or named trigger\n"
" -U, --username=NAME connect as specified database user\n"
" -v, --verbose verbose\n"
" -W, --password force password prompt (should happen automatically)\n"
- " -x, --no-acl skip dumping of ACLs (grant/revoke)\n"
+ " -x, --no-privileges skip dumping of access privileges (grant/revoke)\n"
));
#else /* not HAVE_GETOPT_LONG */