Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc666d6f

Browse files
committed
Here is a diff of changes to the psql source code implementing a simple
'list domains' command '\dD'. This is the interface component ofrbt@zort.ca's domain backend modifications.Jonathan Eisler
1 parent01c76f7 commitc666d6f

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

‎src/bin/psql/command.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.67 2002/03/05 00:01:00 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.68 2002/03/06 20:39:45 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -380,6 +380,10 @@ exec_command(const char *cmd,
380380
case'u':
381381
success=describeUsers(name);
382382
break;
383+
case'D':
384+
success=listDomains(name);
385+
break;
386+
383387
default:
384388
status=CMD_UNKNOWN;
385389
}

‎src/bin/psql/describe.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.43 2002/03/05 02:42:56 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.44 2002/03/06 20:39:45 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -1036,3 +1036,51 @@ listTables(const char *infotype, const char *name, bool desc)
10361036
PQclear(res);
10371037
return true;
10381038
}
1039+
1040+
/*
1041+
* \dD [domain]
1042+
*
1043+
* Describes domains, possibly based on a simplistic prefix search on the
1044+
* argument.
1045+
*/
1046+
1047+
bool
1048+
listDomains(constchar*name)
1049+
{
1050+
charbuf[512+REGEXP_CUTOFF];
1051+
PGresult*res;
1052+
printQueryOptmyopt=pset.popt;
1053+
1054+
snprintf(buf,sizeof(buf),
1055+
"SELECT t.typname as \"%s\",\n"
1056+
" format_type( t.typbasetype, t.typmod) as \"%s\",\n"
1057+
" CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n"
1058+
" WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
1059+
" WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
1060+
" ELSE ''\n"
1061+
" END as \"%s\"\n"
1062+
"FROM pg_type t\n"
1063+
"WHERE t.typtype = 'd'\n",
1064+
_("Name"),
1065+
_("Type"),
1066+
_("Modifier"));
1067+
if (name)
1068+
{
1069+
strcat(buf,"AND t.typname ~ '^");
1070+
strncat(buf,name,REGEXP_CUTOFF);
1071+
strcat(buf,"'\n");
1072+
}
1073+
strcat(buf,"ORDER BY 1;");
1074+
1075+
res=PSQLexec(buf);
1076+
if (!res)
1077+
return false;
1078+
1079+
myopt.nullPrint=NULL;
1080+
myopt.title=_("List of database domains");
1081+
1082+
printQuery(res,&myopt,pset.queryFout);
1083+
1084+
PQclear(res);
1085+
return true;
1086+
}

‎src/bin/psql/describe.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.13 2001/11/05 17:46:31 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.14 2002/03/06 20:39:45 momjian Exp $
77
*/
88
#ifndefDESCRIBE_H
99
#defineDESCRIBE_H
@@ -40,4 +40,7 @@ boollistAllDbs(bool desc);
4040
/* \dt, \di, \ds, \dS, etc. */
4141
boollistTables(constchar*infotype,constchar*name,booldesc);
4242

43+
/* \dD */
44+
boollistDomains(constchar*name);
45+
4346
#endif/* DESCRIBE_H */

‎src/bin/psql/help.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.44 2002/03/05 06:13:19 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.45 2002/03/06 20:39:45 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"help.h"
@@ -202,6 +202,7 @@ slashUsage(void)
202202
fprintf(fout,_(" \\d{p|S|l} list access privileges, system tables, or large objects\n"));
203203
fprintf(fout,_(" \\da list aggregate functions\n"));
204204
fprintf(fout,_(" \\dd NAME show comment for table, type, function, or operator\n"));
205+
fprintf(fout,_(" \\dD [NAME] list domains\n"));
205206
fprintf(fout,_(" \\df list functions\n"));
206207
fprintf(fout,_(" \\do list operators\n"));
207208
fprintf(fout,_(" \\dT list data types\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp