SQLTable.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 SQLTABLE_HPP_
  14. #define SQLTABLE_HPP_
  15. #include "ws_sql.hpp"
  16. #include "SQLJoin.hpp"
  17. class SQLTable : public CInterface, public IInterface
  18. {
  19. public:
  20. IMPLEMENT_IINTERFACE;
  21. static SQLTable * createSQLTable()
  22. {
  23. return new SQLTable();
  24. }
  25. SQLTable(){}
  26. virtual ~SQLTable()
  27. {
  28. #ifdef _DEBUG
  29. fprintf(stderr, "Leaving SQLTable");
  30. #endif
  31. }
  32. SQLJoin* getJoin() const
  33. {
  34. return join.get();
  35. }
  36. void setJoin(SQLJoin* join)
  37. {
  38. this->join.setown(join);
  39. }
  40. void setNewJoin(SQLJoinType jointype)
  41. {
  42. this->join.setown(SQLJoin::creatSQLJoin(jointype));
  43. }
  44. bool hasIndexHint()
  45. {
  46. return indexhint.length() > 0;
  47. }
  48. const char* getIndexhint() const
  49. {
  50. return indexhint.str();
  51. }
  52. void setIndexhint(const char* indexhint)
  53. {
  54. this->indexhint.set(indexhint);
  55. }
  56. const char * getAlias() const
  57. {
  58. return alias.c_str();
  59. }
  60. void setAlias(const char * alias)
  61. {
  62. this->alias = alias;
  63. }
  64. const char * getName() const
  65. {
  66. return name.c_str();
  67. }
  68. void setName(const char * name)
  69. {
  70. this->name = name;
  71. }
  72. bool hasJoin()
  73. {
  74. return (join.get() != NULL);
  75. }
  76. const char * translateIfAlias(const char* possibleAlias)
  77. {
  78. if ((!alias.empty() && alias.compare(possibleAlias) == 0) || (!name.empty() && name.compare(possibleAlias) == 0))
  79. return name.c_str();
  80. else
  81. return "";
  82. }
  83. private:
  84. string name;
  85. string alias;
  86. StringBuffer indexhint;
  87. Owned<SQLJoin> join;
  88. };
  89. #endif /* SQLTABLE_HPP_ */