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++;