diff options
| author | Bruce Momjian | 2001-03-22 04:01:46 +0000 |
|---|---|---|
| committer | Bruce Momjian | 2001-03-22 04:01:46 +0000 |
| commit | 9e1552607a9dc6bc23e43d46770a9063ade4f3f0 (patch) | |
| tree | 6a230d81917ebc004e40cd46c48f2aa27eec153e /contrib/pg_dumplo | |
| parent | 6cf8707b828b14b5c2336076ce358b18b67829d6 (diff) | |
pgindent run. Make it all clean.
Diffstat (limited to 'contrib/pg_dumplo')
| -rw-r--r-- | contrib/pg_dumplo/lo_export.c | 172 | ||||
| -rw-r--r-- | contrib/pg_dumplo/lo_import.c | 86 | ||||
| -rw-r--r-- | contrib/pg_dumplo/main.c | 380 | ||||
| -rw-r--r-- | contrib/pg_dumplo/pg_dumplo.h | 73 | ||||
| -rw-r--r-- | contrib/pg_dumplo/utils.c | 85 |
5 files changed, 425 insertions, 371 deletions
diff --git a/contrib/pg_dumplo/lo_export.c b/contrib/pg_dumplo/lo_export.c index 5a2a1614a5..6a62c88bc6 100644 --- a/contrib/pg_dumplo/lo_export.c +++ b/contrib/pg_dumplo/lo_export.c @@ -1,20 +1,20 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.5 2001/01/24 19:42:44 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.6 2001/03/22 03:59:10 momjian Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- */ -#include <stdio.h> +#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> -#include <errno.h> +#include <errno.h> #include <time.h> #include <libpq-fe.h> @@ -22,17 +22,17 @@ #include "pg_dumplo.h" -extern int errno; +extern int errno; -void -load_lolist( LODumpMaster *pgLO ) +void +load_lolist(LODumpMaster * pgLO) { - LOlist *ll; - int i; - int n; + LOlist *ll; + int i; + int n; - /* ---------- + /* ---------- * Now find any candidate tables who have columns of type oid. * * NOTE: System tables including pg_largeobject will be ignored. @@ -40,8 +40,8 @@ load_lolist( LODumpMaster *pgLO ) * * NOTE: the system oid column is ignored, as it has attnum < 1. * This shouldn't matter for correctness, but it saves time. - * ---------- - */ + * ---------- + */ pgLO->res = PQexec(pgLO->conn, "SELECT c.relname, a.attname " "FROM pg_class c, pg_attribute a, pg_type t " @@ -52,43 +52,49 @@ load_lolist( LODumpMaster *pgLO ) " AND c.relkind = 'r' " " AND c.relname NOT LIKE 'pg_%'"); - if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK) { + if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK) + { fprintf(stderr, "%s: Failed to get LO OIDs:\n%s", progname, PQerrorMessage(pgLO->conn)); exit(RE_ERROR); } - if ((n = PQntuples(pgLO->res)) == 0) { + if ((n = PQntuples(pgLO->res)) == 0) + { fprintf(stderr, "%s: No OID columns in the database.\n", progname); exit(RE_ERROR); - } - + } + pgLO->lolist = (LOlist *) malloc((n + 1) * sizeof(LOlist)); - - if (!pgLO->lolist) { + + if (!pgLO->lolist) + { fprintf(stderr, "%s: can't allocate memory\n", progname); exit(RE_ERROR); - } - - for (i = 0, ll = pgLO->lolist; i < n; i++, ll++) { + } + + for (i = 0, ll = pgLO->lolist; i < n; i++, ll++) + { ll->lo_table = strdup(PQgetvalue(pgLO->res, i, 0)); - ll->lo_attr = strdup(PQgetvalue(pgLO->res, i, 1)); + ll->lo_attr = strdup(PQgetvalue(pgLO->res, i, 1)); } - ll->lo_table = ll->lo_attr = (char *) NULL; - + ll->lo_table = ll->lo_attr = (char *) NULL; + PQclear(pgLO->res); } -void -pglo_export(LODumpMaster *pgLO) +void +pglo_export(LODumpMaster * pgLO) { - LOlist *ll; - int tuples; + LOlist *ll; + int tuples; char path[BUFSIZ], - Qbuff[QUERY_BUFSIZ]; - - if (pgLO->action != ACTION_SHOW) { - time_t t; + Qbuff[QUERY_BUFSIZ]; + + if (pgLO->action != ACTION_SHOW) + { + time_t t; + time(&t); fprintf(pgLO->index, "#\n# This is the PostgreSQL large object dump index\n#\n"); fprintf(pgLO->index, "#\tDate: %s", ctime(&t)); @@ -97,90 +103,102 @@ pglo_export(LODumpMaster *pgLO) fprintf(pgLO->index, "#\tUser: %s\n", pgLO->user); fprintf(pgLO->index, "#\n# oid\ttable\tattribut\tinfile\n#\n"); } - + pgLO->counter = 0; - for(ll=pgLO->lolist; ll->lo_table != NULL; ll++) { - + for (ll = pgLO->lolist; ll->lo_table != NULL; ll++) + { + /* ---------- * Query: find the LOs referenced by this column * ---------- */ sprintf(Qbuff, "SELECT DISTINCT l.loid FROM \"%s\" x, pg_largeobject l WHERE x.\"%s\" = l.loid", ll->lo_table, ll->lo_attr); - + /* puts(Qbuff); */ - + pgLO->res = PQexec(pgLO->conn, Qbuff); - if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK) { + if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK) + { fprintf(stderr, "%s: Failed to get LO OIDs:\n%s", progname, PQerrorMessage(pgLO->conn)); - } - else if ((tuples = PQntuples(pgLO->res)) == 0) { + } + else if ((tuples = PQntuples(pgLO->res)) == 0) + { if (!pgLO->quiet && pgLO->action == ACTION_EXPORT_ATTR) printf("%s: no large objects in \"%s\".\"%s\"\n", - progname, ll->lo_table, ll->lo_attr); - } else { - - int t; - char *val; - + progname, ll->lo_table, ll->lo_attr); + } + else + { + + int t; + char *val; + /* ---------- * Create DIR/FILE * ---------- */ - if (pgLO->action != ACTION_SHOW) { - + if (pgLO->action != ACTION_SHOW) + { + sprintf(path, "%s/%s/%s", pgLO->space, pgLO->db, ll->lo_table); - if (mkdir(path, DIR_UMASK) == -1) { - if (errno != EEXIST) { + if (mkdir(path, DIR_UMASK) == -1) + { + if (errno != EEXIST) + { perror(path); - exit(RE_ERROR); - } + exit(RE_ERROR); + } } sprintf(path, "%s/%s/%s/%s", pgLO->space, pgLO->db, - ll->lo_table, ll->lo_attr); - - if (mkdir(path, DIR_UMASK) == -1) { - if (errno != EEXIST) { + ll->lo_table, ll->lo_attr); + + if (mkdir(path, DIR_UMASK) == -1) + { + if (errno != EEXIST) + { perror(path); - exit(RE_ERROR); - } + exit(RE_ERROR); + } } - + if (!pgLO->quiet) - printf("dump %s.%s (%d large obj)\n", - ll->lo_table, ll->lo_attr, tuples); + printf("dump %s.%s (%d large obj)\n", + ll->lo_table, ll->lo_attr, tuples); } pgLO->counter += tuples; - - for(t=0; t<tuples; t++) { - Oid lo; - + + for (t = 0; t < tuples; t++) + { + Oid lo; + val = PQgetvalue(pgLO->res, t, 0); - + lo = atooid(val); - - if (pgLO->action == ACTION_SHOW) { + + if (pgLO->action == ACTION_SHOW) + { printf("%s.%s: %u\n", ll->lo_table, ll->lo_attr, lo); continue; } - - sprintf(path, "%s/%s/%s/%s/%s", pgLO->space, - pgLO->db, ll->lo_table, ll->lo_attr, val); - - if (lo_export(pgLO->conn, lo, path) < 0) + + sprintf(path, "%s/%s/%s/%s/%s", pgLO->space, + pgLO->db, ll->lo_table, ll->lo_attr, val); + + if (lo_export(pgLO->conn, lo, path) < 0) fprintf(stderr, "%s: lo_export failed:\n%s", progname, PQerrorMessage(pgLO->conn)); - - else - fprintf(pgLO->index, "%s\t%s\t%s\t%s/%s/%s/%s\n", val, - ll->lo_table, ll->lo_attr, pgLO->db, ll->lo_table, ll->lo_attr, val); + + else + fprintf(pgLO->index, "%s\t%s\t%s\t%s/%s/%s/%s\n", val, + ll->lo_table, ll->lo_attr, pgLO->db, ll->lo_table, ll->lo_attr, val); } } diff --git a/contrib/pg_dumplo/lo_import.c b/contrib/pg_dumplo/lo_import.c index 996bdf9e27..ff8929d6d6 100644 --- a/contrib/pg_dumplo/lo_import.c +++ b/contrib/pg_dumplo/lo_import.c @@ -1,20 +1,20 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.3 2001/01/24 19:42:45 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.4 2001/03/22 03:59:10 momjian Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- */ -#include <stdio.h> +#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> -#include <errno.h> +#include <errno.h> #include <time.h> #include <libpq-fe.h> @@ -22,76 +22,82 @@ #include "pg_dumplo.h" -extern int errno; +extern int errno; -void -pglo_import(LODumpMaster *pgLO) +void +pglo_import(LODumpMaster * pgLO) { LOlist loa; - Oid new_oid; - char tab[MAX_TABLE_NAME], attr[MAX_ATTR_NAME], - path[BUFSIZ], lo_path[BUFSIZ], - Qbuff[QUERY_BUFSIZ]; - - while(fgets(Qbuff, QUERY_BUFSIZ, pgLO->index)) { - + Oid new_oid; + char tab[MAX_TABLE_NAME], + attr[MAX_ATTR_NAME], + path[BUFSIZ], + lo_path[BUFSIZ], + Qbuff[QUERY_BUFSIZ]; + + while (fgets(Qbuff, QUERY_BUFSIZ, pgLO->index)) + { + if (*Qbuff == '#') continue; - if (! pgLO->remove && ! pgLO->quiet) + if (!pgLO->remove && !pgLO->quiet) printf(Qbuff); - - sscanf(Qbuff, "%u\t%s\t%s\t%s\n", &loa.lo_oid, tab, attr, path); + + sscanf(Qbuff, "%u\t%s\t%s\t%s\n", &loa.lo_oid, tab, attr, path); loa.lo_table = tab; - loa.lo_attr = attr; + loa.lo_attr = attr; - sprintf(lo_path, "%s/%s", pgLO->space, path); + sprintf(lo_path, "%s/%s", pgLO->space, path); /* ---------- * Import LO * ---------- */ - if ((new_oid = lo_import(pgLO->conn, lo_path)) == 0) { - + if ((new_oid = lo_import(pgLO->conn, lo_path)) == 0) + { + fprintf(stderr, "%s: %s\n", progname, PQerrorMessage(pgLO->conn)); - + PQexec(pgLO->conn, "ROLLBACK"); fprintf(stderr, "\n%s: ROLLBACK\n", progname); exit(RE_ERROR); } - if (pgLO->remove) { + if (pgLO->remove) + { notice(pgLO, FALSE); - if (lo_unlink(pgLO->conn, loa.lo_oid) < 0) - fprintf(stderr, "%s: can't remove LO %u:\n%s", - progname, loa.lo_oid, PQerrorMessage(pgLO->conn)); - + if (lo_unlink(pgLO->conn, loa.lo_oid) < 0) + fprintf(stderr, "%s: can't remove LO %u:\n%s", + progname, loa.lo_oid, PQerrorMessage(pgLO->conn)); + else if (!pgLO->quiet) - printf("remove old %u and create new %u\n", - loa.lo_oid, new_oid); - notice(pgLO, TRUE); + printf("remove old %u and create new %u\n", + loa.lo_oid, new_oid); + notice(pgLO, TRUE); } - + pgLO->counter++; - + /* ---------- * UPDATE oid in tab * ---------- */ - sprintf(Qbuff, "UPDATE \"%s\" SET \"%s\"=%u WHERE \"%s\"=%u", + sprintf(Qbuff, "UPDATE \"%s\" SET \"%s\"=%u WHERE \"%s\"=%u", loa.lo_table, loa.lo_attr, new_oid, loa.lo_attr, loa.lo_oid); - /*fprintf(stderr, Qbuff);*/ - + /* fprintf(stderr, Qbuff); */ + pgLO->res = PQexec(pgLO->conn, Qbuff); - - if (PQresultStatus(pgLO->res) != PGRES_COMMAND_OK) { - fprintf(stderr, "%s: %s\n",progname, PQerrorMessage(pgLO->conn)); + + if (PQresultStatus(pgLO->res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "%s: %s\n", progname, PQerrorMessage(pgLO->conn)); PQclear(pgLO->res); PQexec(pgLO->conn, "ROLLBACK"); fprintf(stderr, "\n%s: ROLLBACK\n", progname); exit(RE_ERROR); - } + } PQclear(pgLO->res); - } - } + } +} diff --git a/contrib/pg_dumplo/main.c b/contrib/pg_dumplo/main.c index e8ff2f72e0..3878aeca02 100644 --- a/contrib/pg_dumplo/main.c +++ b/contrib/pg_dumplo/main.c @@ -1,7 +1,7 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.6 2001/02/10 02:31:25 tgl Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.7 2001/03/22 03:59:10 momjian Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- @@ -12,238 +12,254 @@ #include "postgres_fe.h" #endif -#include <stdio.h> +#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> -#include <errno.h> +#include <errno.h> #include <libpq-fe.h> #include <libpq/libpq-fs.h> -#include "pg_dumplo.h" +#include "pg_dumplo.h" #ifdef HAVE_GETOPT_LONG - #include <getopt.h> - #define no_argument 0 - #define required_argument 1 +#include <getopt.h> +#define no_argument 0 +#define required_argument 1 #endif - -extern int errno; -char *progname = NULL; +extern int errno; -int main(int argc, char **argv); +char *progname = NULL; + +int main(int argc, char **argv); static void usage(void); -static void parse_lolist (LODumpMaster *pgLO); - +static void parse_lolist(LODumpMaster * pgLO); + /*----- * The mother of all C functions *----- */ -int +int main(int argc, char **argv) -{ - LODumpMaster _pgLO, *pgLO = &_pgLO; - char *pwd = NULL; - - pgLO->argv = argv; - pgLO->argc = argc; - pgLO->action = 0; - pgLO->lolist = NULL; - pgLO->user = NULL; - pgLO->db = NULL; - pgLO->host = NULL; - pgLO->space = NULL; - pgLO->index = NULL; - pgLO->remove = FALSE; - pgLO->quiet = FALSE; - pgLO->counter = 0; +{ + LODumpMaster _pgLO, + *pgLO = &_pgLO; + char *pwd = NULL; + + pgLO->argv = argv; + pgLO->argc = argc; + pgLO->action = 0; + pgLO->lolist = NULL; + pgLO->user = NULL; + pgLO->db = NULL; + pgLO->host = NULL; + pgLO->space = NULL; + pgLO->index = NULL; + pgLO->remove = FALSE; + pgLO->quiet = FALSE; + pgLO->counter = 0; pgLO->lolist_start = 0; - + progname = argv[0]; /* ---------- * Parse ARGV * ---------- */ - if (argc > 1) { - int arg; - extern int optind; - -#ifdef HAVE_GETOPT_LONG - int l_index=0; - static struct option l_opt[] = { - { "help", no_argument, 0, 'h' }, - { "user", required_argument, 0, 'u' }, - { "pwd", required_argument, 0, 'p' }, - { "db", required_argument, 0, 'd' }, - { "host", required_argument, 0, 'h' }, - { "space", required_argument, 0, 's' }, - { "import", no_argument, 0, 'i' }, - { "export", no_argument, 0, 'e' }, - { "remove", no_argument, 0, 'r' }, - { "quiet", no_argument, 0, 'q' }, - { "all", no_argument, 0, 'a' }, - { "show", no_argument, 0, 'w' }, - { NULL, 0, 0, 0 } - }; - - while((arg = getopt_long(argc, argv, "?aehu:p:qd:l:t:irs:w", l_opt, &l_index)) != -1) { + if (argc > 1) + { + int arg; + extern int optind; + +#ifdef HAVE_GETOPT_LONG + int l_index = 0; + static struct option l_opt[] = { + {"help", no_argument, 0, 'h'}, + {"user", required_argument, 0, 'u'}, + {"pwd", required_argument, 0, 'p'}, + {"db", required_argument, 0, 'd'}, + {"host", required_argument, 0, 'h'}, + {"space", required_argument, 0, 's'}, + {"import", no_argument, 0, 'i'}, + {"export", no_argument, 0, 'e'}, + {"remove", no_argument, 0, 'r'}, + {"quiet", no_argument, 0, 'q'}, + {"all", no_argument, 0, 'a'}, + {"show", no_argument, 0, 'w'}, + {NULL, 0, 0, 0} + }; + + while ((arg = getopt_long(argc, argv, "?aehu:p:qd:l:t:irs:w", l_opt, &l_index)) != -1) + { #else - while((arg = getopt(argc, argv, "?aehu:p:qd:l:t:irs:w")) != -1) { + while ((arg = getopt(argc, argv, "?aehu:p:qd:l:t:irs:w")) != -1) + { #endif - switch(arg) { - case '?': - case 'h': - usage(); + switch (arg) + { + case '?': + case 'h': + usage(); exit(RE_OK); - case 'u': - pgLO->user = strdup(optarg); - break; - case 't': - pgLO->host = strdup(optarg); - break; - case 'p': - pwd = strdup(optarg); - break; - case 'd': - pgLO->db = strdup(optarg); - break; - case 's': - pgLO->space = strdup(optarg); - break; - case 'i': - pgLO->action = ACTION_IMPORT; - break; - case 'l': - pgLO->action = ACTION_EXPORT_ATTR; - pgLO->lolist_start = optind-1; - parse_lolist (pgLO); - break; - case 'e': - case 'a': + case 'u': + pgLO->user = strdup(optarg); + break; + case 't': + pgLO->host = strdup(optarg); + break; + case 'p': + pwd = strdup(optarg); + break; + case 'd': + pgLO->db = strdup(optarg); + break; + case 's': + pgLO->space = strdup(optarg); + break; + case 'i': + pgLO->action = ACTION_IMPORT; + break; + case 'l': + pgLO->action = ACTION_EXPORT_ATTR; + pgLO->lolist_start = optind - 1; + parse_lolist(pgLO); + break; + case 'e': + case 'a': pgLO->action = ACTION_EXPORT_ALL; break; case 'w': pgLO->action = ACTION_SHOW; - break; - case 'r': - pgLO->remove = TRUE; - break; - case 'q': - pgLO->quiet = TRUE; - break; - default: - fprintf(stderr, "%s: bad arg -%c\n", progname, arg); - usage(); - exit(RE_ERROR); + break; + case 'r': + pgLO->remove = TRUE; + break; + case 'q': + pgLO->quiet = TRUE; + break; + default: + fprintf(stderr, "%s: bad arg -%c\n", progname, arg); + usage(); + exit(RE_ERROR); } - } - } else { + } + } + else + { usage(); - exit(RE_ERROR); - } + exit(RE_ERROR); + } /* ---------- * Check space * ---------- */ - if (! pgLO->space && ! pgLO->action == ACTION_SHOW) { - if (!(pgLO->space = getenv("PWD"))) { + if (!pgLO->space && !pgLO->action == ACTION_SHOW) + { + if (!(pgLO->space = getenv("PWD"))) + { fprintf(stderr, "%s: not set space for dump-tree (option '-s' or $PWD).\n", progname); exit(RE_ERROR); - } + } } - - if (!pgLO->action) { + + if (!pgLO->action) + { fprintf(stderr, "%s: What do you want - export or import?\n", progname); exit(RE_ERROR); } - + /* ---------- * Make connection * ---------- */ - pgLO->conn = PQsetdbLogin(pgLO->host, NULL, NULL, NULL, pgLO->db, - pgLO->user, pwd); - - if (PQstatus(pgLO->conn) == CONNECTION_BAD) { + pgLO->conn = PQsetdbLogin(pgLO->host, NULL, NULL, NULL, pgLO->db, + pgLO->user, pwd); + + if (PQstatus(pgLO->conn) == CONNECTION_BAD) + { fprintf(stderr, "%s (connection): %s\n", progname, PQerrorMessage(pgLO->conn)); exit(RE_ERROR); - } + } pgLO->host = PQhost(pgLO->conn) ? PQhost(pgLO->conn) : "localhost"; - pgLO->db = PQdb(pgLO->conn); - pgLO->user = PQuser(pgLO->conn); - - + pgLO->db = PQdb(pgLO->conn); + pgLO->user = PQuser(pgLO->conn); + + /* ---------- * Init index file * ---------- */ - if (pgLO->action != ACTION_SHOW) + if (pgLO->action != ACTION_SHOW) index_file(pgLO); - + PQexec(pgLO->conn, "BEGIN"); - switch(pgLO->action) { - + switch (pgLO->action) + { + case ACTION_SHOW: case ACTION_EXPORT_ALL: load_lolist(pgLO); /* FALL THROUGH */ - + case ACTION_EXPORT_ATTR: pglo_export(pgLO); - if (!pgLO->quiet) { + if (!pgLO->quiet) + { if (pgLO->action == ACTION_SHOW) printf("\nDatabase '%s' contains %d large objects.\n\n", pgLO->db, pgLO->counter); - else + else printf("\nExported %d large objects.\n\n", pgLO->counter); } break; - + case ACTION_IMPORT: pglo_import(pgLO); if (!pgLO->quiet) printf("\nImported %d large objects.\n\n", pgLO->counter); - break; - } + break; + } PQexec(pgLO->conn, "COMMIT"); - PQfinish(pgLO->conn); - + PQfinish(pgLO->conn); + if (pgLO->action != ACTION_SHOW) fclose(pgLO->index); - + exit(RE_OK); } static void -parse_lolist (LODumpMaster *pgLO) +parse_lolist(LODumpMaster * pgLO) { - LOlist *ll; - char **d, - *loc, - buff[MAX_TABLE_NAME + MAX_ATTR_NAME +1]; + LOlist *ll; + char **d, + *loc, + buff[MAX_TABLE_NAME + MAX_ATTR_NAME + 1]; pgLO->lolist = (LOlist *) malloc(pgLO->argc * sizeof(LOlist)); - - if (! pgLO->lolist) { + + if (!pgLO->lolist) + { fprintf(stderr, "%s: can't allocate memory\n", progname); exit(RE_ERROR); } - - for( d=pgLO->argv + pgLO->lolist_start, ll=pgLO->lolist; - *d != NULL; - d++, ll++) { - + + for (d = pgLO->argv + pgLO->lolist_start, ll = pgLO->lolist; + *d != NULL; + d++, ll++) + { + strncpy(buff, *d, MAX_TABLE_NAME + MAX_ATTR_NAME); - - if ((loc = strchr(buff, '.')) == NULL) { + + if ((loc = strchr(buff, '.')) == NULL) + { fprintf(stderr, "%s: '%s' is bad 'table.attr'\n", progname, buff); - exit(RE_ERROR); + exit(RE_ERROR); } *loc = '\0'; ll->lo_table = strdup(buff); @@ -254,55 +270,55 @@ parse_lolist (LODumpMaster *pgLO) } -static void +static void usage() { printf("\npg_dumplo %s - PostgreSQL large objects dump\n", VERSION); - puts("pg_dumplo [option]\n\n" + puts("pg_dumplo [option]\n\n" #ifdef HAVE_GETOPT_LONG - - "-h --help this help\n" - "-u --user=<username> username for connection to server\n" - "-p --password=<password> password for connection to server\n" - "-d --db=<database> database name\n" - "-t --host=<hostname> server hostname\n" - "-s --space=<dir> directory with dump tree (for export/import)\n" - "-i --import import large obj dump tree to DB\n" - "-e --export export (dump) large obj to dump tree\n" - "-l <table.attr ...> dump attribute (columns) with LO to dump tree\n" - "-a --all dump all LO in DB (default)\n" - "-r --remove if is set '-i' try remove old LO\n" - "-q --quiet run quietly\n" - "-w --show not dump, but show all LO in DB\n" - ); /* puts() */ + + "-h --help this help\n" + "-u --user=<username> username for connection to server\n" + "-p --password=<password> password for connection to server\n" + "-d --db=<database> database name\n" + "-t --host=<hostname> server hostname\n" + "-s --space=<dir> directory with dump tree (for export/import)\n" + "-i --import import large obj dump tree to DB\n" + "-e --export export (dump) large obj to dump tree\n" + "-l <table.attr ...> dump attribute (columns) with LO to dump tree\n" + "-a --all dump all LO in DB (default)\n" + "-r --remove if is set '-i' try remove old LO\n" + "-q --quiet run quietly\n" + "-w --show not dump, but show all LO in DB\n" + ); /* puts() */ #else - "-h this help\n" - "-u <username> username for connection to server\n" - "-p <password> password for connection to server\n" - "-d <database> database name\n" - "-t <hostname> server hostname\n" - "-s <dir> directory with dump tree (for export/import)\n" - "-i import large obj dump tree to DB\n" - "-e export (dump) large obj to dump tree\n" - "-l <table.attr ...> dump attribute (columns) with LO to dump tree\n" - "-a dump all LO in DB (default)\n" - "-r if is set '-i' try remove old LO\n" - "-q run quietly\n" - "-w not dump, but show all LO in DB\n" - ); /* puts() */ + "-h this help\n" + "-u <username> username for connection to server\n" + "-p <password> password for connection to server\n" + "-d <database> database name\n" + "-t <hostname> server hostname\n" + "-s <dir> directory with dump tree (for export/import)\n" + "-i import large obj dump tree to DB\n" + "-e export (dump) large obj to dump tree\n" + "-l <table.attr ...> dump attribute (columns) with LO to dump tree\n" + "-a dump all LO in DB (default)\n" + "-r if is set '-i' try remove old LO\n" + "-q run quietly\n" + "-w not dump, but show all LO in DB\n" + ); /* puts() */ #endif puts( - "Example (dump): pg_dumplo -d my_db -s /my_dump/dir -l t1.a t1.b t2.a\n" - " pg_dumplo -a -d my_db -s /my_dump/dir\n" - "Example (import): pg_dumplo -i -d my_db -s /my_dump/dir\n" - "Example (show): pg_dumplo -w -d my_db\n\n" - "Note: * option '-l' must be last option!\n" - " * option '-i' without option '-r' make new large obj in DB\n" - " not rewrite old, the '-i' UPDATE oid numbers in table.attr only!\n" - " * if is not set option -s, the pg_dumplo use $PWD\n" - ); /* puts()*/ + "Example (dump): pg_dumplo -d my_db -s /my_dump/dir -l t1.a t1.b t2.a\n" + " pg_dumplo -a -d my_db -s /my_dump/dir\n" + "Example (import): pg_dumplo -i -d my_db -s /my_dump/dir\n" + "Example (show): pg_dumplo -w -d my_db\n\n" + "Note: * option '-l' must be last option!\n" + " * option '-i' without option '-r' make new large obj in DB\n" + " not rewrite old, the '-i' UPDATE oid numbers in table.attr only!\n" + " * if is not set option -s, the pg_dumplo use $PWD\n" + ); /* puts() */ } diff --git a/contrib/pg_dumplo/pg_dumplo.h b/contrib/pg_dumplo/pg_dumplo.h index 7513c71b9b..3ab25495cb 100644 --- a/contrib/pg_dumplo/pg_dumplo.h +++ b/contrib/pg_dumplo/pg_dumplo.h @@ -1,7 +1,7 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/pg_dumplo.h,v 1.3 2001/01/24 19:42:45 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/pg_dumplo.h,v 1.4 2001/03/22 03:59:10 momjian Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- @@ -17,12 +17,12 @@ /* ---------- * Define * ---------- - */ + */ #define QUERY_BUFSIZ (8*1024) #define DIR_UMASK 0755 #define FILE_UMASK 0644 -#define TRUE 1 +#define TRUE 1 #define FALSE 0 #define RE_OK 0 #define RE_ERROR 1 @@ -36,44 +36,47 @@ * LO struct * ---------- */ -typedef struct { - char *lo_table, - *lo_attr; - Oid lo_oid; -} LOlist; +typedef struct +{ + char *lo_table, + *lo_attr; + Oid lo_oid; +} LOlist; -typedef struct { - int action; - LOlist *lolist; - char **argv, - *user, - *db, - *host, - *space; - FILE *index; - int counter, - argc, - lolist_start, - remove, - quiet; - PGresult *res; - PGconn *conn; -} LODumpMaster; +typedef struct +{ + int action; + LOlist *lolist; + char **argv, + *user, + *db, + *host, + *space; + FILE *index; + int counter, + argc, + lolist_start, + remove, + quiet; + PGresult *res; + PGconn *conn; +} LODumpMaster; -typedef enum { +typedef enum +{ ACTION_NONE, ACTION_SHOW, - ACTION_EXPORT_ATTR, - ACTION_EXPORT_ALL, + ACTION_EXPORT_ATTR, + ACTION_EXPORT_ALL, ACTION_IMPORT -} PGLODUMP_ACTIONS; +} PGLODUMP_ACTIONS; extern char *progname; -extern void notice (LODumpMaster *pgLO, int set); -extern void index_file (LODumpMaster *pgLO); -extern void load_lolist (LODumpMaster *pgLO); -extern void pglo_export (LODumpMaster *pgLO); -extern void pglo_import (LODumpMaster *pgLO); +extern void notice(LODumpMaster * pgLO, int set); +extern void index_file(LODumpMaster * pgLO); +extern void load_lolist(LODumpMaster * pgLO); +extern void pglo_export(LODumpMaster * pgLO); +extern void pglo_import(LODumpMaster * pgLO); -#endif /* PG_DUMPLO_H */ +#endif /* PG_DUMPLO_H */ diff --git a/contrib/pg_dumplo/utils.c b/contrib/pg_dumplo/utils.c index dc3f5bbf9a..d36ee4be08 100644 --- a/contrib/pg_dumplo/utils.c +++ b/contrib/pg_dumplo/utils.c @@ -1,20 +1,20 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/utils.c,v 1.3 2001/01/24 19:42:45 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/utils.c,v 1.4 2001/03/22 03:59:10 momjian Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- */ -#include <stdio.h> +#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> -#include <errno.h> +#include <errno.h> #include <time.h> #include <libpq-fe.h> @@ -22,65 +22,76 @@ #include "pg_dumplo.h" -extern int errno; +extern int errno; + +static void Dummy_NoticeProcessor(void *arg, const char *message); +static void Default_NoticeProcessor(void *arg, const char *message); -static void Dummy_NoticeProcessor(void * arg, const char * message); -static void Default_NoticeProcessor(void * arg, const char * message); - void -index_file(LODumpMaster *pgLO) +index_file(LODumpMaster * pgLO) { - char path[BUFSIZ]; + char path[BUFSIZ]; if (pgLO->action == ACTION_SHOW) return; - - sprintf(path, "%s/%s", pgLO->space, pgLO->db); - + + sprintf(path, "%s/%s", pgLO->space, pgLO->db); + if (pgLO->action == ACTION_EXPORT_ATTR || - pgLO->action == ACTION_EXPORT_ALL) { - - if (mkdir(path, DIR_UMASK) == -1) { - if (errno != EEXIST) { + pgLO->action == ACTION_EXPORT_ALL) + { + + if (mkdir(path, DIR_UMASK) == -1) + { + if (errno != EEXIST) + { perror(path); - exit(RE_ERROR); - } + exit(RE_ERROR); + } } - - sprintf(path, "%s/lo_dump.index", path); - if ((pgLO->index = fopen(path, "w")) == NULL) { + sprintf(path, "%s/lo_dump.index", path); + + if ((pgLO->index = fopen(path, "w")) == NULL) + { perror(path); exit(RE_ERROR); } - - } else if (pgLO->action != ACTION_NONE ) { - - sprintf(path, "%s/lo_dump.index", path); - if ((pgLO->index = fopen(path, "r")) == NULL) { + } + else if (pgLO->action != ACTION_NONE) + { + + sprintf(path, "%s/lo_dump.index", path); + + if ((pgLO->index = fopen(path, "r")) == NULL) + { perror(path); exit(RE_ERROR); } } } -static -void Dummy_NoticeProcessor(void * arg, const char * message) +static +void +Dummy_NoticeProcessor(void *arg, const char *message) { - ; + ; } -static -void Default_NoticeProcessor(void * arg, const char * message) +static +void +Default_NoticeProcessor(void *arg, const char *message) { - fprintf(stderr, "%s", message); + fprintf(stderr, "%s", message); } -void -notice(LODumpMaster *pgLO, int set) -{ - if (set)PQsetNoticeProcessor(pgLO->conn, Default_NoticeProcessor, NULL); - else PQsetNoticeProcessor(pgLO->conn, Dummy_NoticeProcessor, NULL); +void +notice(LODumpMaster * pgLO, int set) +{ + if (set) + PQsetNoticeProcessor(pgLO->conn, Default_NoticeProcessor, NULL); + else + PQsetNoticeProcessor(pgLO->conn, Dummy_NoticeProcessor, NULL); } |
