On Tue, 16 Apr 2002, Bruce Momjian wrote:

> The code that bothered me about the CREATE DATABASE param processing
> was:
> 
>     /* process additional options */
>     foreach(l, $5)
>     {
>       List   *optitem = (List *) lfirst(l);
>     
>       switch (lfirsti(optitem))
>       {
>           case 1:   
>               n->dbpath = (char *) lsecond(optitem);
>               break;   
>           case 2:  
>               n->dbtemplate = (char *) lsecond(optitem);
>               break;
>           case 3:
>               n->encoding = lfirsti(lnext(optitem));
>               break;
>           case 4:
>               n->dbowner = (char *) lsecond(optitem);
>               break;
>       }
>     }
> 
> I see what it is doing, but it seems quite unclear.  Seeing that people
> are using this as a pattern for other param processing, I will work on a
> patch to convert this to DefElem.

Wouldn't a few macros clean this up better (ie, make it clearer)?

#define CDBOPTDBPATH 1

#define optparam(l)     (char *)lsecond(l)
#define optparami(l)    (int)lfirsti(lnext(l))

     foreach(l, $5)
     {
       List   *optitem = (List *) lfirst(l);

       switch (lfirsti(optitem))
       {
           case CDBOPTDBPATH:
               n->dbpath = optparam(optitem);
               break;

...


Regardless, I guess that code is pointless since the consensus seems to be
that the use of DefElem is better since it allows for the abstraction of
the parameters list. Obviously a good thing if CREATE DATABASE, COPY etc
are to be extended often enough.

Gavin


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to