2121 *
2222 *
2323 * IDENTIFICATION
24- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.111 1999/05/2619:45:53 momjian Exp $
24+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.112 1999/05/2621:51:12 tgl Exp $
2525 *
2626 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727 *
@@ -188,7 +188,7 @@ isViewRule(char *relname)
188188{
189189PGresult * res ;
190190int ntups ;
191- char query [MAXQUERYLEN ];
191+ char query [MAX_QUERY_SIZE ];
192192
193193res = PQexec (g_conn ,"begin" );
194194if (!res ||
@@ -319,11 +319,10 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
319319const TableInfo tblinfo ,bool oids )
320320{
321321PGresult * res ;
322- char q [MAXQUERYLEN ];
322+ char q [MAX_QUERY_SIZE ];
323323int tuple ;
324324int field ;
325325char * expsrc ;
326- char * expdest ;
327326
328327sprintf (q ,"SELECT * FROM %s" ,fmtId (classname ,force_quotes ));
329328res = PQexec (g_conn ,q );
@@ -348,60 +347,58 @@ dumpClasses_dumpData(FILE *fout, const char *classname,
348347strcat (q ,") " );
349348fprintf (fout ,"%s" ,q );
350349}
351- fprintf (fout ,"values (" );
350+ fprintf (fout ,"VALUES (" );
352351for (field = 0 ;field < PQnfields (res );field ++ )
353352{
354353if (field > 0 )
355354fprintf (fout ,"," );
356355if (PQgetisnull (res ,tuple ,field ))
356+ {
357357fprintf (fout ,"NULL" );
358- else
358+ continue ;
359+ }
360+ switch (PQftype (res ,field ))
359361{
360- switch (PQftype (res ,field ))
361- {
362- case INT2OID :
363- case INT4OID :
364- case OIDOID :/* int types */
365- case FLOAT4OID :
366- case FLOAT8OID :/* float types */
367- /* These types are printed without quotes */
368- fprintf (fout ,"%s" ,
369- PQgetvalue (res ,tuple ,field ));
370- break ;
371- default :
372-
373- /*
374- * All other types are printed as string literals,
375- * with appropriate escaping of special
376- * characters. Quote mark ' goes to '' per SQL
377- * standard, other stuff goes to \ sequences.
378- */
379- expsrc = PQgetvalue (res ,tuple ,field );
380- expdest = q ;
381- for (;* expsrc ;expsrc ++ )
362+ case INT2OID :
363+ case INT4OID :
364+ case OIDOID :/* int types */
365+ case FLOAT4OID :
366+ case FLOAT8OID :/* float types */
367+ /* These types are printed without quotes */
368+ fprintf (fout ,"%s" ,
369+ PQgetvalue (res ,tuple ,field ));
370+ break ;
371+ default :
372+ /*
373+ * All other types are printed as string literals,
374+ * with appropriate escaping of special
375+ * characters. Quote mark ' goes to '' per SQL
376+ * standard, other stuff goes to \ sequences.
377+ */
378+ putc ('\'' ,fout );
379+ expsrc = PQgetvalue (res ,tuple ,field );
380+ while (* expsrc )
381+ {
382+ char ch = * expsrc ++ ;
383+
384+ if (ch == '\\' || ch == '\'' )
382385{
383- char ch = * expsrc ;
384-
385- if (ch == '\\' || ch == '\'' )
386- {
387- * expdest ++ = ch ;/* double it */
388- * expdest ++ = ch ;
389- }
390- else if (ch < '\040' )
391- {
392- /* generate octal escape for control chars */
393- * expdest ++ = '\\' ;
394- * expdest ++ = ((ch >>6 )& 3 )+ '0' ;
395- * expdest ++ = ((ch >>3 )& 7 )+ '0' ;
396- * expdest ++ = (ch & 7 )+ '0' ;
397- }
398- else
399- * expdest ++ = ch ;
386+ putc (ch ,fout );/* double these */
387+ putc (ch ,fout );
400388}
401- * expdest = '\0' ;
402- fprintf (fout ,"'%s'" ,q );
403- break ;
404- }
389+ else if (ch < '\040' )
390+ {
391+ /* generate octal escape for control chars */
392+ putc ('\\' ,fout );
393+ putc (((ch >>6 )& 3 )+ '0' ,fout );
394+ putc (((ch >>3 )& 7 )+ '0' ,fout );
395+ putc ((ch & 7 )+ '0' ,fout );
396+ }
397+ else
398+ putc (ch ,fout );
399+ }
400+ putc ('\'' ,fout );
401+ break ;
405402}
406403}
407404fprintf (fout ,");\n" );
@@ -746,7 +743,9 @@ main(int argc, char **argv)
746743}
747744
748745fflush (g_fout );
749- fclose (g_fout );
746+ if (g_fout != stdout )
747+ fclose (g_fout );
748+
750749clearTableInfo (tblinfo ,numTables );
751750PQfinish (g_conn );
752751exit (0 );
@@ -766,7 +765,7 @@ getTypes(int *numTypes)
766765PGresult * res ;
767766int ntups ;
768767int i ;
769- char query [MAXQUERYLEN ];
768+ char query [MAX_QUERY_SIZE ];
770769TypeInfo * tinfo ;
771770
772771int i_oid ;
@@ -895,7 +894,7 @@ getOperators(int *numOprs)
895894PGresult * res ;
896895int ntups ;
897896int i ;
898- char query [MAXQUERYLEN ];
897+ char query [MAX_QUERY_SIZE ];
899898
900899OprInfo * oprinfo ;
901900
@@ -1238,7 +1237,7 @@ getAggregates(int *numAggs)
12381237PGresult * res ;
12391238int ntups ;
12401239int i ;
1241- char query [MAXQUERYLEN ];
1240+ char query [MAX_QUERY_SIZE ];
12421241AggInfo * agginfo ;
12431242
12441243int i_oid ;
@@ -1332,7 +1331,7 @@ getFuncs(int *numFuncs)
13321331PGresult * res ;
13331332int ntups ;
13341333int i ;
1335- char query [MAXQUERYLEN ];
1334+ char query [MAX_QUERY_SIZE ];
13361335FuncInfo * finfo ;
13371336
13381337int i_oid ;
@@ -1432,7 +1431,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
14321431PGresult * res ;
14331432int ntups ;
14341433int i ;
1435- char query [MAXQUERYLEN ];
1434+ char query [MAX_QUERY_SIZE ];
14361435TableInfo * tblinfo ;
14371436
14381437int i_oid ;
@@ -1651,7 +1650,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
16511650int tgnargs = atoi (PQgetvalue (res2 ,i2 ,i_tgnargs ));
16521651char * tgargs = PQgetvalue (res2 ,i2 ,i_tgargs );
16531652char * p ;
1654- char farg [MAXQUERYLEN ];
1653+ char farg [MAX_QUERY_SIZE ];
16551654int findx ;
16561655
16571656for (findx = 0 ;findx < numFuncs ;findx ++ )
@@ -1778,7 +1777,7 @@ getInherits(int *numInherits)
17781777PGresult * res ;
17791778int ntups ;
17801779int i ;
1781- char query [MAXQUERYLEN ];
1780+ char query [MAX_QUERY_SIZE ];
17821781InhInfo * inhinfo ;
17831782
17841783int i_inhrel ;
@@ -1840,7 +1839,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
18401839{
18411840int i ,
18421841j ;
1843- char q [MAXQUERYLEN ];
1842+ char q [MAX_QUERY_SIZE ];
18441843int i_attname ;
18451844int i_typname ;
18461845int i_atttypmod ;
@@ -1951,7 +1950,7 @@ IndInfo *
19511950getIndices (int * numIndices )
19521951{
19531952int i ;
1954- char query [MAXQUERYLEN ];
1953+ char query [MAX_QUERY_SIZE ];
19551954PGresult * res ;
19561955int ntups ;
19571956IndInfo * indinfo ;
@@ -2042,7 +2041,7 @@ dumpTypes(FILE *fout, FuncInfo *finfo, int numFuncs,
20422041TypeInfo * tinfo ,int numTypes )
20432042{
20442043int i ;
2045- char q [MAXQUERYLEN ];
2044+ char q [MAX_QUERY_SIZE ];
20462045int funcInd ;
20472046
20482047for (i = 0 ;i < numTypes ;i ++ )
@@ -2122,7 +2121,7 @@ dumpProcLangs(FILE *fout, FuncInfo *finfo, int numFuncs,
21222121TypeInfo * tinfo ,int numTypes )
21232122{
21242123PGresult * res ;
2125- char query [MAXQUERYLEN ];
2124+ char query [MAX_QUERY_SIZE ];
21262125int ntups ;
21272126int i_lanname ;
21282127int i_lanpltrusted ;
@@ -2224,7 +2223,7 @@ static void
22242223dumpOneFunc (FILE * fout ,FuncInfo * finfo ,int i ,
22252224TypeInfo * tinfo ,int numTypes )
22262225{
2227- char q [MAXQUERYLEN ];
2226+ char q [MAX_QUERY_SIZE ];
22282227int j ;
22292228char * func_def ;
22302229char func_lang [NAMEDATALEN + 1 ];
@@ -2344,15 +2343,15 @@ dumpOprs(FILE *fout, OprInfo *oprinfo, int numOperators,
23442343TypeInfo * tinfo ,int numTypes )
23452344{
23462345int i ;
2347- char q [MAXQUERYLEN ];
2348- char leftarg [MAXQUERYLEN ];
2349- char rightarg [MAXQUERYLEN ];
2350- char commutator [MAXQUERYLEN ];
2351- char negator [MAXQUERYLEN ];
2352- char restrictor [MAXQUERYLEN ];
2353- char join [MAXQUERYLEN ];
2354- char sort1 [MAXQUERYLEN ];
2355- char sort2 [MAXQUERYLEN ];
2346+ char q [MAX_QUERY_SIZE ];
2347+ char leftarg [MAX_QUERY_SIZE / 8 ];
2348+ char rightarg [MAX_QUERY_SIZE / 8 ];
2349+ char commutator [MAX_QUERY_SIZE / 8 ];
2350+ char negator [MAX_QUERY_SIZE / 8 ];
2351+ char restrictor [MAX_QUERY_SIZE / 8 ];
2352+ char join [MAX_QUERY_SIZE / 8 ];
2353+ char sort1 [MAX_QUERY_SIZE / 8 ];
2354+ char sort2 [MAX_QUERY_SIZE / 8 ];
23562355
23572356for (i = 0 ;i < numOperators ;i ++ )
23582357{
@@ -2460,11 +2459,11 @@ dumpAggs(FILE *fout, AggInfo *agginfo, int numAggs,
24602459TypeInfo * tinfo ,int numTypes )
24612460{
24622461int i ;
2463- char q [MAXQUERYLEN ];
2464- char sfunc1 [MAXQUERYLEN ];
2465- char sfunc2 [MAXQUERYLEN ];
2466- char basetype [MAXQUERYLEN ];
2467- char finalfunc [MAXQUERYLEN ];
2462+ char q [MAX_QUERY_SIZE ];
2463+ char sfunc1 [MAX_QUERY_SIZE ];
2464+ char sfunc2 [MAX_QUERY_SIZE ];
2465+ char basetype [MAX_QUERY_SIZE ];
2466+ char finalfunc [MAX_QUERY_SIZE ];
24682467char comma1 [2 ],
24692468comma2 [2 ];
24702469
@@ -2667,10 +2666,11 @@ dumpACL(FILE *fout, TableInfo tbinfo)
26672666else
26682667{
26692668* eqpos = '\0' ;/* it's ok to clobber aclbuf */
2670- if (strncmp (tok ,"group " ,strlen ("group " ))== 0 )
2671- fprintf (fout ,"GROUP %s;\n" ,
2672- fmtId (tok + sizeof ("group " )- 1 ,force_quotes ));
2673- else fprintf (fout ,"%s;\n" ,fmtId (tok ,force_quotes ));
2669+ if (strncmp (tok ,"group " ,strlen ("group " ))== 0 )
2670+ fprintf (fout ,"GROUP %s;\n" ,
2671+ fmtId (tok + strlen ("group " ),force_quotes ));
2672+ else
2673+ fprintf (fout ,"%s;\n" ,fmtId (tok ,force_quotes ));
26742674}
26752675}
26762676free (priv );
@@ -2694,7 +2694,7 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
26942694int i ,
26952695j ,
26962696k ;
2697- char q [MAXQUERYLEN ];
2697+ char q [MAX_QUERY_SIZE ];
26982698char * serialSeq = NULL ;/* implicit sequence name created
26992699 * by SERIAL datatype */
27002700const char * serialSeqSuffix = "_id_seq" ;/* suffix for implicit
@@ -2873,9 +2873,9 @@ dumpIndices(FILE *fout, IndInfo *indinfo, int numIndices,
28732873indclass ;
28742874int nclass ;
28752875
2876- char q [MAXQUERYLEN ],
2877- id1 [MAXQUERYLEN ],
2878- id2 [MAXQUERYLEN ];
2876+ char q [MAX_QUERY_SIZE ],
2877+ id1 [MAX_QUERY_SIZE ],
2878+ id2 [MAX_QUERY_SIZE ];
28792879PGresult * res ;
28802880
28812881for (i = 0 ;i < numIndices ;i ++ )
@@ -3213,7 +3213,7 @@ dumpSequence(FILE *fout, TableInfo tbinfo)
32133213char cycled ,
32143214called ,
32153215* t ;
3216- char query [MAXQUERYLEN ];
3216+ char query [MAX_QUERY_SIZE ];
32173217
32183218sprintf (query ,
32193219"SELECT sequence_name, last_value, increment_by, max_value, "
@@ -3310,7 +3310,7 @@ dumpRules(FILE *fout, const char *tablename,
33103310int nrules ;
33113311int i ,
33123312t ;
3313- char query [MAXQUERYLEN ];
3313+ char query [MAX_QUERY_SIZE ];
33143314
33153315int i_definition ;
33163316