Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
4191e16c
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4191e16c
编写于
2月 24, 2011
作者:
I
Itagaki Takahiro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tab-completion for CREATE UNLOGGED TABLE in psql,
and fix unexpected completion for DROP TEMP and UNIQUE.
上级
2c72d704
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
51 deletion
+35
-51
src/bin/psql/tab-complete.c
src/bin/psql/tab-complete.c
+35
-51
未找到文件。
src/bin/psql/tab-complete.c
浏览文件 @
4191e16c
...
...
@@ -598,10 +598,13 @@ typedef struct
const
char
*
name
;
const
char
*
query
;
/* simple query, or NULL */
const
SchemaQuery
*
squery
;
/* schema query, or NULL */
const
bool
noshow
;
/* NULL or true if this word should not show
* up after CREATE or DROP */
const
bits32
flags
;
/* visibility flags, see below */
}
pgsql_thing_t
;
#define THING_NO_CREATE (1 << 0)
/* should not show up after CREATE */
#define THING_NO_DROP (1 << 1)
/* should not show up after DROP */
#define THING_NO_SHOW (THING_NO_CREATE | THING_NO_DROP)
static
const
pgsql_thing_t
words_after_create
[]
=
{
{
"AGGREGATE"
,
NULL
,
&
Query_for_list_of_aggregates
},
{
"CAST"
,
NULL
,
NULL
},
/* Casts have complex structures for names, so
...
...
@@ -612,10 +615,10 @@ static const pgsql_thing_t words_after_create[] = {
* CREATE CONSTRAINT TRIGGER is not supported here because it is designed
* to be used only by pg_dump.
*/
{
"CONFIGURATION"
,
Query_for_list_of_ts_configurations
,
NULL
,
true
},
{
"CONFIGURATION"
,
Query_for_list_of_ts_configurations
,
NULL
,
THING_NO_SHOW
},
{
"CONVERSION"
,
"SELECT pg_catalog.quote_ident(conname) FROM pg_catalog.pg_conversion WHERE substring(pg_catalog.quote_ident(conname),1,%d)='%s'"
},
{
"DATABASE"
,
Query_for_list_of_databases
},
{
"DICTIONARY"
,
Query_for_list_of_ts_dictionaries
,
NULL
,
true
},
{
"DICTIONARY"
,
Query_for_list_of_ts_dictionaries
,
NULL
,
THING_NO_SHOW
},
{
"DOMAIN"
,
NULL
,
&
Query_for_list_of_domains
},
{
"EXTENSION"
,
Query_for_list_of_extensions
},
{
"FOREIGN DATA WRAPPER"
,
NULL
,
NULL
},
...
...
@@ -626,7 +629,8 @@ static const pgsql_thing_t words_after_create[] = {
{
"INDEX"
,
NULL
,
&
Query_for_list_of_indexes
},
{
"OPERATOR"
,
NULL
,
NULL
},
/* Querying for this is probably not such a
* good idea. */
{
"PARSER"
,
Query_for_list_of_ts_parsers
,
NULL
,
true
},
{
"OWNED"
,
NULL
,
NULL
,
THING_NO_CREATE
},
/* for DROP OWNED BY ... */
{
"PARSER"
,
Query_for_list_of_ts_parsers
,
NULL
,
THING_NO_SHOW
},
{
"ROLE"
,
Query_for_list_of_roles
},
{
"RULE"
,
"SELECT pg_catalog.quote_ident(rulename) FROM pg_catalog.pg_rules WHERE substring(pg_catalog.quote_ident(rulename),1,%d)='%s'"
},
{
"SCHEMA"
,
Query_for_list_of_schemas
},
...
...
@@ -634,16 +638,17 @@ static const pgsql_thing_t words_after_create[] = {
{
"SERVER"
,
Query_for_list_of_servers
},
{
"TABLE"
,
NULL
,
&
Query_for_list_of_tables
},
{
"TABLESPACE"
,
Query_for_list_of_tablespaces
},
{
"TEMP"
,
NULL
,
NULL
},
/* for CREATE TEMP TABLE ... */
{
"TEMPLATE"
,
Query_for_list_of_ts_templates
,
NULL
,
true
},
{
"TEMP"
,
NULL
,
NULL
,
THING_NO_DROP
},
/* for CREATE TEMP TABLE ... */
{
"TEMPLATE"
,
Query_for_list_of_ts_templates
,
NULL
,
THING_NO_SHOW
},
{
"TEXT SEARCH"
,
NULL
,
NULL
},
{
"TRIGGER"
,
"SELECT pg_catalog.quote_ident(tgname) FROM pg_catalog.pg_trigger WHERE substring(pg_catalog.quote_ident(tgname),1,%d)='%s'"
},
{
"TYPE"
,
NULL
,
&
Query_for_list_of_datatypes
},
{
"UNIQUE"
,
NULL
,
NULL
},
/* for CREATE UNIQUE INDEX ... */
{
"UNIQUE"
,
NULL
,
NULL
,
THING_NO_DROP
},
/* for CREATE UNIQUE INDEX ... */
{
"UNLOGGED"
,
NULL
,
NULL
,
THING_NO_DROP
},
/* for CREATE UNLOGGED TABLE ... */
{
"USER"
,
Query_for_list_of_roles
},
{
"USER MAPPING FOR"
,
NULL
,
NULL
},
{
"VIEW"
,
NULL
,
&
Query_for_list_of_views
},
{
NULL
,
NULL
,
NULL
,
false
}
/* end of list */
{
NULL
}
/* end of list */
};
...
...
@@ -1771,6 +1776,12 @@ psql_completion(char *text, int start, int end)
COMPLETE_WITH_LIST
(
list_TEMP
);
}
/* Complete "CREATE UNLOGGED" with TABLE */
else
if
(
pg_strcasecmp
(
prev2_wd
,
"CREATE"
)
==
0
&&
pg_strcasecmp
(
prev_wd
,
"UNLOGGED"
)
==
0
)
{
COMPLETE_WITH_CONST
(
"TABLE"
);
}
/* CREATE TABLESPACE */
else
if
(
pg_strcasecmp
(
prev3_wd
,
"CREATE"
)
==
0
&&
...
...
@@ -2858,11 +2869,11 @@ psql_completion(char *text, int start, int end)
*/
/*
*
This one gives you one from a list of things you can put after CREATE
*
as defined above
.
*
Common routine for create_command_generator and drop_command_generator.
*
Entries that have 'excluded' flags are not returned
.
*/
static
char
*
create_
command_generator
(
const
char
*
text
,
int
state
)
create_
or_drop_command_generator
(
const
char
*
text
,
int
state
,
bits32
excluded
)
{
static
int
list_index
,
string_length
;
...
...
@@ -2879,57 +2890,30 @@ create_command_generator(const char *text, int state)
while
((
name
=
words_after_create
[
list_index
++
].
name
))
{
if
((
pg_strncasecmp
(
name
,
text
,
string_length
)
==
0
)
&&
!
words_after_create
[
list_index
-
1
].
noshow
)
!
(
words_after_create
[
list_index
-
1
].
flags
&
excluded
)
)
return
pg_strdup
(
name
);
}
/* if nothing matches, return NULL */
return
NULL
;
}
/*
* This one gives you one from a list of things you can put after CREATE
* as defined above.
*/
static
char
*
create_command_generator
(
const
char
*
text
,
int
state
)
{
return
create_or_drop_command_generator
(
text
,
state
,
THING_NO_CREATE
);
}
/*
* This function gives you a list of things you can put after a DROP command.
* Very similar to create_command_generator, but has an additional entry for
* OWNED BY. (We do it this way in order not to duplicate the
* words_after_create list.)
*/
static
char
*
drop_command_generator
(
const
char
*
text
,
int
state
)
{
static
int
list_index
,
string_length
;
const
char
*
name
;
if
(
state
==
0
)
{
/* If this is the first time for this completion, init some values */
list_index
=
0
;
string_length
=
strlen
(
text
);
/*
* DROP can be followed by "OWNED BY", which is not found in the list
* for CREATE matches, so make it the first state. (We do not make it
* the last state because it would be more difficult to detect when we
* have to return NULL instead.)
*
* Make sure we advance to the next state.
*/
list_index
++
;
if
(
pg_strncasecmp
(
"OWNED"
,
text
,
string_length
)
==
0
)
return
pg_strdup
(
"OWNED"
);
}
/*
* In subsequent attempts, try to complete with the same items we use for
* CREATE
*/
while
((
name
=
words_after_create
[
list_index
++
-
1
].
name
))
{
if
((
pg_strncasecmp
(
name
,
text
,
string_length
)
==
0
)
&&
(
!
words_after_create
[
list_index
-
2
].
noshow
))
return
pg_strdup
(
name
);
}
/* if nothing matches, return NULL */
return
NULL
;
return
create_or_drop_command_generator
(
text
,
state
,
THING_NO_DROP
);
}
/* The following two functions are wrappers for _complete_from_query */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录