*** describe.c 2003-02-23 13:11:17.000000000 +0530 --- ../psql/describe.c 2003-02-23 21:17:12.000000000 +0530 *************** *** 636,641 **** --- 636,642 ---- char **ptr; PQExpBufferData title; unsigned int cols = 0; + unsigned int defaultcol = 5; struct { bool hasindex; *************** *** 702,710 **** --- 703,721 ---- printfPQExpBuffer(&buf, "SELECT a.attname,"); appendPQExpBuffer(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod),\n" " a.attnotnull, a.atthasdef, a.attnum"); + if (verbose) appendPQExpBuffer(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)"); + + /* my code additions 1 */ + appendPQExpBuffer(&buf, ", (SELECT substring(adsrc for 128) FROM pg_catalog.pg_attrdef WHERE adrelid =%s AND adnum = a.attnum ) " , oid ); + /* ends 1 */ + + appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a"); + + + if (tableinfo.relkind == 'i') appendPQExpBuffer(&buf, ", pg_catalog.pg_index i"); appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid); *************** *** 713,718 **** --- 724,731 ---- appendPQExpBuffer(&buf, "\nORDER BY a.attnum"); res = PSQLexec(buf.data, false); + + if (!res) goto error_return; *************** *** 740,745 **** --- 753,759 ---- { /* Name */ cells[i * cols + 0] = PQgetvalue(res, i, 0); /* don't free this + * afterwards */ /* Type */ cells[i * cols + 1] = PQgetvalue(res, i, 1); /* don't free this *************** *** 751,777 **** { cells[i * cols + 2] = xmalloc(128 + 128); cells[i * cols + 2][0] = '\0'; if (strcmp(PQgetvalue(res, i, 2), "t") == 0) strcat(cells[i * cols + 2], "not null"); /* handle "default" here */ if (strcmp(PQgetvalue(res, i, 3), "t") == 0) { - PGresult *result; - - printfPQExpBuffer(&buf, - "SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d\n" - "WHERE d.adrelid = '%s' AND d.adnum = %s", - oid, PQgetvalue(res, i, 4)); - - result = PSQLexec(buf.data, false); - if (cells[i * cols + 2][0]) strcat(cells[i * cols + 2], " "); strcat(cells[i * cols + 2], "default "); - strcat(cells[i * cols + 2], result ? PQgetvalue(result, 0, 0) : "?"); ! PQclear(result); } } --- 765,787 ---- { cells[i * cols + 2] = xmalloc(128 + 128); cells[i * cols + 2][0] = '\0'; + + if (strcmp(PQgetvalue(res, i, 2), "t") == 0) strcat(cells[i * cols + 2], "not null"); /* handle "default" here */ if (strcmp(PQgetvalue(res, i, 3), "t") == 0) { if (cells[i * cols + 2][0]) strcat(cells[i * cols + 2], " "); + strcat(cells[i * cols + 2], "default "); ! if (verbose) ! defaultcol = 6; ! strcat(cells[i * cols + 2], PQgetvalue(res, i, defaultcol ) ); ! } }