SQLColumn.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef SQLCOLUMN_HPP_
  14. #define SQLCOLUMN_HPP_
  15. #include "ws_sql.hpp"
  16. class SQLColumn : public CInterface, public IInterface
  17. {
  18. private:
  19. StringBuffer name;
  20. StringBuffer alias;
  21. StringBuffer parenttable;
  22. int position;
  23. bool ascending;
  24. StringBuffer columnType;
  25. public:
  26. IMPLEMENT_IINTERFACE;
  27. SQLColumn();
  28. SQLColumn(const char* parentname, const char* columnname, const char* alias, int position);
  29. virtual ~SQLColumn();
  30. bool isAscending() const
  31. {
  32. return ascending;
  33. }
  34. void setAscending(bool ascending)
  35. {
  36. this->ascending = ascending;
  37. }
  38. const char * getAlias() const
  39. {
  40. return alias.str();
  41. }
  42. void setAlias(const char * alias)
  43. {
  44. this->alias.set(alias);
  45. }
  46. const char * getName()
  47. {
  48. return name.str();
  49. }
  50. void setName(const char * name)
  51. {
  52. this->name.set(name);
  53. }
  54. const char * getParenttable() const
  55. {
  56. return parenttable.str();
  57. }
  58. void setParenttable(const char * parenttable)
  59. {
  60. this->parenttable.set(parenttable);
  61. }
  62. int getPosition() const
  63. {
  64. return position;
  65. }
  66. void setPosition(int position)
  67. {
  68. this->position = position;
  69. }
  70. bool isFieldNameOrAalias(const char* possiblenameoralias);
  71. void toString(StringBuffer & str, bool fullOutput);
  72. const char * getColumnNameOrAlias()
  73. {
  74. if (alias.length() > 0)
  75. return alias.str();
  76. else
  77. return name.str();
  78. }
  79. const char * getColumnType() const
  80. {
  81. return columnType.str();
  82. }
  83. void setColumnType(const char* columnType)
  84. {
  85. this->columnType.set(columnType);
  86. }
  87. };
  88. #define DEFAULTDECIMALCHARS 32;
  89. #define DEFAULTINTBYTES 8;
  90. #define DEFAULTREALBYTES 8;
  91. #define DEFAULTCOLCHARS 0;
  92. #define DEFAULTDECDIGITS 0;
  93. class HPCCColumnMetaData : public CInterface, public IInterface
  94. {
  95. private:
  96. StringBuffer columnName;
  97. StringBuffer tableName;
  98. int index;
  99. int decimalDigits;
  100. StringBuffer columnType;
  101. bool keyedField;
  102. public:
  103. IMPLEMENT_IINTERFACE;
  104. static HPCCColumnMetaData * createHPCCColumnMetaData(const char * name)
  105. {
  106. return new HPCCColumnMetaData(name);
  107. }
  108. HPCCColumnMetaData() : keyedField(false), decimalDigits(0), index(-1)
  109. {
  110. columnName.clear();
  111. }
  112. HPCCColumnMetaData(const char * colname) : keyedField(false), decimalDigits(0), index(-1)
  113. {
  114. columnName.set(colname);
  115. }
  116. virtual ~HPCCColumnMetaData()
  117. {
  118. #ifdef _DEBUG
  119. fprintf(stderr, "leaving columnmetadata.");
  120. #endif
  121. }
  122. StringBuffer toEclRecString()
  123. {
  124. StringBuffer result;
  125. result.append(this->columnType.str());
  126. result.append(" ");
  127. result.append(this->columnName.str());
  128. return result;
  129. }
  130. const char * getColumnType() const
  131. {
  132. return columnType.str();
  133. }
  134. void setColumnType(const char* columnType)
  135. {
  136. this->columnType.set(columnType);
  137. }
  138. int getDecimalDigits() const
  139. {
  140. return decimalDigits;
  141. }
  142. void setDecimalDigits(int decimalDigits = 0)
  143. {
  144. this->decimalDigits = decimalDigits;
  145. }
  146. int getIndex() const
  147. {
  148. return index;
  149. }
  150. void setIndex(int index)
  151. {
  152. this->index = index;
  153. }
  154. const char * getTableName() const
  155. {
  156. return tableName.str();
  157. }
  158. void setTableName(const char* tableName)
  159. {
  160. this->tableName.set(tableName);
  161. }
  162. bool isKeyedField() const
  163. {
  164. return keyedField;
  165. }
  166. void setKeyedField(bool keyedField)
  167. {
  168. this->keyedField = keyedField;
  169. }
  170. const char * getColumnName() const
  171. {
  172. return columnName.str();
  173. }
  174. };
  175. #endif /* SQLCOLUMN_HPP_ */