Code_column.hpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:3k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #ifndef ODBC_CODEGEN_Code_column_hpp
  14. #define ODBC_CODEGEN_Code_column_hpp
  15. #include <common/common.hpp>
  16. #include <common/DataType.hpp>
  17. #include "Code_base.hpp"
  18. class DictColumn;
  19. class Plan_table;
  20. /**
  21.  * @class Plan_column
  22.  * @brief Abstract base class for columns
  23.  */
  24. class Plan_column {
  25. public:
  26.     enum Type {
  27. Type_expr = 1,
  28. Type_dml = 2,
  29. Type_ddl = 3, // new columns in create table
  30. Type_idx = 4 // old columns in create index
  31.     };
  32.     Plan_column(Type type, const BaseString& name);
  33.     virtual ~Plan_column() = 0;
  34.     void analyzeColumn(Ctx& ctx, Plan_base::Ctl& ctl);
  35.     // attributes
  36.     const BaseString& getName() const;
  37.     const BaseString& getCname() const;
  38.     const char* getPrintName() const;
  39.     void setCname(const BaseString& cname);
  40.     const DictColumn& dictColumn() const;
  41.     const SqlType& sqlType() const;
  42. protected:
  43.     friend class Plan_table;
  44.     friend class Plan_comp_op;
  45.     Type m_type;
  46.     BaseString m_name;
  47.     BaseString m_cname;
  48.     BaseString m_printName;
  49.     DictColumn* m_dictColumn;
  50.     /**
  51.      * Resolve to table and operational position (for example
  52.      * column number in scan query).
  53.      */
  54.     Plan_table* m_resTable;
  55.     unsigned m_resPos;
  56.     SqlType m_sqlType;
  57. };
  58. inline
  59. Plan_column::Plan_column(Type type, const BaseString& name) :
  60.     m_type(type),
  61.     m_name(name),
  62.     m_printName(name),
  63.     m_dictColumn(0),
  64.     m_resTable(0),
  65.     m_resPos(0)
  66. {
  67. }
  68. inline const BaseString&
  69. Plan_column::getName() const
  70. {
  71.     return m_name;
  72. }
  73. inline const BaseString&
  74. Plan_column::getCname() const
  75. {
  76.     return m_cname;
  77. }
  78. inline const char*
  79. Plan_column::getPrintName() const
  80. {
  81.     return m_printName.c_str();
  82. }
  83. inline void
  84. Plan_column::setCname(const BaseString& cname)
  85. {
  86.     m_cname.assign(cname);
  87.     if (m_cname.empty())
  88. m_printName.assign(m_name);
  89.     else {
  90. m_printName.assign(m_cname);
  91. m_printName.append(".");
  92. m_printName.append(m_name);
  93.     }
  94. }
  95. inline const DictColumn&
  96. Plan_column::dictColumn() const
  97. {
  98.     ctx_assert(m_dictColumn != 0);
  99.     return *m_dictColumn;
  100. }
  101. inline const SqlType&
  102. Plan_column::sqlType() const
  103. {
  104.     ctx_assert(m_sqlType.type() != SqlType::Undef);
  105.     return m_sqlType;
  106. }
  107. #endif