zoukankan      html  css  js  c++  java
  • PostgreSQL 的 target_list分析(七)

    修改gram.y 的select 部分,看能否找出 target_list中的 各个字段名称:

    simple_select:
                SELECT opt_distinct target_list
                into_clause from_clause where_clause
                group_clause having_clause window_clause
                    {
                        SelectStmt *n = makeNode(SelectStmt);
                        n->distinctClause = $2;
                        n->targetList = $3;
                        n->intoClause = $4;
                        n->fromClause = $5;
                        n->whereClause = $6;
                        n->groupClause = $7;
                        n->havingClause = $8;
                        n->windowClause = $9;
                        $$ = (Node *)n;
                        ListCell * curr=n->targetList->head; 
                        while ( curr != NULL)
                        {
                           //To display the current ResTarget Node
                           if (curr->data.ptr_value==NULL)
                              fprintf(stderr,"NULL of ptr_value\n");
                           else
                              fprintf(stderr,"Not NULL of ptr_value\n");
                           ResTarget * restar=(ResTarget *)(curr->data.ptr_value);
                           Node * nod=(Node *)(restar->val); 
                           ColumnRef * colref=(ColumnRef *)nod;
                           if (colref ==NULL)
                             fprintf(stderr,"NULL of ColumnRef\n");
                           else
                             fprintf(stderr,"Not NULL of ColumnRef\n");
    
                          Value * vval=(Value *)(colref->fields->head->data.ptr_value);
                          if (vval == NULL)
                             fprintf(stderr,"NULl of vval\n");
                          else
                             fprintf(stderr,"Not Null of vval\n"); 
    
                          fprintf(stderr,"colum is: %s\n",vval->val.str);
                          curr=curr->next;
                       }
                    }
                | values_clause                            { $$ = $1; }
                | TABLE relation_expr
                    {
                        /* same as SELECT * FROM relation_expr */
                        ColumnRef *cr = makeNode(ColumnRef);
                        ResTarget *rt = makeNode(ResTarget);
                        SelectStmt *n = makeNode(SelectStmt);
    
                        cr->fields = list_make1(makeNode(A_Star));
                        cr->location = -1;
    
                        rt->name = NULL;
                        rt->indirection = NIL;
                        rt->val = (Node *)cr;
                        rt->location = -1;
    
                        n->targetList = list_make1(rt);
                        n->fromClause = list_make1($2);
                        $$ = (Node *)n;
                    }
                | select_clause UNION opt_all select_clause
                    {
                        $$ = makeSetOp(SETOP_UNION, $3, $1, $4);
                    }
                | select_clause INTERSECT opt_all select_clause
                    {
                        $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4);
                    }
                | select_clause EXCEPT opt_all select_clause
                    {
                        $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4);
                    }
            ;

    执行sql文的时候,后台能够正确给出 各个字段的名称。

  • 相关阅读:
    网上找的,C# 小票打印机 直接打印,备用
    SlickUpload 破解方法
    全文索引的一点个人总结
    在ASP.NET中利用SlickUpload来上传大文件
    再谈iframe自适应高度 By 大米
    发送邮件到 163、Gmail、QQ 等邮箱时,全丢垃圾箱中怎么办?
    iis下Awstats的安装使用说明
    AutoCompleteExtender控件出现undefined和null现象
    IT业史上最棒的图片之一
    EnableViewState="false",取dropdownlist的值
  • 原文地址:https://www.cnblogs.com/gaojian/p/2680395.html
Copyright © 2011-2022 走看看