Index: src/bin/pg_dump/pg_dump.c =================================================================== RCS file: /var/lib/cvs/pgsql/src/bin/pg_dump/pg_dump.c,v retrieving revision 1.275 diff -c -r1.275 pg_dump.c *** src/bin/pg_dump/pg_dump.c 24 Jul 2002 19:11:11 -0000 1.275 --- src/bin/pg_dump/pg_dump.c 24 Jul 2002 23:10:48 -0000 *************** *** 134,139 **** --- 134,140 ---- static int dumpDatabase(Archive *AH); static const char *getAttrName(int attrnum, TableInfo *tblInfo); static const char* fmtCopyColumnList(const TableInfo* ti); + static void myAppendPQExpBuffer(PQExpBuffer buf, const char *fmt, ...); extern char *optarg; extern int optind, *************** *** 1282,1297 **** encoding = PQgetvalue(res, 0, i_encoding); datpath = PQgetvalue(res, 0, i_datpath); ! appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0", ! fmtId(datname, force_quotes)); if (strlen(encoding) > 0) appendPQExpBuffer(creaQry, " ENCODING = %s", encoding); if (strlen(datpath) > 0) appendPQExpBuffer(creaQry, " LOCATION = '%s'", datpath); appendPQExpBuffer(creaQry, ";\n"); ! appendPQExpBuffer(delQry, "DROP DATABASE %s;\n", ! fmtId(datname, force_quotes)); ArchiveEntry(AH, "0", /* OID */ datname, /* Name */ --- 1283,1298 ---- encoding = PQgetvalue(res, 0, i_encoding); datpath = PQgetvalue(res, 0, i_datpath); ! myAppendPQExpBuffer(creaQry, "CREATE DATABASE %S WITH TEMPLATE = template0", ! datname); if (strlen(encoding) > 0) appendPQExpBuffer(creaQry, " ENCODING = %s", encoding); if (strlen(datpath) > 0) appendPQExpBuffer(creaQry, " LOCATION = '%s'", datpath); appendPQExpBuffer(creaQry, ";\n"); ! myAppendPQExpBuffer(delQry, "DROP DATABASE %S;\n", ! datname); ArchiveEntry(AH, "0", /* OID */ datname, /* Name */ *************** *** 2605,2612 **** if (objsubid == 0) { resetPQExpBuffer(target); ! appendPQExpBuffer(target, "%s %s", reltypename, ! fmtId(tbinfo->relname, force_quotes)); resetPQExpBuffer(query); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); --- 2606,2612 ---- if (objsubid == 0) { resetPQExpBuffer(target); ! myAppendPQExpBuffer(target, "%s %S", reltypename, tbinfo->relname); resetPQExpBuffer(query); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); *************** *** 2621,2631 **** else if (objsubid > 0 && objsubid <= tbinfo->numatts) { resetPQExpBuffer(target); ! appendPQExpBuffer(target, "COLUMN %s.", ! fmtId(tbinfo->relname, force_quotes)); ! appendPQExpBuffer(target, "%s", ! fmtId(tbinfo->attnames[objsubid-1], ! force_quotes)); resetPQExpBuffer(query); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); --- 2621,2628 ---- else if (objsubid > 0 && objsubid <= tbinfo->numatts) { resetPQExpBuffer(target); ! myAppendPQExpBuffer(target, "COLUMN %S.%S", ! tbinfo->relname, tbinfo->attnames[objsubid - 1]); resetPQExpBuffer(query); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); *************** *** 2682,2688 **** { i_oid = PQfnumber(res, "oid"); resetPQExpBuffer(query); ! appendPQExpBuffer(query, "DATABASE %s", fmtId(PQdb(g_conn), force_quotes)); dumpComment(fout, query->data, NULL, "", PQgetvalue(res, 0, i_oid), "pg_database", 0, NULL); } --- 2679,2685 ---- { i_oid = PQfnumber(res, "oid"); resetPQExpBuffer(query); ! myAppendPQExpBuffer(query, "DATABASE %S", PQdb(g_conn)); dumpComment(fout, query->data, NULL, "", PQgetvalue(res, 0, i_oid), "pg_database", 0, NULL); } *************** *** 2883,2898 **** (*deps)[depIdx++] = strdup(typoutputoid); /* DROP must be fully qualified in case same name appears in pg_catalog */ ! appendPQExpBuffer(delq, "DROP TYPE %s.", ! fmtId(tinfo->typnamespace->nspname, force_quotes)); ! appendPQExpBuffer(delq, "%s;\n", ! fmtId(tinfo->typname, force_quotes)); ! ! appendPQExpBuffer(q, ! "CREATE TYPE %s " ! "( internallength = %s,", ! fmtId(tinfo->typname, force_quotes), ! (strcmp(typlen, "-1") == 0) ? "variable" : typlen); if (fout->remoteVersion >= 70300) { --- 2880,2893 ---- (*deps)[depIdx++] = strdup(typoutputoid); /* DROP must be fully qualified in case same name appears in pg_catalog */ ! myAppendPQExpBuffer(delq, "DROP TYPE %S.%S;\n", ! tinfo->typnamespace->nspname, ! tinfo->typname); ! ! myAppendPQExpBuffer(q, "CREATE TYPE %S " ! "( internallength = %s,", ! tinfo->typname, ! (strcmp(typlen, "-1") == 0) ? "variable" : typlen); if (fout->remoteVersion >= 70300) { *************** *** 2903,2913 **** else { /* regproc delivers an unquoted name before 7.3 */ ! /* cannot combine these because fmtId uses static result area */ ! appendPQExpBuffer(q, " input = %s,", ! fmtId(typinput, force_quotes)); ! appendPQExpBuffer(q, " output = %s,", ! fmtId(typoutput, force_quotes)); } if (typdefault != NULL) --- 2898,2905 ---- else { /* regproc delivers an unquoted name before 7.3 */ ! myAppendPQExpBuffer(q, " input = %S, output = %S,", ! typinput, typoutput); } if (typdefault != NULL) *************** *** 5965,5967 **** --- 5957,5987 ---- return q->data; } + static void + myAppendPQExpBuffer(PQExpBuffer buf, const char *fmt, ...) + { + char fmt_buf[3]; + va_list argp; + int i; + + va_start(argp, fmt); + + for (i = 0; i < strlen(fmt); i++) + { + if (fmt[i] == '%') + { + i++; + if (fmt[i] == 'S') + appendPQExpBuffer(buf, "%s", fmtId(va_arg(argp, char *), force_quotes)); + else + { + strncpy(fmt_buf, fmt - 1, 3); + appendPQExpBuffer(buf, fmt_buf, va_arg(argp, void *)); + } + } + else + appendPQExpBufferChar(buf, fmt[i]); + } + + va_end(argp); + }