From 76f9dd4fa82270899f7b56b002b5d34226dc99d8 Mon Sep 17 00:00:00 2001 From: Kevin Grittner Date: Thu, 1 Sep 2016 16:10:30 -0500 Subject: [PATCH] Improve tab completion for BEGIN & START|SET TRANSACTION. Andreas Karlsson with minor change by me for SET TRANSACTION SNAPSHOT. --- src/bin/psql/tab-complete.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 1345e4ed80..019f75a376 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1894,8 +1894,11 @@ psql_completion(const char *text, int start, int end) else if (Matches5("ALTER", "GROUP", MatchAny, "ADD|DROP", "USER")) COMPLETE_WITH_QUERY(Query_for_list_of_roles); -/* BEGIN, END, ABORT */ - else if (Matches1("BEGIN|END|ABORT")) +/* BEGIN */ + else if (Matches1("BEGIN")) + COMPLETE_WITH_LIST6("WORK", "TRANSACTION", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE"); +/* END, ABORT */ + else if (Matches1("END|ABORT")) COMPLETE_WITH_LIST2("WORK", "TRANSACTION"); /* COMMIT */ else if (Matches1("COMMIT")) @@ -2762,20 +2765,36 @@ psql_completion(const char *text, int start, int end) else if (Matches1("SHOW")) COMPLETE_WITH_QUERY(Query_for_list_of_show_vars); /* Complete "SET TRANSACTION" */ - else if (Matches2("SET|BEGIN|START", "TRANSACTION") || + else if (Matches2("SET", "TRANSACTION")) + COMPLETE_WITH_LIST5("SNAPSHOT", "ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE"); + else if (Matches2("BEGIN|START", "TRANSACTION") || Matches2("BEGIN", "WORK") || + Matches1("BEGIN") || Matches5("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION")) - COMPLETE_WITH_LIST2("ISOLATION LEVEL", "READ"); + COMPLETE_WITH_LIST4("ISOLATION LEVEL", "READ", "DEFERRABLE", "NOT DEFERRABLE"); + else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "NOT") || + Matches2("BEGIN", "NOT") || + Matches6("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "NOT")) + COMPLETE_WITH_CONST("DEFERRABLE"); else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION") || + Matches2("BEGIN", "ISOLATION") || Matches6("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION")) COMPLETE_WITH_CONST("LEVEL"); - else if (Matches4("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL")) + else if (Matches4("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL") || + Matches3("BEGIN", "ISOLATION", "LEVEL") || + Matches7("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL")) COMPLETE_WITH_LIST3("READ", "REPEATABLE READ", "SERIALIZABLE"); - else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "READ")) + else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "READ") || + Matches4("BEGIN", "ISOLATION", "LEVEL", "READ") || + Matches8("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL", "READ")) COMPLETE_WITH_LIST2("UNCOMMITTED", "COMMITTED"); - else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "REPEATABLE")) + else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "REPEATABLE") || + Matches4("BEGIN", "ISOLATION", "LEVEL", "REPEATABLE") || + Matches8("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION", "LEVEL", "REPEATABLE")) COMPLETE_WITH_CONST("READ"); - else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "READ")) + else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "READ") || + Matches2("BEGIN", "READ") || + Matches6("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "READ")) COMPLETE_WITH_LIST2("ONLY", "WRITE"); /* SET CONSTRAINTS */ else if (Matches2("SET", "CONSTRAINTS")) -- 2.40.0