summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorVadim B. Mikheev1997-08-19 04:46:15 +0000
committerVadim B. Mikheev1997-08-19 04:46:15 +0000
commitb992e200b8872ecb6652ec85111995f8d4c5aee0 (patch)
tree52ce3eed9d36e779fe3fa729c12757b13a521b56 /src/bin
parentb99c63cfc029cc0552e98f652d1734aec1124a5b (diff)
NOT NULL implementation (submitted by Robson Paniago de Miranda).
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/pg_dump/pg_dump.c11
-rw-r--r--src/bin/pg_dump/pg_dump.h3
-rw-r--r--src/bin/psql/psql.c4
-rw-r--r--src/bin/psql/psqlHelp.h4
4 files changed, 15 insertions, 7 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 1af318a6b06..efd411d20d8 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -21,7 +21,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.36 1997/07/28 23:53:54 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.37 1997/08/19 04:44:38 vadim Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
@@ -798,6 +798,8 @@ clearTableInfo(TableInfo *tblinfo, int numTables)
if ( tblinfo[i].sequence )
continue;
+ if (tblinfo[i].notnull) free (tblinfo[i].notnull);
+
/* Process Attributes */
for(j=0;j<tblinfo[i].numatts;j++) {
if(tblinfo[i].attnames[j]) free (tblinfo[i].attnames[j]);
@@ -1233,6 +1235,7 @@ getTableAttrs(TableInfo* tblinfo, int numTables)
int i_attname;
int i_typname;
int i_attlen;
+ int i_attnotnull;
PGresult *res;
int ntups;
@@ -1255,7 +1258,7 @@ getTableAttrs(TableInfo* tblinfo, int numTables)
tblinfo[i].relname,
g_comment_end);
- sprintf(q,"SELECT a.attnum, a.attname, t.typname, a.attlen "
+ sprintf(q,"SELECT a.attnum, a.attname, t.typname, a.attlen, a.attnotnull "
"from pg_attribute a, pg_type t "
"where a.attrelid = '%s'::oid and a.atttypid = t.oid "
"and a.attnum > 0 order by attnum",
@@ -1272,12 +1275,14 @@ getTableAttrs(TableInfo* tblinfo, int numTables)
i_attname = PQfnumber(res,"attname");
i_typname = PQfnumber(res,"typname");
i_attlen = PQfnumber(res,"attlen");
+ i_attnotnull = PQfnumber(res,"attnotnull");
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].notnull = (bool*) malloc (ntups * sizeof(bool));
tblinfo[i].parentRels = NULL;
tblinfo[i].numParents = 0;
for (j=0;j<ntups;j++) {
@@ -1287,6 +1292,7 @@ getTableAttrs(TableInfo* tblinfo, int numTables)
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()*/
+ tblinfo[i].notnull[j] = PQgetvalue(res,j,i_attnotnull)[0]=='t'?true:false;
}
PQclear(res);
}
@@ -1766,6 +1772,7 @@ void dumpTables(FILE* fout, TableInfo *tblinfo, int numTables,
tblinfo[i].typnames[j]);
actual_atts++;
}
+ sprintf(q, "%s%s NULL", q, tblinfo[i].notnull[j]?" NOT":"");
}
}
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
index e65eb6e5e7f..a8df2db03ea 100644
--- a/src/bin/pg_dump/pg_dump.h
+++ b/src/bin/pg_dump/pg_dump.h
@@ -5,7 +5,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_dump.h,v 1.17 1997/07/23 17:15:13 momjian Exp $
+ * $Id: pg_dump.h,v 1.18 1997/08/19 04:44:40 vadim Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
@@ -70,6 +70,7 @@ typedef struct _tableInfo {
an inherited attribute */
char **attnames; /* the attribute names */
char **typnames; /* fill out attributes */
+ bool *notnull; /* Not null constraints of an attribute */
int numParents; /* number of (immediate) parent supertables */
char **parentRels; /* names of parent relations, NULL
if numParents == 0 */
diff --git a/src/bin/psql/psql.c b/src/bin/psql/psql.c
index e8ef0092292..b8947606be5 100644
--- a/src/bin/psql/psql.c
+++ b/src/bin/psql/psql.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.82 1997/08/17 00:48:45 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.83 1997/08/19 04:45:02 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -422,7 +422,7 @@ tableDesc(PsqlSettings * ps, char *table)
table[i] = tolower(table[i]);
descbuf[0] = '\0';
- strcat(descbuf, "SELECT a.attnum, a.attname, t.typname, a.attlen");
+ strcat(descbuf, "SELECT a.attnum, a.attname, t.typname, a.attlen, a.attnotnull");
strcat(descbuf, " FROM pg_class c, pg_attribute a, pg_type t ");
strcat(descbuf, " WHERE c.relname = '");
strcat(descbuf, table);
diff --git a/src/bin/psql/psqlHelp.h b/src/bin/psql/psqlHelp.h
index e3b2ed0cf8c..a88918669e9 100644
--- a/src/bin/psql/psqlHelp.h
+++ b/src/bin/psql/psqlHelp.h
@@ -5,7 +5,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: psqlHelp.h,v 1.20 1997/07/24 19:11:53 momjian Exp $
+ * $Id: psqlHelp.h,v 1.21 1997/08/19 04:45:04 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -76,7 +76,7 @@ static struct _helpStruct QL_HELP[] = {
"create sequence <sequence_name>\n\t[increment <NUMBER>]\n\t[start <NUMBER>]\n\t[minvalue <NUMBER>]\n\t[maxvalue <NUMBER>]\n\t[cache <NUMBER>]\n\t[cycle];"},
{ "create table",
"create a new table",
- "create table <class_name> ( <attr1> <type1>,... <attrN> <typeN>)\n\t[inherits (<class_name1>,...<class_nameN>\n\tarchive=<archive_mode>\n\tstore=<smgr_name>\n\tarch_store=<smgr_name>];"},
+ "create table <class_name> ( <attr1> <type1> [[not] null],... <attrN> <typeN>)\n\t[inherits (<class_name1>,...<class_nameN>\n\tarchive=<archive_mode>\n\tstore=<smgr_name>\n\tarch_store=<smgr_name>];"},
{ "create type",
"create a new user-defined base data type",
"create type <typename> (\n\tinternallength = (<number> | variable),\n\t[externallength = (<number>|variable),]\n\tinput=<input_function>, output = <output_function>\n\t[,element = <typename>][,delimiter=<character>][,default=\'<string>\']\n\t[,send = <send_function>][,receive = <receive_function>][,passedbyvalue]);"},