Re: psql tabcomplete - minor bugfix - tabcomplete for SET ROLE TO xxx - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: psql tabcomplete - minor bugfix - tabcomplete for SET ROLE TO xxx
Date
Msg-id CAFj8pRAHCwAjqVWzi=XjJvZ3mC4ucthCTb7-PQOBOs3_gAmLRw@mail.gmail.com
Whole thread Raw
In response to Re: psql tabcomplete - minor bugfix - tabcomplete for SET ROLE TO xxx  (Andres Freund <andres@anarazel.de>)
Responses Re: psql tabcomplete - minor bugfix - tabcomplete for SET ROLE TO xxx  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Hi

2015-09-02 15:23 GMT+02:00 Andres Freund <andres@anarazel.de>:
Hi,

On 2015-07-08 14:50:37 +0200, Pavel Stehule wrote:
> -                     static const char *const my_list[] =
> -                     {"DEFAULT", NULL};
> +                     /* fallback for GUC settings */
>
> -                     COMPLETE_WITH_LIST(my_list);
> +                     char *vartype = get_vartype(prev2_wd);
> +
> +                     if (strcmp(vartype, "enum") == 0)
> +                     {
> +                             char querybuf[1024];
> +
> +                             snprintf(querybuf, 1024, Query_for_enum, prev2_wd);
> +                             COMPLETE_WITH_QUERY(querybuf);
> +                     }

Won't that mean that enum variables don't complete to default anymore?

no, it does

#define Query_for_enum \
" SELECT name FROM ( "\
"   SELECT unnest(enumvals) AS name "\
"    FROM pg_catalog.pg_settings "\
"   WHERE pg_catalog.lower(name)=pg_catalog.lower('%s') "\
"   UNION SELECT 'DEFAULT' ) ss "\                                 ****************
"  WHERE pg_catalog.substring(name,1,%%d)='%%s'"

 

> +static char *
> +get_vartype(const char *varname)
> +{
> +     PQExpBufferData query_buffer;
> +     char    *e_varname;
> +     PGresult *result;
> +     int     string_length;
> +     static char resbuf[10];
> +
> +     initPQExpBuffer(&query_buffer);
> +
> +     string_length = strlen(varname);
> +     e_varname = pg_malloc(string_length * 2 + 1);
> +     PQescapeString(e_varname, varname, string_length);

Independent of this patch, we really shouldn't do this in several places
:(

fixed 

> +     appendPQExpBuffer(&query_buffer,
> +             "SELECT vartype FROM pg_settings WHERE pg_catalog.lower(name) = pg_catalog.lower('%s')",
> +                      e_varname);

Missing pg_catalog for pg_settings.

fixed

Greetings,

Andres Freund

I am sending new version

Regards

Pavel

Attachment

pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: src/test/ssl broken on HEAD
Next
From: Robert Haas
Date:
Subject: Re: src/test/ssl broken on HEAD