Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
0af9137f
Commit
0af9137f
authored
Jan 05, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add NOT NULL and DEFAULT to \d table.
parent
0aa92876
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
26 deletions
+48
-26
src/bin/psql/psql.c
src/bin/psql/psql.c
+48
-26
No files found.
src/bin/psql/psql.c
View file @
0af9137f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.12
2 1997/12/23 21:38:40
momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.12
3 1998/01/05 02:21:22
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -527,9 +527,11 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
...
@@ -527,9 +527,11 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
char
descbuf
[
256
];
char
descbuf
[
256
];
int
nColumns
;
int
nColumns
;
char
*
rtype
;
char
*
rtype
;
char
*
rnotnull
;
char
*
rhasdef
;
int
i
;
int
i
;
int
rsize
;
int
rsize
;
PGresult
*
res
;
PGresult
*
res
,
*
res2
;
int
usePipe
=
0
;
int
usePipe
=
0
;
char
*
pagerenv
;
char
*
pagerenv
;
...
@@ -564,7 +566,7 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
...
@@ -564,7 +566,7 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
}
}
descbuf
[
0
]
=
'\0'
;
descbuf
[
0
]
=
'\0'
;
strcat
(
descbuf
,
"SELECT a.attnum, a.attname, t.typname, a.attlen, a.attnotnull "
);
strcat
(
descbuf
,
"SELECT a.attnum, a.attname, t.typname, a.attlen, a.attnotnull
, a.atthasdef
"
);
strcat
(
descbuf
,
"FROM pg_class c, pg_attribute a, pg_type t "
);
strcat
(
descbuf
,
"FROM pg_class c, pg_attribute a, pg_type t "
);
strcat
(
descbuf
,
"WHERE c.relname = '"
);
strcat
(
descbuf
,
"WHERE c.relname = '"
);
strcat
(
descbuf
,
table
);
strcat
(
descbuf
,
table
);
...
@@ -594,7 +596,7 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
...
@@ -594,7 +596,7 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
fout
=
stdout
;
fout
=
stdout
;
}
}
/*
/*
*
*
Display the information
*
Display the information
*/
*/
fprintf
(
fout
,
"
\n
Table = %s
\n
"
,
table
);
fprintf
(
fout
,
"
\n
Table = %s
\n
"
,
table
);
...
@@ -605,39 +607,59 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
...
@@ -605,39 +607,59 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
/* next, print out the instances */
/* next, print out the instances */
for
(
i
=
0
;
i
<
PQntuples
(
res
);
i
++
)
for
(
i
=
0
;
i
<
PQntuples
(
res
);
i
++
)
{
{
char
type_str
[
33
];
fprintf
(
fout
,
"| %-32.32s | "
,
PQgetvalue
(
res
,
i
,
1
));
fprintf
(
fout
,
"| %-32.32s | "
,
PQgetvalue
(
res
,
i
,
1
));
rtype
=
PQgetvalue
(
res
,
i
,
2
);
rtype
=
PQgetvalue
(
res
,
i
,
2
);
rsize
=
atoi
(
PQgetvalue
(
res
,
i
,
3
));
rsize
=
atoi
(
PQgetvalue
(
res
,
i
,
3
));
if
(
strcmp
(
rtype
,
"text"
)
==
0
)
rnotnull
=
PQgetvalue
(
res
,
i
,
4
);
rhasdef
=
PQgetvalue
(
res
,
i
,
5
);
strcpy
(
type_str
,
rtype
);
if
(
strcmp
(
rtype
,
"bpchar"
)
==
0
)
strcpy
(
type_str
,
"char()"
);
else
if
(
strcmp
(
rtype
,
"varchar"
)
==
0
)
strcpy
(
type_str
,
"varchar()"
);
else
if
(
rtype
[
0
]
==
'_'
)
{
{
fprintf
(
fout
,
"%-32.32s |"
,
rtype
);
strcpy
(
type_str
,
rtype
+
1
);
fprintf
(
fout
,
"%6s |"
,
"var"
);
strncat
(
type_str
,
"[]"
,
32
-
strlen
(
type_str
));
type_str
[
32
]
=
'\0'
;
}
}
else
if
(
strcmp
(
rtype
,
"bpchar"
)
==
0
)
if
(
rnotnull
[
0
]
==
't'
)
{
{
fprintf
(
fout
,
"%-32.32s |"
,
"(bp)char"
);
strncat
(
type_str
,
" not null"
,
32
-
strlen
(
type_str
)
);
fprintf
(
fout
,
"%6i |"
,
rsize
>
0
?
rsize
-
VARHDRSZ
:
0
)
;
type_str
[
32
]
=
'\0'
;
}
}
else
if
(
strcmp
(
rtype
,
"varchar"
)
==
0
)
if
(
rhasdef
[
0
]
==
't'
)
{
{
fprintf
(
fout
,
"%-32.32s |"
,
rtype
);
descbuf
[
0
]
=
'\0'
;
fprintf
(
fout
,
"%6i |"
,
rsize
>
0
?
rsize
-
VARHDRSZ
:
0
);
strcat
(
descbuf
,
"SELECT d.adsrc "
);
strcat
(
descbuf
,
"FROM pg_attrdef d, pg_class c "
);
strcat
(
descbuf
,
"WHERE c.relname = '"
);
strcat
(
descbuf
,
table
);
strcat
(
descbuf
,
"'"
);
strcat
(
descbuf
,
" and c.oid = d.adrelid "
);
strcat
(
descbuf
,
" and d.adnum = "
);
strcat
(
descbuf
,
PQgetvalue
(
res
,
i
,
0
));
if
(
!
(
res2
=
PSQLexec
(
pset
,
descbuf
)))
return
-
1
;
strcat
(
type_str
,
" default '"
);
strncat
(
type_str
,
PQgetvalue
(
res2
,
0
,
0
),
32
-
strlen
(
type_str
));
type_str
[
32
]
=
'\0'
;
strncat
(
type_str
,
"'"
,
32
-
strlen
(
type_str
));
type_str
[
32
]
=
'\0'
;
}
}
fprintf
(
fout
,
"%-32.32s |"
,
type_str
);
if
(
strcmp
(
rtype
,
"text"
)
==
0
)
fprintf
(
fout
,
"%6s |"
,
"var"
);
else
if
(
strcmp
(
rtype
,
"bpchar"
)
==
0
||
strcmp
(
rtype
,
"varchar"
)
==
0
)
fprintf
(
fout
,
"%6i |"
,
rsize
>
0
?
rsize
-
VARHDRSZ
:
0
);
else
else
{
{
/* array types start with an underscore */
if
(
rtype
[
0
]
!=
'_'
)
fprintf
(
fout
,
"%-32.32s |"
,
rtype
);
else
{
char
*
newname
;
newname
=
malloc
(
strlen
(
rtype
)
+
2
);
strcpy
(
newname
,
rtype
+
1
);
strcat
(
newname
,
"[]"
);
fprintf
(
fout
,
"%-32.32s |"
,
newname
);
free
(
newname
);
}
if
(
rsize
>
0
)
if
(
rsize
>
0
)
fprintf
(
fout
,
"%6i |"
,
rsize
);
fprintf
(
fout
,
"%6i |"
,
rsize
);
else
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment