@@ -697,7 +697,7 @@ static char **complete_from_variables(char *text,
697697const char * prefix ,const char * suffix );
698698static char * complete_from_files (const char * text ,int state );
699699
700- static char * pg_strdup_same_case (const char * s ,const char * ref );
700+ static char * pg_strdup_keyword_case (const char * s ,const char * ref );
701701static PGresult * exec_query (const char * query );
702702
703703static void get_previous_words (int point ,char * * previous_words ,int nwords );
@@ -3125,7 +3125,7 @@ create_or_drop_command_generator(const char *text, int state, bits32 excluded)
31253125{
31263126if ((pg_strncasecmp (name ,text ,string_length )== 0 )&&
31273127!(words_after_create [list_index - 1 ].flags & excluded ))
3128- return pg_strdup_same_case (name ,text );
3128+ return pg_strdup_keyword_case (name ,text );
31293129}
31303130/* if nothing matches, return NULL */
31313131return NULL ;
@@ -3412,9 +3412,9 @@ complete_from_list(const char *text, int state)
34123412if (completion_case_sensitive )
34133413return pg_strdup (item );
34143414else
3415- /* If case insensitive matching was requested initially,return
3416- *it in the caseof what was already entered . */
3417- return pg_strdup_same_case (item ,text );
3415+ /* If case insensitive matching was requested initially,adjust
3416+ * the caseaccording to setting . */
3417+ return pg_strdup_keyword_case (item ,text );
34183418}
34193419}
34203420
@@ -3451,9 +3451,9 @@ complete_from_const(const char *text, int state)
34513451if (completion_case_sensitive )
34523452return pg_strdup (completion_charp );
34533453else
3454- /* If case insensitive matching was requested initially,return it
3455- *in the caseof what was already entered . */
3456- return pg_strdup_same_case (completion_charp ,text );
3454+ /* If case insensitive matching was requested initially,adjust the
3455+ * caseaccording to setting . */
3456+ return pg_strdup_keyword_case (completion_charp ,text );
34573457}
34583458else
34593459return NULL ;
@@ -3561,27 +3561,48 @@ complete_from_files(const char *text, int state)
35613561
35623562
35633563/*
3564- * Make a pg_strdup copy of s and convert it to the same case as ref.
3564+ * Make a pg_strdup copy of s and convert the case according to
3565+ * COMP_KEYWORD_CASE variable, using ref as the text that was already entered.
35653566 */
35663567static char *
3567- pg_strdup_same_case (const char * s ,const char * ref )
3568+ pg_strdup_keyword_case (const char * s ,const char * ref )
35683569{
35693570char * ret ,* p ;
35703571unsignedchar first = ref [0 ];
3572+ int tocase ;
3573+ const char * varval ;
3574+
3575+ varval = GetVariable (pset .vars ,"COMP_KEYWORD_CASE" );
3576+ if (!varval )
3577+ tocase = 0 ;
3578+ else if (strcmp (varval ,"lower" )== 0 )
3579+ tocase = -2 ;
3580+ else if (strcmp (varval ,"preserve-lower" )== 0 )
3581+ tocase = -1 ;
3582+ else if (strcmp (varval ,"preserve-upper" )== 0 )
3583+ tocase = +1 ;
3584+ else if (strcmp (varval ,"upper" )== 0 )
3585+ tocase = +2 ;
3586+ else
3587+ tocase = 0 ;
35713588
3572- if (isalpha (first ))
3573- {
3574- ret = pg_strdup (s );
3575- if (islower (first ))
3576- for (p = ret ;* p ;p ++ )
3577- * p = pg_tolower ((unsignedchar )* p );
3578- else
3579- for (p = ret ;* p ;p ++ )
3580- * p = pg_toupper ((unsignedchar )* p );
3581- return ret ;
3582- }
3589+ /* default */
3590+ if (tocase == 0 )
3591+ tocase = +1 ;
3592+
3593+ ret = pg_strdup (s );
3594+
3595+ if (tocase == -2
3596+ || ((tocase == -1 || tocase == +1 )&& islower (first ))
3597+ || (tocase == -1 && !isalpha (first ))
3598+ )
3599+ for (p = ret ;* p ;p ++ )
3600+ * p = pg_tolower ((unsignedchar )* p );
35833601else
3584- return pg_strdup (s );
3602+ for (p = ret ;* p ;p ++ )
3603+ * p = pg_toupper ((unsignedchar )* p );
3604+
3605+ return ret ;
35853606}
35863607
35873608