SQLColumn.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. IArrayOf<HPCCColumnMetaData> childColumns;
  103. public:
  104. IMPLEMENT_IINTERFACE;
  105. static HPCCColumnMetaData * createHPCCColumnMetaData(const char * name)
  106. {
  107. return new HPCCColumnMetaData(name);
  108. }
  109. HPCCColumnMetaData() : keyedField(false), decimalDigits(0), index(-1)
  110. {
  111. columnName.clear();
  112. }
  113. HPCCColumnMetaData(const char * colname) : keyedField(false), decimalDigits(0), index(-1)
  114. {
  115. columnName.set(colname);
  116. }
  117. virtual ~HPCCColumnMetaData()
  118. {
  119. #ifdef _DEBUG
  120. fprintf(stderr, "leaving %s columnmetadata.\n", columnName.str());
  121. #endif
  122. childColumns.kill(false);
  123. }
  124. StringBuffer &toEclRecString(StringBuffer &result)
  125. {
  126. result.append(this->columnType.str());
  127. result.append(" ");
  128. result.append(this->columnName.str());
  129. return result;
  130. }
  131. const char * getColumnType() const
  132. {
  133. return columnType.str();
  134. }
  135. void setColumnType(const char* columnType)
  136. {
  137. if (strncmp(columnType, "table of", 8)==0)
  138. {
  139. StringBuffer result;
  140. result.append("DATASET({");
  141. ForEachItemIn(childIndex, childColumns)
  142. {
  143. this->childColumns.item(childIndex).toEclRecString(result);
  144. if (childIndex < childColumns.length()-1)
  145. result.append(", ");
  146. }
  147. result.append("})");
  148. this->columnType.set(result);
  149. }
  150. else
  151. this->columnType.set(columnType);
  152. }
  153. int getDecimalDigits() const
  154. {
  155. return decimalDigits;
  156. }
  157. void setDecimalDigits(int decimalDigits = 0)
  158. {
  159. this->decimalDigits = decimalDigits;
  160. }
  161. int getIndex() const
  162. {
  163. return index;
  164. }
  165. void setIndex(int index)
  166. {
  167. this->index = index;
  168. }
  169. const char * getTableName() const
  170. {
  171. return tableName.str();
  172. }
  173. void setTableName(const char* tableName)
  174. {
  175. this->tableName.set(tableName);
  176. }
  177. bool isKeyedField() const
  178. {
  179. return keyedField;
  180. }
  181. void setKeyedField(bool keyedField)
  182. {
  183. this->keyedField = keyedField;
  184. }
  185. const char * getColumnName() const
  186. {
  187. return columnName.str();
  188. }
  189. void setChildCol(HPCCColumnMetaData * child)
  190. {
  191. childColumns.append(*LINK(child));
  192. }
  193. IArrayOf<HPCCColumnMetaData> * getChildColumns()
  194. {
  195. return &childColumns;
  196. }
  197. };
  198. #endif /* SQLCOLUMN_HPP_ */