Commits

Marc Fournier committed 672f6ec

Brought in David Bennett's (dave@bensoft.com) changes to pg_dump

Comments (0)

Files changed (5)

src/bin/pg_dump/Makefile

 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.2 1996/07/12 05:39:30 scrappy Exp $
+#    $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.3 1996/07/22 08:36:57 scrappy Exp $
 #
 #-------------------------------------------------------------------------
 

src/bin/pg_dump/README.dhb

+version 1.13.dhb.2 README
+---------------------------
+
+* Fixed dumpTable output to output lengths for char and varchar types!
+
+* Added single. quote to twin single quote expansion for 'insert' string
+  mode.
+
+version 1.13.dhb README
+-------------------------
  
 This is a modified version of the pg_dump.c program that is distributed with
 pg95 1.01.  Modifications include:

src/bin/pg_dump/common.c

  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.2 1996/07/12 05:39:33 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.3 1996/07/22 08:36:59 scrappy Exp $
+ *
+ * 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.
  *
  *-------------------------------------------------------------------------
  */
   return result;
 }
 
-
 /*
  * findTypeByOid 
  *    given an oid of a type, return its typename

src/bin/pg_dump/pg_dump.c

  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.2 1996/07/12 05:39:35 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.3 1996/07/22 08:36:59 scrappy Exp $
  *
- * Modifications - 6/10/96 - dave@bensoft.com
+ * 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.
+ *
  *-------------------------------------------------------------------------
  */
 
 static void
 usage(char* progname)
 {
+    fprintf(stderr, "%s - version 1.13.dhb.2\n\n",progname);
     fprintf(stderr, "usage:  %s [options] [dbname]\n",progname);
     fprintf(stderr, "\t -f filename \t\t script output filename\n");
     fprintf(stderr, "\t -d[a]       \t\t dump data as proper insert strings\n");
     char q[MAXQUERYLEN];
     int i_attname;
     int i_typname;
+    int i_attlen;
     PGresult *res;
     int ntups;
 
 	    tblinfo[i].relname,
 	    g_comment_end);
 
-	sprintf(q,"SELECT a.attnum, a.attname, t.typname from pg_attribute a, pg_type t where a.attrelid = '%s'::oid and a.atttypid = t.oid and a.attnum > 0 order by attnum",tblinfo[i].oid);
+	sprintf(q,"SELECT a.attnum, a.attname, t.typname, a.attlen from pg_attribute a, pg_type t where a.attrelid = '%s'::oid and a.atttypid = t.oid and a.attnum > 0 order by attnum",tblinfo[i].oid);
 	res = PQexec(g_conn, q);
 	if (!res || 
 	    PQresultStatus(res) != PGRES_TUPLES_OK) {
 
 	i_attname = PQfnumber(res,"attname");
 	i_typname = PQfnumber(res,"typname");
+	i_attlen  = PQfnumber(res,"attlen");
 
 	tblinfo[i].numatts = ntups;
 	tblinfo[i].attnames = (char**) malloc( ntups * sizeof(char*));
 	tblinfo[i].typnames = (char**) malloc( ntups * sizeof(char*));
+	tblinfo[i].attlen   = (int*) malloc(ntups * sizeof(int));
 	tblinfo[i].inhAttrs = (int*) malloc (ntups * sizeof(int));
 	tblinfo[i].parentRels = NULL;
 	tblinfo[i].numParents = 0;
 	for (j=0;j<ntups;j++) {
 	    tblinfo[i].attnames[j] = dupstr(PQgetvalue(res,j,i_attname));
 	    tblinfo[i].typnames[j] = dupstr(PQgetvalue(res,j,i_typname));
+	    tblinfo[i].attlen[j] = atoi(PQgetvalue(res,j,i_attlen));
+	    if (tblinfo[i].attlen[j] > 0) 
+	      tblinfo[i].attlen[j] = tblinfo[i].attlen[j] - 4;
 	    tblinfo[i].inhAttrs[j] = 0; /* this flag is set in flagInhAttrs()*/
 	}
 	PQclear(res);
 	    actual_atts = 0;
 	    for (j=0;j<tblinfo[i].numatts;j++) {
 	        if (tblinfo[i].inhAttrs[j] == 0) {
-		    sprintf(q, "%s%s%s %s",
-		   	    q,
-			    (actual_atts > 0) ? ", " : "",
-			    tblinfo[i].attnames[j],
-			    tblinfo[i].typnames[j]);
-		    actual_atts++;
+	        
+	            /* Show lengths on bpchar and varchar */
+	            if (!strcmp(tblinfo[i].typnames[j],"bpchar")) {
+		        sprintf(q, "%s%s%s char(%d)",
+		   	        q,
+			        (actual_atts > 0) ? ", " : "",
+			        tblinfo[i].attnames[j],
+			        tblinfo[i].attlen[j]);
+		        actual_atts++;
+	            }
+	            else if (!strcmp(tblinfo[i].typnames[j],"varchar")) {
+		        sprintf(q, "%s%s%s %s(%d)",
+		   	        q,
+			        (actual_atts > 0) ? ", " : "",
+			        tblinfo[i].attnames[j],
+			        tblinfo[i].typnames[j],
+			        tblinfo[i].attlen[j]);
+		        actual_atts++;
+	            }
+	            else {    
+		        sprintf(q, "%s%s%s %s",
+		   	        q,
+			        (actual_atts > 0) ? ", " : "",
+			        tblinfo[i].attnames[j],
+			        tblinfo[i].typnames[j]);
+		        actual_atts++;
+		    }
 	        }
 	    }
 
     char query[255];
 #define COPYBUFSIZ	8192
     char copybuf[COPYBUFSIZ];
+    char expandbuf[COPYBUFSIZ];
+    char *expsrc,*expdest;
     char q[MAXQUERYLEN];
     PGresult *res;
     int i,j;
 			        fprintf(fout, "%s", PQgetvalue(res,tuple,field));
 			        break;
 		            default:  
-			        fprintf(fout, "'%s'", PQgetvalue(res,tuple,field));
+		            
+		                /* Before outputing string value, expand all
+		                   single quotes to twin single quotes -
+		                   dhb - 6/11/96 */
+		                expsrc=PQgetvalue(res,tuple,field);
+		                expdest=expandbuf;
+		                while (*expsrc) {
+		                    *expdest++=*expsrc;
+		                    if (*expsrc == (char)0x27) /*sing. quote*/
+		                        *expdest++ = *expsrc;
+		                    expsrc++;
+		                }
+		                *expdest=*expsrc; /* null term. */
+		                
+			        fprintf(fout, "'%s'", expandbuf);
 			        break;
 		        }
 		        field++;

src/bin/pg_dump/pg_dump.h

  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_dump.h,v 1.2 1996/07/12 05:39:39 scrappy Exp $
+ * $Id: pg_dump.h,v 1.3 1996/07/22 08:37:00 scrappy Exp $
  *
+ * 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.
  *-------------------------------------------------------------------------
  */
 
 			       this is needed because the SQL tables will
 			       not have the same order of attributes as
 			       the POSTQUEL tables */
+    int *attlen;	    /* attribute lengths */
            
 } TableInfo;