Commit 8eb18d87 authored by Tom Lane's avatar Tom Lane

Fix pg_dump to use the same maximum-query-size constant as

the backend does.  Remove unnecessary limitation on field size in
dumpClasses_dumpData (ie, -d or -D case).
parent 26fb87d3
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.30 1999/05/25 16:13:05 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.31 1999/05/26 21:51:13 tgl Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
...@@ -502,7 +502,7 @@ const char * ...@@ -502,7 +502,7 @@ const char *
fmtId(const char *rawid, bool force_quotes) fmtId(const char *rawid, bool force_quotes)
{ {
const char *cp; const char *cp;
static char id[MAXQUERYLEN]; static char id[MAX_QUERY_SIZE];
if (!force_quotes) if (!force_quotes)
for (cp = rawid; *cp != '\0'; cp++) for (cp = rawid; *cp != '\0'; cp++)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.111 1999/05/26 19:45:53 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.112 1999/05/26 21:51:12 tgl Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -188,7 +188,7 @@ isViewRule(char *relname) ...@@ -188,7 +188,7 @@ isViewRule(char *relname)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
res = PQexec(g_conn, "begin"); res = PQexec(g_conn, "begin");
if (!res || if (!res ||
...@@ -319,11 +319,10 @@ dumpClasses_dumpData(FILE *fout, const char *classname, ...@@ -319,11 +319,10 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
const TableInfo tblinfo, bool oids) const TableInfo tblinfo, bool oids)
{ {
PGresult *res; PGresult *res;
char q[MAXQUERYLEN]; char q[MAX_QUERY_SIZE];
int tuple; int tuple;
int field; int field;
char *expsrc; char *expsrc;
char *expdest;
sprintf(q, "SELECT * FROM %s", fmtId(classname, force_quotes)); sprintf(q, "SELECT * FROM %s", fmtId(classname, force_quotes));
res = PQexec(g_conn, q); res = PQexec(g_conn, q);
...@@ -348,15 +347,16 @@ dumpClasses_dumpData(FILE *fout, const char *classname, ...@@ -348,15 +347,16 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
strcat(q, ") "); strcat(q, ") ");
fprintf(fout, "%s", q); fprintf(fout, "%s", q);
} }
fprintf(fout, "values ("); fprintf(fout, "VALUES (");
for (field = 0; field < PQnfields(res); field++) for (field = 0; field < PQnfields(res); field++)
{ {
if (field > 0) if (field > 0)
fprintf(fout, ","); fprintf(fout, ",");
if (PQgetisnull(res, tuple, field)) if (PQgetisnull(res, tuple, field))
fprintf(fout, "NULL");
else
{ {
fprintf(fout, "NULL");
continue;
}
switch (PQftype(res, field)) switch (PQftype(res, field))
{ {
case INT2OID: case INT2OID:
...@@ -369,41 +369,38 @@ dumpClasses_dumpData(FILE *fout, const char *classname, ...@@ -369,41 +369,38 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
PQgetvalue(res, tuple, field)); PQgetvalue(res, tuple, field));
break; break;
default: default:
/* /*
* All other types are printed as string literals, * All other types are printed as string literals,
* with appropriate escaping of special * with appropriate escaping of special
* characters. Quote mark ' goes to '' per SQL * characters. Quote mark ' goes to '' per SQL
* standard, other stuff goes to \ sequences. * standard, other stuff goes to \ sequences.
*/ */
putc('\'', fout);
expsrc = PQgetvalue(res, tuple, field); expsrc = PQgetvalue(res, tuple, field);
expdest = q; while (*expsrc)
for (; *expsrc; expsrc++)
{ {
char ch = *expsrc; char ch = *expsrc++;
if (ch == '\\' || ch == '\'') if (ch == '\\' || ch == '\'')
{ {
*expdest++ = ch; /* double it */ putc(ch, fout); /* double these */
*expdest++ = ch; putc(ch, fout);
} }
else if (ch < '\040') else if (ch < '\040')
{ {
/* generate octal escape for control chars */ /* generate octal escape for control chars */
*expdest++ = '\\'; putc('\\', fout);
*expdest++ = ((ch >> 6) & 3) + '0'; putc(((ch >> 6) & 3) + '0', fout);
*expdest++ = ((ch >> 3) & 7) + '0'; putc(((ch >> 3) & 7) + '0', fout);
*expdest++ = (ch & 7) + '0'; putc((ch & 7) + '0', fout);
} }
else else
*expdest++ = ch; putc(ch, fout);
} }
*expdest = '\0'; putc('\'', fout);
fprintf(fout, "'%s'", q);
break; break;
} }
} }
}
fprintf(fout, ");\n"); fprintf(fout, ");\n");
} }
PQclear(res); PQclear(res);
...@@ -746,7 +743,9 @@ main(int argc, char **argv) ...@@ -746,7 +743,9 @@ main(int argc, char **argv)
} }
fflush(g_fout); fflush(g_fout);
if (g_fout != stdout)
fclose(g_fout); fclose(g_fout);
clearTableInfo(tblinfo, numTables); clearTableInfo(tblinfo, numTables);
PQfinish(g_conn); PQfinish(g_conn);
exit(0); exit(0);
...@@ -766,7 +765,7 @@ getTypes(int *numTypes) ...@@ -766,7 +765,7 @@ getTypes(int *numTypes)
PGresult *res; PGresult *res;
int ntups; int ntups;
int i; int i;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
TypeInfo *tinfo; TypeInfo *tinfo;
int i_oid; int i_oid;
...@@ -895,7 +894,7 @@ getOperators(int *numOprs) ...@@ -895,7 +894,7 @@ getOperators(int *numOprs)
PGresult *res; PGresult *res;
int ntups; int ntups;
int i; int i;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
OprInfo *oprinfo; OprInfo *oprinfo;
...@@ -1238,7 +1237,7 @@ getAggregates(int *numAggs) ...@@ -1238,7 +1237,7 @@ getAggregates(int *numAggs)
PGresult *res; PGresult *res;
int ntups; int ntups;
int i; int i;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
AggInfo *agginfo; AggInfo *agginfo;
int i_oid; int i_oid;
...@@ -1332,7 +1331,7 @@ getFuncs(int *numFuncs) ...@@ -1332,7 +1331,7 @@ getFuncs(int *numFuncs)
PGresult *res; PGresult *res;
int ntups; int ntups;
int i; int i;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
FuncInfo *finfo; FuncInfo *finfo;
int i_oid; int i_oid;
...@@ -1432,7 +1431,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -1432,7 +1431,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
PGresult *res; PGresult *res;
int ntups; int ntups;
int i; int i;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
TableInfo *tblinfo; TableInfo *tblinfo;
int i_oid; int i_oid;
...@@ -1651,7 +1650,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -1651,7 +1650,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
int tgnargs = atoi(PQgetvalue(res2, i2, i_tgnargs)); int tgnargs = atoi(PQgetvalue(res2, i2, i_tgnargs));
char *tgargs = PQgetvalue(res2, i2, i_tgargs); char *tgargs = PQgetvalue(res2, i2, i_tgargs);
char *p; char *p;
char farg[MAXQUERYLEN]; char farg[MAX_QUERY_SIZE];
int findx; int findx;
for (findx = 0; findx < numFuncs; findx++) for (findx = 0; findx < numFuncs; findx++)
...@@ -1778,7 +1777,7 @@ getInherits(int *numInherits) ...@@ -1778,7 +1777,7 @@ getInherits(int *numInherits)
PGresult *res; PGresult *res;
int ntups; int ntups;
int i; int i;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
InhInfo *inhinfo; InhInfo *inhinfo;
int i_inhrel; int i_inhrel;
...@@ -1840,7 +1839,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -1840,7 +1839,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
{ {
int i, int i,
j; j;
char q[MAXQUERYLEN]; char q[MAX_QUERY_SIZE];
int i_attname; int i_attname;
int i_typname; int i_typname;
int i_atttypmod; int i_atttypmod;
...@@ -1951,7 +1950,7 @@ IndInfo * ...@@ -1951,7 +1950,7 @@ IndInfo *
getIndices(int *numIndices) getIndices(int *numIndices)
{ {
int i; int i;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
PGresult *res; PGresult *res;
int ntups; int ntups;
IndInfo *indinfo; IndInfo *indinfo;
...@@ -2042,7 +2041,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs, ...@@ -2042,7 +2041,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
TypeInfo *tinfo, int numTypes) TypeInfo *tinfo, int numTypes)
{ {
int i; int i;
char q[MAXQUERYLEN]; char q[MAX_QUERY_SIZE];
int funcInd; int funcInd;
for (i = 0; i < numTypes; i++) for (i = 0; i < numTypes; i++)
...@@ -2122,7 +2121,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs, ...@@ -2122,7 +2121,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
TypeInfo *tinfo, int numTypes) TypeInfo *tinfo, int numTypes)
{ {
PGresult *res; PGresult *res;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
int ntups; int ntups;
int i_lanname; int i_lanname;
int i_lanpltrusted; int i_lanpltrusted;
...@@ -2224,7 +2223,7 @@ static void ...@@ -2224,7 +2223,7 @@ static void
dumpOneFunc(FILE *fout, FuncInfo *finfo, int i, dumpOneFunc(FILE *fout, FuncInfo *finfo, int i,
TypeInfo *tinfo, int numTypes) TypeInfo *tinfo, int numTypes)
{ {
char q[MAXQUERYLEN]; char q[MAX_QUERY_SIZE];
int j; int j;
char *func_def; char *func_def;
char func_lang[NAMEDATALEN + 1]; char func_lang[NAMEDATALEN + 1];
...@@ -2344,15 +2343,15 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators, ...@@ -2344,15 +2343,15 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
TypeInfo *tinfo, int numTypes) TypeInfo *tinfo, int numTypes)
{ {
int i; int i;
char q[MAXQUERYLEN]; char q[MAX_QUERY_SIZE];
char leftarg[MAXQUERYLEN]; char leftarg[MAX_QUERY_SIZE/8];
char rightarg[MAXQUERYLEN]; char rightarg[MAX_QUERY_SIZE/8];
char commutator[MAXQUERYLEN]; char commutator[MAX_QUERY_SIZE/8];
char negator[MAXQUERYLEN]; char negator[MAX_QUERY_SIZE/8];
char restrictor[MAXQUERYLEN]; char restrictor[MAX_QUERY_SIZE/8];
char join[MAXQUERYLEN]; char join[MAX_QUERY_SIZE/8];
char sort1[MAXQUERYLEN]; char sort1[MAX_QUERY_SIZE/8];
char sort2[MAXQUERYLEN]; char sort2[MAX_QUERY_SIZE/8];
for (i = 0; i < numOperators; i++) for (i = 0; i < numOperators; i++)
{ {
...@@ -2460,11 +2459,11 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs, ...@@ -2460,11 +2459,11 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
TypeInfo *tinfo, int numTypes) TypeInfo *tinfo, int numTypes)
{ {
int i; int i;
char q[MAXQUERYLEN]; char q[MAX_QUERY_SIZE];
char sfunc1[MAXQUERYLEN]; char sfunc1[MAX_QUERY_SIZE];
char sfunc2[MAXQUERYLEN]; char sfunc2[MAX_QUERY_SIZE];
char basetype[MAXQUERYLEN]; char basetype[MAX_QUERY_SIZE];
char finalfunc[MAXQUERYLEN]; char finalfunc[MAX_QUERY_SIZE];
char comma1[2], char comma1[2],
comma2[2]; comma2[2];
...@@ -2667,10 +2666,11 @@ dumpACL(FILE *fout, TableInfo tbinfo) ...@@ -2667,10 +2666,11 @@ dumpACL(FILE *fout, TableInfo tbinfo)
else else
{ {
*eqpos = '\0'; /* it's ok to clobber aclbuf */ *eqpos = '\0'; /* it's ok to clobber aclbuf */
if (strncmp(tok, "group ",strlen("group ")) == 0) if (strncmp(tok, "group ", strlen("group ")) == 0)
fprintf(fout, "GROUP %s;\n", fprintf(fout, "GROUP %s;\n",
fmtId(tok + sizeof("group ") - 1, force_quotes)); fmtId(tok + strlen("group "), force_quotes));
else fprintf(fout, "%s;\n", fmtId(tok, force_quotes)); else
fprintf(fout, "%s;\n", fmtId(tok, force_quotes));
} }
} }
free(priv); free(priv);
...@@ -2694,7 +2694,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables, ...@@ -2694,7 +2694,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
int i, int i,
j, j,
k; k;
char q[MAXQUERYLEN]; char q[MAX_QUERY_SIZE];
char *serialSeq = NULL; /* implicit sequence name created char *serialSeq = NULL; /* implicit sequence name created
* by SERIAL datatype */ * by SERIAL datatype */
const char *serialSeqSuffix = "_id_seq"; /* suffix for implicit const char *serialSeqSuffix = "_id_seq"; /* suffix for implicit
...@@ -2873,9 +2873,9 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices, ...@@ -2873,9 +2873,9 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
indclass; indclass;
int nclass; int nclass;
char q[MAXQUERYLEN], char q[MAX_QUERY_SIZE],
id1[MAXQUERYLEN], id1[MAX_QUERY_SIZE],
id2[MAXQUERYLEN]; id2[MAX_QUERY_SIZE];
PGresult *res; PGresult *res;
for (i = 0; i < numIndices; i++) for (i = 0; i < numIndices; i++)
...@@ -3213,7 +3213,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo) ...@@ -3213,7 +3213,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
char cycled, char cycled,
called, called,
*t; *t;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
sprintf(query, sprintf(query,
"SELECT sequence_name, last_value, increment_by, max_value, " "SELECT sequence_name, last_value, increment_by, max_value, "
...@@ -3310,7 +3310,7 @@ dumpRules(FILE *fout, const char *tablename, ...@@ -3310,7 +3310,7 @@ dumpRules(FILE *fout, const char *tablename,
int nrules; int nrules;
int i, int i,
t; t;
char query[MAXQUERYLEN]; char query[MAX_QUERY_SIZE];
int i_definition; int i_definition;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_dump.h,v 1.38 1999/05/25 16:13:09 momjian Exp $ * $Id: pg_dump.h,v 1.39 1999/05/26 21:51:11 tgl Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
...@@ -224,9 +224,4 @@ extern void dumpTables(FILE *fout, TableInfo *tbinfo, int numTables, ...@@ -224,9 +224,4 @@ extern void dumpTables(FILE *fout, TableInfo *tbinfo, int numTables,
const bool acls); const bool acls);
extern void dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices, extern void dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
TableInfo *tbinfo, int numTables, const char *tablename); TableInfo *tbinfo, int numTables, const char *tablename);
extern const char *fmtId(const char *identifier, bool force_quotes);
extern const char *
fmtId(const char *identifier, bool force_quotes);
/* largest query string size */
#define MAXQUERYLEN 5000
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment